atfork(3thr)
Name
atfork − Arranges for fork cleanup handling
Syntax
#include <pthread.h>
void pthread_create (user_state, pre_fork, parent_fork, child_fork)
void *user_state;
void *pre_fork();
void *parent_fork();
void *child_fork();
Arguments
user_state
Pointer to the user state that is passed to each routine.
pre_fork Routine to be called before performing the fork.
parent_fork
Routine to be called after the fork, in the parent.
child_fork
Routine to be called after the fork, in the child.
Description
This routine allows you to register three routines to be executed at different times relative to a fork. The different times and/or places are:
Just prior to the fork in the parent process
Just after the fork in the parent process
Just after the fork in the created (child) process
Use these routines to clean up just prior to fork(), to set up after fork(), and to perform locking relative to fork(). You are allowed to provide one argument to be used in conjunction with all the routines. This parameter must be: user_state.
Note that if your library’s pre-fork action routine consists of locking all of your library’s mutexes, then your library must be coded such that your code never holds a mutex during a call to another library which would lock one of that library’s mutexes. Otherwise, you risk entering a deadlock when your pre-fork action routine is called, if the the other library has an analogous pre-fork action routine that has already been called for this fork.
Return Values
This routine returns 0 if successful. Otherwise, it returns -1 if there is insufficient table space to record the handler addresses.