1 .\" $NetBSD: pthread_atfork.3,v 1.4 2005/06/17 18:08:00 peter Exp $
3 .\" Copyright (c) 2003 The NetBSD Foundation, Inc.
4 .\" All rights reserved.
6 .\" This code is derived from software contributed to The NetBSD Foundation
7 .\" by Nathan J. Williams.
9 .\" Redistribution and use in source and binary forms, with or without
10 .\" modification, are permitted provided that the following conditions
12 .\" 1. Redistributions of source code must retain the above copyright
13 .\" notice, this list of conditions and the following disclaimer.
14 .\" 2. Redistributions in binary form must reproduce the above copyright
15 .\" notice, this list of conditions and the following disclaimer in the
16 .\" documentation and/or other materials provided with the distribution.
18 .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19 .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20 .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22 .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 .\" POSSIBILITY OF SUCH DAMAGE.
35 .Nd register handlers to be called when process forks
41 .Fn pthread_atfork "void (*prepare)(void)" "void (*parent)(void)" "void (*child)(void)"
45 function registers the provided handler functions to be called when the
48 Each of the three handlers is called at a different place in the
53 handler is called in the parent process before the fork happens, the
55 handler is called in the parent process after the fork has happened, and the
57 handler is called in the child process after the fork has happened.
62 handlers are called in the order in which they were registered, while the
64 handlers are called in reverse of the order in which they were registered.
66 Any of the handlers given may be
71 is to provide a consistent state to a child process from a multithreaded parent
72 process where locks may be acquired and released asynchronously with respect to the
75 Each subsystem with locks that are used in a child process should register
78 that acquires those locks in the
80 handler and releases them in the
86 function returns 0 on success and an error number on failure.
88 The following error code may be returned:
91 Insufficient memory exists to register the fork handlers.
103 function first appeared in
108 from a multithreaded process, it is only safe to call
109 async-signal-safe functions until calling one of the
114 functions are not async-signal-safe, so it is not safe to use such functions
119 There is no way to unregister a handler registered with