]>
Commit | Line | Data |
---|---|---|
f1a1da6c A |
1 | .\" Copyright (c) 2004 Apple Computer, Inc. |
2 | .\" | |
2546420a A |
3 | .\" Redistribution and use in source and binary forms, with or without |
4 | .\" modification, are permitted provided that the following conditions | |
5 | .\" are met: | |
6 | .\" 1. Redistributions of source code must retain the above copyright | |
7 | .\" notice, this list of conditions and the following disclaimer. | |
8 | .\" 2. Redistributions in binary form must reproduce the above copyright | |
9 | .\" notice, this list of conditions and the following disclaimer in the | |
10 | .\" documentation and/or other materials provided with the distribution. | |
11 | .\" | |
12 | .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND | |
13 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
14 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
15 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | |
16 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
17 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
18 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
19 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
20 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
21 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
22 | .\" SUCH DAMAGE. | |
23 | .\" | |
24 | .\" Portions of this text are reprinted and reproduced in electronic form | |
25 | .\" from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- | |
26 | .\" Portable Operating System Interface (POSIX), The Open Group Base | |
27 | .\" Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of | |
28 | .\" Electrical and Electronics Engineers, Inc and The Open Group. In the | |
29 | .\" event of any discrepancy between this version and the original IEEE and | |
30 | .\" The Open Group Standard, the original IEEE and The Open Group Standard is | |
31 | .\" the referee document. The original Standard can be obtained online at | |
32 | .\" http://www.opengroup.org/unix/online.html. | |
33 | .\" | |
34 | .\" $FreeBSD$ | |
35 | .\" | |
36 | .Dd June 21, 2004 | |
f1a1da6c A |
37 | .Dt PTHREAD_ATFORK 3 |
38 | .Os | |
39 | .Sh NAME | |
40 | .Nm pthread_atfork | |
41 | .Nd register handlers to be called before and after | |
42 | .Fn fork | |
43 | .Sh SYNOPSIS | |
2546420a | 44 | .In pthread.h |
f1a1da6c | 45 | .Ft int |
2546420a A |
46 | .Fo pthread_atfork |
47 | .Fa "void \*[lp]*prepare\*[rp]\*[lp]void\*[rp]" | |
48 | .Fa "void \*[lp]*parent\*[rp]\*[lp]void\*[rp]" | |
49 | .Fa "void \*[lp]*child\*[rp]\*[lp]void\*[rp]" | |
50 | .Fc | |
f1a1da6c A |
51 | .Sh DESCRIPTION |
52 | The | |
53 | .Fn pthread_atfork | |
2546420a A |
54 | function declares fork handlers to be called before and after |
55 | .Xr fork 2 , | |
56 | in the context of the thread that called | |
57 | .Xr fork 2 . | |
58 | .Pp | |
59 | The handlers registered with | |
60 | .Fn pthread_atfork | |
61 | are called at the moments in time described below: | |
62 | .Bl -tag -width ".Fa prepare" | |
63 | .It Fa prepare | |
64 | Before | |
65 | .Xr fork 2 | |
66 | processing commences in the parent process. | |
67 | If more than one | |
f1a1da6c | 68 | .Fa prepare |
2546420a A |
69 | handler is registered they will be called in the opposite order |
70 | they were registered. | |
71 | .It Fa parent | |
72 | After | |
73 | .Xr fork 2 | |
74 | completes in the parent process. | |
75 | If more than one | |
f1a1da6c | 76 | .Fa parent |
2546420a A |
77 | handler is registered they will be called in the same order |
78 | they were registered. | |
79 | .It Fa child | |
80 | After | |
81 | .Xr fork 2 | |
82 | processing completes in the child process. | |
83 | If more than one | |
f1a1da6c | 84 | .Fa child |
2546420a A |
85 | handler is registered they will be called in the same order |
86 | they were registered. | |
87 | .El | |
88 | .Pp | |
89 | If no handling is desired at one or more of these three points, | |
90 | a null pointer may be passed as the corresponding fork handler. | |
f1a1da6c A |
91 | .Pp |
92 | .Em Important : | |
93 | only async-signal-safe functions are allowed on the child side of | |
94 | .Fn fork . | |
95 | See | |
96 | .Xr sigaction 2 | |
97 | for details. | |
98 | .Sh RETURN VALUES | |
99 | If successful, the | |
100 | .Fn pthread_atfork | |
2546420a A |
101 | function will return zero. |
102 | Otherwise an error number will be returned to indicate the error. | |
f1a1da6c | 103 | .Sh ERRORS |
2546420a | 104 | The |
f1a1da6c | 105 | .Fn pthread_atfork |
2546420a | 106 | function will fail if: |
f1a1da6c A |
107 | .Bl -tag -width Er |
108 | .It Bq Er ENOMEM | |
109 | The system lacked the necessary resources to add another handler to the list. | |
110 | .El | |
111 | .Sh SEE ALSO | |
2546420a A |
112 | .Xr fork 2 , |
113 | .Xr pthread 3 | |
f1a1da6c | 114 | .Sh STANDARDS |
2546420a | 115 | The |
f1a1da6c A |
116 | .Fn pthread_atfork |
117 | conforms to | |
118 | .St -p1003.1-96 . |