1 .\" $NetBSD: clone.2,v 1.13 2012/01/29 11:44:54 wiz Exp $
3 .\" Copyright (c) 2001 The NetBSD Foundation, Inc.
4 .\" All rights reserved.
6 .\" This code is derived from software contributed to The NetBSD Foundation
7 .\" by Jason R. Thorpe.
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.
36 .Nd spawn new process with options
42 .Fn clone "int (*func)(void *arg)" "void *stack" "int flags" "void *arg"
44 .Fn __clone "int (*func)(void *arg)" "void *stack" "int flags" "void *arg"
48 system call (and associated library support code) creates a new process
49 in a way that allows the caller to specify several options for the new
56 in which the child process returns to the call site,
58 causes the child process to begin execution at the function specified
63 is passed to the entry point, as a means for the parent to provide
65 The stack pointer for the child process will be set to
69 interface requires that the application know the stack direction
70 for the architecture, and that the caller initialize the
72 argument as appropriate for the stack direction.
76 argument specifies several options that control how the child process
80 specify the signal that is to be sent to the parent when the child
82 The following flags may also be specified by bitwise-or'ing
83 them with the signal value:
84 .Bl -tag -width "CLONE_SIGHAND" -offset 2n
86 Share the virtual address space with the parent.
87 The address space is shared in the same way as
91 .Dq file system information
93 This include the current working directory and file creation mask.
95 Share the file descriptor table with the parent.
97 Share the signal handler set with the parent.
98 Note that the signal mask
99 is never shared between the parent and the child, even if
103 Preserve the synchronization semantics of
105 the parent blocks until the child exits.
110 call returns the pid of the child in the parent's context.
111 The child is provided no return value, since it begins execution at
114 If the child process's entry point returns, the value it returns
117 and the child process exits.
118 Note that if the child process wants to exit directly, it should use
124 will flush and close standard I/O channels, and thereby corrupt the
125 parent process's standard I/O data structures (even with
129 since buffered data would then be flushed twice).
133 is not intended to be used for new native
136 It is provided as a means to port software
137 originally written for the Linux operating system to
157 function call appeared in
159 It is compatible with the Linux function call of the same name
160 with respect to the described options.
166 does not implement the following
168 that are present in the Linux implementation:
170 .Bl -bullet -offset indent -compact
172 .Dv CLONE_CHILD_CLEARTID
174 .Dv CLONE_CHILD_SETTID
190 .Dv CLONE_PARENT_SETTID