Name
NAME
pthread_atfork — register fork handlers
SYNOPSIS
THR #include <pthread.h> int pthread_atfork(void (*prepare
)(void), void (*parent
)(void), void (*child
)(void));
DESCRIPTION
The pthread_atfork() function shall declare fork handlers to be called before and after fork(), in the context of the thread that called fork(). The prepare fork handler shall be called before fork() processing commences. The parent fork handle shall be called after fork() processing completes in the parent process. The child fork handler shall be called after fork() processing completes in the child process. If no handling is desired at one or more of these three points, the corresponding fork handler address(es) may be set to NULL.
The order of calls to pthread_atfork() is significant. The parent and child fork handlers shall be called in the order in which they were established by calls to pthread_atfork(). The prepare fork handlers shall be called in the opposite order.
RETURN VALUE
Upon successful completion, pthread_atfork() shall return a value of zero; otherwise, an error number shall be returned to indicate the error.
ERRORS
The pthread_atfork() function shall fail if:
[ENOMEM] | Insufficient table space exists to record the fork handler addresses. |
The pthread_atfork() function shall not return an error code of [EINTR].
EXAMPLES
None.
APPLICATION USAGE
None.
RATIONALE
There are at least two serious problems with the semantics of fork() in a multi-threaded program. One problem has to do with state (for example, memory) ...
Get Professional Multicore Programming: Design and Implementation for C++ Developers now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.