xref: /openbsd-src/lib/libpthread/man/pthread_atfork.3 (revision 53bd3188afdc7dc2ed854f2d320cdbd2c80e5467)
1.\"	$OpenBSD: pthread_atfork.3,v 1.12 2015/05/15 18:47:53 jmc Exp $
2.\"
3.\" David Leonard <d@openbsd.org>, 1999. Public domain.
4.\"
5.Dd $Mdocdate: May 15 2015 $
6.Dt PTHREAD_ATFORK 3
7.Os
8.Sh NAME
9.Nm pthread_atfork
10.Nd specify handler functions to call when the process forks
11.Sh SYNOPSIS
12.In pthread.h
13.Ft int
14.Fn pthread_atfork "void (*prepare)(void)" "void (*parent)(void)" "void (*child)(void)"
15.Sh DESCRIPTION
16The
17.Fn pthread_atfork
18function declares fork handlers to be called before and after
19.Xr fork 2 ,
20in the context of the thread that called
21.Xr fork 2 .
22The
23.Fa prepare
24fork handler will be called before
25.Xr fork 2
26processing commences.
27The
28.Fa parent
29fork handler will be called after
30.Xr fork 2
31processing completes in the parent process.
32The
33.Fa child
34fork handler will be called after
35.Xr fork 2
36processing completes in the child process.
37If no handling is desired at
38one or more of these three points,
39the corresponding fork handler
40address(es) may be set to
41.Dv NULL .
42.Pp
43The order of calls to
44.Fn pthread_atfork
45is significant.
46The
47.Fa parent
48and
49.Fa child
50fork handlers will be called in the order in which they were established
51by calls to
52.Fn pthread_atfork .
53The
54.Fa prepare
55fork handlers will be called in the opposite order.
56.Pp
57If a shared object is unloaded from process memory using
58.Xr dlclose 3 ,
59then any functions registered by calling
60.Fn pthread_atfork
61from that shared object will be unregistered without being invoked.
62Note that it is the source of the call to
63.Fn pthread_atfork
64that matters, not the source of the functions that were registered.
65.Sh RETURN VALUES
66Upon successful completion,
67.Fn pthread_atfork
68will return a value of zero.
69Otherwise, an error number will be
70returned to indicate the error.
71.Sh ERRORS
72.Fn pthread_atfork
73will fail if:
74.Bl -tag -width Er
75.It Bq Er ENOMEM
76Insufficient table space exists to record the fork handler addresses.
77None of the handler lists are modified.
78.El
79.Sh SEE ALSO
80.Xr fork 2 ,
81.Xr atexit 3 ,
82.Xr dlclose 3
83.Sh STANDARDS
84.Fn pthread_atfork
85conforms to
86.St -p1003.1-2004 .
87.Pp
88The behavior when a shared object is unloaded is an extension to
89that standard.
90