Register fork handlers.
2. Syntax
1 |
int pthread_atfork(void (*prepare)(void), |
3. Param
prepare
The prepare fork handler.
parent
The parent fork handler.
child
The child fork handler.
4. Return Value
Upon successful, return zero; otherwise, an error number shall be returned to indicate the error.
5. Remark
-
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 handler 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.
-
If a fork() call in a multi-threaded process leads to a child fork handler calling any function that is not async-signal-safe, the behavior is undefined.
-
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.
6. Example
1 |
#include <stdio.h> |
1 |
PrepareWhenFork1 26 |
1 |
The invocation of PrepareWhenFork() is early than ParentWhenFork() and ChildWhenFork(), the order of other is unknown. |
近期评论