Skip site navigation (1)Skip section navigation (2)

FreeBSD Manual Pages

  
 
  

home | help
PTHREAD_ATFORK(3)      FreeBSD Library Functions Manual	     PTHREAD_ATFORK(3)

NAME
     pthread_atfork -- specify handler functions to call when the process
     forks

SYNOPSIS
     #include <pthread.h>

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

DESCRIPTION
     The pthread_atfork() function declares fork handlers to be	called before
     and after fork(2),	in the context of the thread that called fork(2).  The
     prepare fork handler will be called before	fork(2)	processing commences.
     The parent	fork handler will be called after fork(2) processing completes
     in	the parent process.  The child fork handler will be called after
     fork(2) processing	completes in the child process.	 If no handling	is de-
     sired at one or more of these three points, the corresponding fork	han-
     dler address(es) may be set to NULL.

     The order of calls	to pthread_atfork() is significant.  The parent	and
     child fork	handlers will be called	in the order in	which they were	estab-
     lished by calls to	pthread_atfork().  The prepare fork handlers will be
     called in the opposite order.

     If	a shared object	is unloaded from process memory	using dlclose(3), then
     any functions registered by calling pthread_atfork() from that shared ob-
     ject will be unregistered without being invoked.  Note that it is the
     source of the call	to pthread_atfork() that matters, not the source of
     the functions that	were registered.

RETURN VALUES
     Upon successful completion, pthread_atfork() will return a	value of zero.
     Otherwise,	an error number	will be	returned to indicate the error.

ERRORS
     pthread_atfork() will fail	if:

     [ENOMEM]		Insufficient table space exists	to record the fork
			handler	addresses.  None of the	handler	lists are mod-
			ified.

SEE ALSO
     fork(2), atexit(3), dlclose(3)

STANDARDS
     pthread_atfork() conforms to IEEE Std 1003.1-2004 ("POSIX.1").

     The behavior when a shared	object is unloaded is an extension to that
     standard.

FreeBSD	13.0			 May 15, 2015			  FreeBSD 13.0

NAME | SYNOPSIS | DESCRIPTION | RETURN VALUES | ERRORS | SEE ALSO | STANDARDS

Want to link to this manual page? Use this URL:
<https://www.freebsd.org/cgi/man.cgi?query=pthread_atfork&sektion=3&manpath=OpenBSD+6.9>

home | help