.\" Copyright (c) 2004 Apple Computer, Inc.
.\"
-.Dd August 12, 2004
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\" Portions of this text are reprinted and reproduced in electronic form
+.\" from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology --
+.\" Portable Operating System Interface (POSIX), The Open Group Base
+.\" Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of
+.\" Electrical and Electronics Engineers, Inc and The Open Group. In the
+.\" event of any discrepancy between this version and the original IEEE and
+.\" The Open Group Standard, the original IEEE and The Open Group Standard is
+.\" the referee document. The original Standard can be obtained online at
+.\" http://www.opengroup.org/unix/online.html.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd June 21, 2004
.Dt PTHREAD_ATFORK 3
.Os
.Sh NAME
.Nd register handlers to be called before and after
.Fn fork
.Sh SYNOPSIS
-.Fd #include <pthread.h>
+.In pthread.h
.Ft int
-.Fn pthread_atfork "void (*prepare)(void)" "void (*parent)(void)" "void (*child)(void)"
+.Fo pthread_atfork
+.Fa "void \*[lp]*prepare\*[rp]\*[lp]void\*[rp]"
+.Fa "void \*[lp]*parent\*[rp]\*[lp]void\*[rp]"
+.Fa "void \*[lp]*child\*[rp]\*[lp]void\*[rp]"
+.Fc
.Sh DESCRIPTION
The
.Fn pthread_atfork
-function is used to register functions to be called before and after
-.Fn fork .
-The
-.Fa prepare
-handler is called before
-.Fn fork ,
-while the
-.Fa parent
-and
-.Fa child
-handlers are called after
-.Fn fork
-in the parent and child process respectively.
-The
+function declares fork handlers to be called before and after
+.Xr fork 2 ,
+in the context of the thread that called
+.Xr fork 2 .
+.Pp
+The handlers registered with
+.Fn pthread_atfork
+are called at the moments in time described below:
+.Bl -tag -width ".Fa prepare"
+.It Fa prepare
+Before
+.Xr fork 2
+processing commences in the parent process.
+If more than one
.Fa prepare
-handlers are called in reverse order of their registration, while
+handler is registered they will be called in the opposite order
+they were registered.
+.It Fa parent
+After
+.Xr fork 2
+completes in the parent process.
+If more than one
.Fa parent
-and
+handler is registered they will be called in the same order
+they were registered.
+.It Fa child
+After
+.Xr fork 2
+processing completes in the child process.
+If more than one
.Fa child
-handlers are called in the order in which they were registered.
-Any of the handlers may be NULL.
+handler is registered they will be called in the same order
+they were registered.
+.El
+.Pp
+If no handling is desired at one or more of these three points,
+a null pointer may be passed as the corresponding fork handler.
.Pp
.Em Important :
only async-signal-safe functions are allowed on the child side of
.Sh RETURN VALUES
If successful, the
.Fn pthread_atfork
-function will return zero; otherwise an error number will be returned to
-indicate the error.
+function will return zero.
+Otherwise an error number will be returned to indicate the error.
.Sh ERRORS
+The
.Fn pthread_atfork
-will fail if:
+function will fail if:
.Bl -tag -width Er
.It Bq Er ENOMEM
The system lacked the necessary resources to add another handler to the list.
.El
.Sh SEE ALSO
-.Xr fork 2
+.Xr fork 2 ,
+.Xr pthread 3
.Sh STANDARDS
+The
.Fn pthread_atfork
conforms to
.St -p1003.1-96 .