xref: /freebsd-src/share/man/man3/pthread_atfork.3 (revision fa9896e082a1046ff4fbc75fcba4d18d1f2efc19)
1a3c8fc53SGiorgos Keramidas.\" Copyright (c) 2004 Alex Vasylenko <lxv@omut.org>
2a3c8fc53SGiorgos Keramidas.\" All rights reserved.
3a3c8fc53SGiorgos Keramidas.\"
4a3c8fc53SGiorgos Keramidas.\" Redistribution and use in source and binary forms, with or without
5a3c8fc53SGiorgos Keramidas.\" modification, are permitted provided that the following conditions
6a3c8fc53SGiorgos Keramidas.\" are met:
7a3c8fc53SGiorgos Keramidas.\" 1. Redistributions of source code must retain the above copyright
8a3c8fc53SGiorgos Keramidas.\"    notice, this list of conditions and the following disclaimer.
9a3c8fc53SGiorgos Keramidas.\" 2. Redistributions in binary form must reproduce the above copyright
10a3c8fc53SGiorgos Keramidas.\"    notice, this list of conditions and the following disclaimer in the
11a3c8fc53SGiorgos Keramidas.\"    documentation and/or other materials provided with the distribution.
12a3c8fc53SGiorgos Keramidas.\"
13a3c8fc53SGiorgos Keramidas.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14a3c8fc53SGiorgos Keramidas.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15a3c8fc53SGiorgos Keramidas.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16a3c8fc53SGiorgos Keramidas.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17a3c8fc53SGiorgos Keramidas.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18a3c8fc53SGiorgos Keramidas.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19a3c8fc53SGiorgos Keramidas.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20a3c8fc53SGiorgos Keramidas.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21a3c8fc53SGiorgos Keramidas.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22a3c8fc53SGiorgos Keramidas.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23a3c8fc53SGiorgos Keramidas.\" SUCH DAMAGE.
24a3c8fc53SGiorgos Keramidas.\"
258a119ad2SGiorgos Keramidas.\" Portions of this text are reprinted and reproduced in electronic form
268a119ad2SGiorgos Keramidas.\" from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology --
278a119ad2SGiorgos Keramidas.\" Portable Operating System Interface (POSIX), The Open Group Base
288a119ad2SGiorgos Keramidas.\" Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of
298a119ad2SGiorgos Keramidas.\" Electrical and Electronics Engineers, Inc and The Open Group.  In the
308a119ad2SGiorgos Keramidas.\" event of any discrepancy between this version and the original IEEE and
318a119ad2SGiorgos Keramidas.\" The Open Group Standard, the original IEEE and The Open Group Standard is
328a119ad2SGiorgos Keramidas.\" the referee document.  The original Standard can be obtained online at
338a119ad2SGiorgos Keramidas.\"	http://www.opengroup.org/unix/online.html.
348a119ad2SGiorgos Keramidas.\"
35a3c8fc53SGiorgos Keramidas.Dd June 21, 2004
36a3c8fc53SGiorgos Keramidas.Dt PTHREAD_ATFORK 3
37a3c8fc53SGiorgos Keramidas.Os
38a3c8fc53SGiorgos Keramidas.Sh NAME
39a3c8fc53SGiorgos Keramidas.Nm pthread_atfork
40a3c8fc53SGiorgos Keramidas.Nd register fork handlers
41a3c8fc53SGiorgos Keramidas.Sh LIBRARY
42a3c8fc53SGiorgos Keramidas.Lb libpthread
43a3c8fc53SGiorgos Keramidas.Sh SYNOPSIS
44a3c8fc53SGiorgos Keramidas.In pthread.h
45a3c8fc53SGiorgos Keramidas.Ft int
46a3c8fc53SGiorgos Keramidas.Fo pthread_atfork
47a3c8fc53SGiorgos Keramidas.Fa "void \*[lp]*prepare\*[rp]\*[lp]void\*[rp]"
48a3c8fc53SGiorgos Keramidas.Fa "void \*[lp]*parent\*[rp]\*[lp]void\*[rp]"
49a3c8fc53SGiorgos Keramidas.Fa "void \*[lp]*child\*[rp]\*[lp]void\*[rp]"
50a3c8fc53SGiorgos Keramidas.Fc
51a3c8fc53SGiorgos Keramidas.Sh DESCRIPTION
52a3c8fc53SGiorgos KeramidasThe
53a3c8fc53SGiorgos Keramidas.Fn pthread_atfork
54a3c8fc53SGiorgos Keramidasfunction declares fork handlers to be called before and after
55a3c8fc53SGiorgos Keramidas.Xr fork 2 ,
56a3c8fc53SGiorgos Keramidasin the context of the thread that called
57a3c8fc53SGiorgos Keramidas.Xr fork 2 .
58a3c8fc53SGiorgos Keramidas.Pp
59a3c8fc53SGiorgos KeramidasThe handlers registered with
60a4be0b3cSRuslan Ermilov.Fn pthread_atfork
61a3c8fc53SGiorgos Keramidasare called at the moments in time described below:
62a4be0b3cSRuslan Ermilov.Bl -tag -width ".Fa prepare"
63a3c8fc53SGiorgos Keramidas.It Fa prepare
64a3c8fc53SGiorgos KeramidasBefore
65a3c8fc53SGiorgos Keramidas.Xr fork 2
66a3c8fc53SGiorgos Keramidasprocessing commences in the parent process.
67a3c8fc53SGiorgos KeramidasIf more than one
68a3c8fc53SGiorgos Keramidas.Fa prepare
69a3c8fc53SGiorgos Keramidashandler is registered they will be called in the opposite order
70a3c8fc53SGiorgos Keramidasthey were registered.
71a3c8fc53SGiorgos Keramidas.It Fa parent
72a3c8fc53SGiorgos KeramidasAfter
73a3c8fc53SGiorgos Keramidas.Xr fork 2
74a3c8fc53SGiorgos Keramidascompletes in the parent process.
75a3c8fc53SGiorgos KeramidasIf more than one
76a3c8fc53SGiorgos Keramidas.Fa parent
77a3c8fc53SGiorgos Keramidashandler is registered they will be called in the same order
78a3c8fc53SGiorgos Keramidasthey were registered.
79a3c8fc53SGiorgos Keramidas.It Fa child
80a3c8fc53SGiorgos KeramidasAfter
81a3c8fc53SGiorgos Keramidas.Xr fork 2
82a3c8fc53SGiorgos Keramidasprocessing completes in the child process.
83a3c8fc53SGiorgos KeramidasIf more than one
84a3c8fc53SGiorgos Keramidas.Fa child
85a3c8fc53SGiorgos Keramidashandler is registered they will be called in the same order
86a3c8fc53SGiorgos Keramidasthey were registered.
87a4be0b3cSRuslan Ermilov.El
88a3c8fc53SGiorgos Keramidas.Pp
89a3c8fc53SGiorgos KeramidasIf no handling is desired at one or more of these three points,
90a3c8fc53SGiorgos Keramidasa null pointer may be passed as the corresponding fork handler.
91a3c8fc53SGiorgos Keramidas.Sh RETURN VALUES
92a3c8fc53SGiorgos KeramidasIf successful, the
93a3c8fc53SGiorgos Keramidas.Fn pthread_atfork
94a3c8fc53SGiorgos Keramidasfunction will return zero.
95a3c8fc53SGiorgos KeramidasOtherwise an error number will be returned to indicate the error.
96a3c8fc53SGiorgos Keramidas.Sh ERRORS
97a3c8fc53SGiorgos KeramidasThe
98a3c8fc53SGiorgos Keramidas.Fn pthread_atfork
99a3c8fc53SGiorgos Keramidasfunction will fail if:
100a3c8fc53SGiorgos Keramidas.Bl -tag -width Er
101a3c8fc53SGiorgos Keramidas.It Bq Er ENOMEM
102a3c8fc53SGiorgos KeramidasInsufficient table space exists to record the fork handler addresses.
103a4be0b3cSRuslan Ermilov.El
104a3c8fc53SGiorgos Keramidas.Sh SEE ALSO
105a3c8fc53SGiorgos Keramidas.Xr fork 2 ,
106a3c8fc53SGiorgos Keramidas.Xr pthread 3
107a3c8fc53SGiorgos Keramidas.Sh STANDARDS
108a3c8fc53SGiorgos KeramidasThe
109a3c8fc53SGiorgos Keramidas.Fn pthread_atfork
110a3c8fc53SGiorgos Keramidasfunction is expected to conform to
111a3c8fc53SGiorgos Keramidas.St -p1003.1 .
112a3c8fc53SGiorgos Keramidas.Sh AUTHORS
113a3c8fc53SGiorgos KeramidasThis manpage was written by
114*a63d6c94SBaptiste Daroussin.An Alex Vasylenko Aq Mt lxv@omut.org .
115