PTHREAD_ATFORK(3) BSD Programmer's Manual PTHREAD_ATFORK(3)NAMEpthread_atfork - pthread fork handlers
SYNOPSIS
#include <pthread.h>
int
pthread_atfork(void (*prepare)(void), void (*parent)(void),
void (*child)(void));
DESCRIPTION
This interface is defined by IEEE Std1003.1c (``POSIX'').
The pthread_atfork() function registers fork handlers to be called before
and after a call to fork() in the context of the thread that calls
fork(). The prepare fork handler is called before the actual fork opera-
tion is completed. The parent fork handler is called in the parent pro-
cess after the fork operation is completed. The child fork handler is
called in the newly created child process after the fork operation is
completed. Any one of prepare, parent, and child may be NULL in which
case no action is performed for that fork handler.
Multiple calls to pthread_atfork() are allowed and the order of these
calls is significant. The parent and child fork handlers are called in
the order they were established. The prepare fork handlers are called in
the reverse order.
RETURN VALUES
The pthread_atfork() function returns 0 upon successful completion. If
an error occurs, a non-zero error value is returned.
ERRORS
The pthread_atfork function may fail and return the following error:
[ENOMEM] Insufficient memory to record the the fork handlers.
SEE ALSOpthreads(3), pthread_exit(3), fork(2)STANDARDS
The pthread_atfork function conforms to IEEE Std1003.1c (``POSIX'').
HISTORY
The pthread_atfork function first appeared in BSD/OS 3.0.
BUGS
No processing is performed for for variants such as vfork(). This is in-
tentional. It is assumed that a call to vfork() will be followed by an
exec() and no atfork processing is desired.
In general calling fork() in a threaded application is a bad idea and is
discouraged.
4th Berkeley Distribution June 3, 1996 1