(CFLAGS-tst-align.c): Add -mpreferred-stack-boundary=4.
[glibc.git] / linuxthreads / man / pthread_atfork.man
blobb682bed3ac8e93cda187b1361920ca2966529cf1
1 .TH PTHREAD_ATFORK 3 LinuxThreads
3 .SH NAME
4 pthread_atfork \- register handlers to be called at fork(2) time
6 .SH SYNOPSIS
7 #include <pthread.h>
9 int pthread_atfork(void (*prepare)(void), void (*parent)(void), void (*child)(void));
11 .SH DESCRIPTION
13 !pthread_atfork! registers handler functions to be called just before
14 and just after a new process is created with !fork!(2). The |prepare|
15 handler will be called from the parent process, just before the new
16 process is created. The |parent| handler will be called from the parent
17 process, just before !fork!(2) returns. The |child| handler will be
18 called from the child process, just before !fork!(2) returns.
20 One or several of the three handlers |prepare|, |parent| and |child|
21 can be given as !NULL!, meaning that no handler needs to be called at
22 the corresponding point.
24 !pthread_atfork! can be called several times to install several sets
25 of handlers. At !fork!(2) time, the |prepare| handlers are called in
26 LIFO order (last added with !pthread_atfork!, first called before !fork!),
27 while the |parent| and |child| handlers are called in FIFO order
28 (first added, first called).
30 To understand the purpose of !pthread_atfork!, recall that !fork!(2)
31 duplicates the whole memory space, including mutexes in their current
32 locking state, but only the calling thread: other threads are not
33 running in the child process.  The mutexes are not usable after the
34 !fork! and must be initialized with |pthread_mutex_init| in the child
35 process.  This is a limitation of the current implementation and might
36 or might not be present in future versions.
38 .SH "RETURN VALUE"
40 !pthread_atfork! returns 0 on success and a non-zero error code on error.
42 .SH ERRORS
43 .TP
44 !ENOMEM!
45 insufficient memory available to register the handlers.
47 .SH AUTHOR
48 Xavier Leroy <Xavier.Leroy@inria.fr>
50 .SH "SEE ALSO"
51 !fork!(2),
52 !pthread_mutex_lock!(3),
53 !pthread_mutex_unlock!(3).