Registers fork handlers.
Threads Library (libpthreads.a)
#include <sys/types.h> #include <unistd.h>
The pthread_atfork subroutine registers fork cleanup handlers. The prepare handler is called before the processing of the fork subroutine commences. The parent handler is called after the processing of the fork subroutine completes in the parent process. The child handler is called after the processing of the fork subroutine completes in the child process.
When the fork subroutine is called, only the calling thread is duplicated in the child process, but all synchronization variables are duplicated. The pthread_atfork subroutine provides a way to prevent state inconsistencies and resulting deadlocks. The expected usage is that the prepare handler acquires all mutexes, and the two other handlers release them in the parent and child processes.
The prepare handlers are called in LIFO (Last In First Out) order; whereas the parent and child handlers are called in FIFO (first-in first-out) order. Thereafter, the order of calls to the pthread_atfork subroutine is significant.
Note: The pthread.h header file must be the first included file of each source file using the threads library.
|prepare||Points to the pre-fork cleanup handler. If no pre-fork handling is desired, the value of this pointer should be set to NULL.|
|parent||Points to the parent post-fork cleanup handler. If no parent post-fork handling is desired, the value of this pointer should be set to NULL.|
|child||Points to the child post-fork cleanup handler. If no child post-fork handling is desired, the value of this pointer should be set to NULL.|
Upon successful completion, pthread_atfork returns a value of zero. Otherwise, an error number is returned to indicate the error.
The pthread_atfork function will
|ENOMEM||Insufficient table space exists to record the fork handler addresses.|
The pthread_atfork function will not return an error code of EINTR.
This subroutine is part of the Base Operating System (BOS) Runtime.
The fork (fork, f_fork, or vfork Subroutine) subroutine, atexit (exit, atexit, or _exit Subroutine) subroutine.
Process Duplication and Termination in AIX 5L Version 5.1 General Programming Concepts: Writing and Debugging Programs.
Threads Library Quick Reference in AIX 5L Version 5.1 General Programming Concepts: Writing and Debugging Programs.