1 .\" $NetBSD: clone.2,v 1.12 2010/05/04 06:13:43 jruoho 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.
35 .Nd spawn new process with options
41 .Fn clone "int (*func)(void *arg)" "void *stack" "int flags" "void *arg"
43 .Fn __clone "int (*func)(void *arg)" "void *stack" "int flags" "void *arg"
47 system call (and associated library support code) creates a new process
48 in a way that allows the caller to specify several options for the new
55 in which the child process returns to the call site,
57 causes the child process to begin execution at the function specified
62 is passed to the entry point, as a means for the parent to provide
64 The stack pointer for the child process will be set to
68 interface requires that the application know the stack direction
69 for the architecture, and that the caller initialize the
71 argument as appropriate for the stack direction.
75 argument specifies several options that control how the child process
79 specify the signal that is to be sent to the parent when the child
81 The following flags may also be specified by bitwise-or'ing
82 them with the signal value:
83 .Bl -tag -width "CLONE_SIGHAND" -offset 2n
85 Share the virtual address space with the parent.
86 The address space is shared in the same way as
90 .Dq file system information
92 This include the current working directory and file creation mask.
94 Share the file descriptor table with the parent.
96 Share the signal handler set with the parent.
97 Note that the signal mask
98 is never shared between the parent and the child, even if
102 Preserve the synchronization semantics of
104 the parent blocks until the child exits.
109 call returns the pid of the child in the parent's context.
110 The child is provided no return value, since it begins execution at
113 If the child process's entry point returns, the value it returns
116 and the child process exits.
117 Note that if the child process wants to exit directly, it should use
123 will flush and close standard I/O channels, and thereby corrupt the
124 parent process's standard I/O data structures (even with
128 since buffered data would then be flushed twice).
132 is not intended to be used for new native
135 It is provided as a means to port software
136 originally written for the Linux operating system to
156 function call appeared in
158 It is compatible with the Linux function call of the same name
159 with respect to the described options.
165 does not implement the following
167 that are present in the Linux implementation:
169 .Bl -bullet -offset indent -compact
171 .Dv CLONE_CHILD_CLEARTID
173 .Dv CLONE_CHILD_SETTID
189 .Dv CLONE_PARENT_SETTID