pthread_atfork(3pthread)


pthread_atfork -- register fork handlers

Synopsis

cc [options] -Kthread file

#include <sys/types.h> #include <unistd.h>

int pthread_atfork(void (*prepare)(void), void (*parent)(void), void (*child)(void));

Description

pthread_atfork declares fork handlers to be called before and after fork(2), in the context of the thread that called fork. The prepare fork handler is called before fork processing commences. The parent fork handle is called after fork processing completes in the parent process. The child fork handler is 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 are called in the order in which they were established by calls to pthread_atfork. The prepare fork handlers are called in the opposite order.

Return values

Upon successful completion, pthread_atfork returns a value of zero. Otherwise, an error number is returned to indicate the error.

Diagnostics

If the following condition is detected, pthread_atfork will return the corresponding value:

ENOMEM
insufficient table space exists to record the fork handler addresses

References

atexit(3C), fork(2)

Standards compliance

The Single UNIX Specification, Version 2; The Open Group.
© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 25 April 2004