xref: /openbsd-src/lib/libpthread/man/pthread_atfork.3 (revision a28daedfc357b214be5c701aa8ba8adb29a7f1c2)
1.\"	$OpenBSD: pthread_atfork.3,v 1.9 2007/05/31 19:19:36 jmc Exp $
2.\"
3.\" David Leonard <d@openbsd.org>, 1999. Public domain.
4.\"
5.Dd $Mdocdate: May 31 2007 $
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.Fd #include <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.Fn fork ,
20in the context of the thread that called
21.Fn fork .
22The
23.Fa prepare
24fork handler will be called before
25.Fn fork
26processing commences.
27The
28.Fa parent
29fork handler will be called after
30.Fn fork
31processing completes in the parent process.
32The
33.Fa child
34fork handler will be called after
35.Fn fork
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.Sh RETURN VALUES
57Upon successful completion,
58.Fn pthread_atfork
59will return a value of zero.
60Otherwise, an error number will be
61returned to indicate the error.
62.Sh ERRORS
63.Fn pthread_atfork
64will fail if:
65.Bl -tag -width Er
66.It Bq Er ENOMEM
67Insufficient table space exists to record the fork handler addresses.
68None of the handler lists are modified.
69.El
70.Sh SEE ALSO
71.Xr fork 2 ,
72.Xr atexit 3
73.Sh STANDARDS
74.Fn pthread_atfork
75conforms to
76.St -p1003.1-2004 .
77