2003-04-16 17:34:34 +04:00
|
|
|
.\" $NetBSD: clone.2,v 1.10 2003/04/16 13:34:51 wiz Exp $
|
2001-07-17 07:05:31 +04:00
|
|
|
.\"
|
|
|
|
.\" Copyright (c) 2001 The NetBSD Foundation, Inc.
|
|
|
|
.\" All rights reserved.
|
|
|
|
.\"
|
|
|
|
.\" This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
.\" by Jason R. Thorpe.
|
|
|
|
.\"
|
|
|
|
.\" 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.
|
|
|
|
.\" 3. All advertising materials mentioning features or use of this software
|
|
|
|
.\" must display the following acknowledgement:
|
|
|
|
.\" This product includes software developed by the NetBSD
|
|
|
|
.\" Foundation, Inc. and its contributors.
|
|
|
|
.\" 4. Neither the name of The NetBSD Foundation nor the names of its
|
|
|
|
.\" contributors may be used to endorse or promote products derived
|
|
|
|
.\" from this software without specific prior written permission.
|
|
|
|
.\"
|
|
|
|
.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
|
|
|
|
.\"
|
|
|
|
.Dd July 16, 2001
|
|
|
|
.Dt CLONE 2
|
|
|
|
.Os
|
|
|
|
.Sh NAME
|
|
|
|
.Nm clone
|
|
|
|
.Nd spawn new process with options
|
|
|
|
.Sh LIBRARY
|
|
|
|
.Lb libc
|
|
|
|
.Sh SYNOPSIS
|
2003-04-16 17:34:34 +04:00
|
|
|
.In sched.h
|
2001-07-17 07:05:31 +04:00
|
|
|
.Ft pid_t
|
2001-07-18 23:29:40 +04:00
|
|
|
.Fn clone "int (*func)(void *arg)" "void *stack" "int flags" "void *arg"
|
2001-07-17 07:05:31 +04:00
|
|
|
.Ft pid_t
|
2001-07-18 23:29:40 +04:00
|
|
|
.Fn __clone "int (*func)(void *arg)" "void *stack" "int flags" "void *arg"
|
2001-07-17 07:05:31 +04:00
|
|
|
.Sh DESCRIPTION
|
|
|
|
The
|
|
|
|
.Nm
|
|
|
|
system call (and associated library support code) creates a new process
|
|
|
|
in a way that allows the caller to specify several options for the new
|
|
|
|
process creation.
|
|
|
|
.Pp
|
|
|
|
Unlike
|
|
|
|
.Xr fork 2
|
|
|
|
or
|
|
|
|
.Xr vfork 2 ,
|
|
|
|
in which the child process returns to the call site,
|
|
|
|
.Nm
|
|
|
|
causes the child process to begin execution at the function specified
|
|
|
|
by
|
|
|
|
.Ar func .
|
|
|
|
The argument
|
|
|
|
.Ar arg
|
|
|
|
is passed to the entry point, as a means for the parent to provide
|
2002-10-01 22:10:43 +04:00
|
|
|
context to the child.
|
|
|
|
The stack pointer for the child process will be set to
|
2001-07-17 07:05:31 +04:00
|
|
|
.Ar stack .
|
|
|
|
Note that the
|
|
|
|
.Nm
|
|
|
|
interface requires that the application know the stack direction
|
|
|
|
for the architecture, and that the caller initialize the
|
|
|
|
.Ar stack
|
|
|
|
argument as appropriate for the stack direction.
|
|
|
|
.Pp
|
|
|
|
The
|
|
|
|
.Ar flags
|
|
|
|
argument specifies several options that control how the child process
|
2002-10-01 22:10:43 +04:00
|
|
|
is created.
|
|
|
|
The lower 8 bits of
|
2001-07-17 07:05:31 +04:00
|
|
|
.Ar flags
|
|
|
|
specify the signal that is to be sent to the parent when the child
|
2002-10-01 22:10:43 +04:00
|
|
|
exits.
|
|
|
|
The following flags may also be specified by bitwise-or'ing
|
2001-07-17 07:05:31 +04:00
|
|
|
them with the signal value:
|
|
|
|
.Bl -tag -width "CLONE_SIGHAND"
|
|
|
|
.It Dv CLONE_VM
|
2002-10-01 22:10:43 +04:00
|
|
|
Share the virtual address space with the parent.
|
|
|
|
The address space is shared in the same way as
|
2001-07-17 07:05:31 +04:00
|
|
|
.Xr vfork 2 .
|
|
|
|
.It Dv CLONE_FS
|
|
|
|
Share the
|
|
|
|
.Dq file system information
|
2002-10-01 22:10:43 +04:00
|
|
|
with the parent.
|
|
|
|
This include the current working directory and file creation mask.
|
2001-07-17 07:05:31 +04:00
|
|
|
.It Dv CLONE_FILES
|
|
|
|
Share the file descriptor table with the parent.
|
|
|
|
.It Dv CLONE_SIGHAND
|
2002-10-01 22:10:43 +04:00
|
|
|
Share the signal handler set with the parent.
|
|
|
|
Note that the signal mask
|
2001-07-17 07:05:31 +04:00
|
|
|
is never shared between the parent and the child, even if
|
|
|
|
.Dv CLONE_SIGHAND
|
|
|
|
is set.
|
2001-07-18 01:16:52 +04:00
|
|
|
.It Dv CLONE_VFORK
|
2003-03-31 07:02:22 +04:00
|
|
|
Preserve the synchronization semantics of
|
2001-07-18 01:16:52 +04:00
|
|
|
.Xr vfork 2 ;
|
|
|
|
the parent blocks until the child exits.
|
2001-07-17 07:05:31 +04:00
|
|
|
.El
|
|
|
|
.Pp
|
2001-09-16 05:38:59 +04:00
|
|
|
The
|
2001-07-17 07:05:31 +04:00
|
|
|
.Nm
|
2002-10-01 22:10:43 +04:00
|
|
|
call returns the pid of the child in the parent's context.
|
|
|
|
The child is provided no return value, since it begins execution at
|
|
|
|
a different address.
|
2001-07-17 07:05:31 +04:00
|
|
|
.Pp
|
|
|
|
If the child process's entry point returns, the value it returns
|
|
|
|
is passed to
|
|
|
|
.Xr _exit 2 ,
|
2002-10-01 22:10:43 +04:00
|
|
|
and the child process exits.
|
|
|
|
Note that if the child process wants to exit directly, it should use
|
2001-07-17 07:05:31 +04:00
|
|
|
.Xr _exit 2 ,
|
|
|
|
and not
|
|
|
|
.Xr exit 3 ,
|
|
|
|
since
|
|
|
|
.Xr exit 3
|
|
|
|
will flush and close standard I/O channels, and thereby corrupt the
|
|
|
|
parent process's standard I/O data structures (even with
|
|
|
|
.Xr fork 2
|
|
|
|
it is wrong to call
|
|
|
|
.Xr exit 3
|
|
|
|
since buffered data would then be flushed twice).
|
|
|
|
.Pp
|
|
|
|
Note that
|
|
|
|
.Nm
|
|
|
|
is not intended to be used for new native
|
|
|
|
.Nx
|
2002-10-01 22:10:43 +04:00
|
|
|
applications.
|
|
|
|
It is provided as a means to port software
|
2001-07-17 07:05:31 +04:00
|
|
|
originally written for the Linux operating system to
|
|
|
|
.Nx .
|
2001-09-16 06:13:26 +04:00
|
|
|
.Sh RETURN VALUES
|
|
|
|
Same as for
|
|
|
|
.Xr fork 2 .
|
|
|
|
.Sh ERRORS
|
2001-07-17 07:05:31 +04:00
|
|
|
Same as for
|
|
|
|
.Xr fork 2 .
|
|
|
|
.Sh SEE ALSO
|
|
|
|
.Xr chdir 2 ,
|
|
|
|
.Xr chroot 2 ,
|
|
|
|
.Xr fork 2 ,
|
|
|
|
.Xr sigaction 2 ,
|
|
|
|
.Xr sigprocmask 2 ,
|
|
|
|
.Xr umask 2 ,
|
2001-09-16 06:13:26 +04:00
|
|
|
.Xr vfork 2 ,
|
2001-07-17 07:05:31 +04:00
|
|
|
.Xr wait 2
|
2001-09-16 06:13:26 +04:00
|
|
|
.Sh HISTORY
|
|
|
|
The
|
|
|
|
.Fn clone
|
|
|
|
function call appeared in
|
|
|
|
.Nx 1.6 .
|
|
|
|
It is compatible with the Linux function call of the same name.
|
2001-07-17 07:05:31 +04:00
|
|
|
.Sh BUGS
|
|
|
|
The
|
|
|
|
.Nx
|
2001-07-18 01:16:52 +04:00
|
|
|
implementation of
|
2001-07-17 07:05:31 +04:00
|
|
|
.Nm
|
|
|
|
does not implement the
|
|
|
|
.Dv CLONE_PID
|
|
|
|
option that is present in the Linux implementation.
|
2001-07-18 01:16:52 +04:00
|
|
|
.Pp
|
|
|
|
The
|
|
|
|
.Nx
|
|
|
|
implementation of
|
|
|
|
.Nm
|
|
|
|
does not implement the
|
|
|
|
.Dv CLONE_PTRACE
|
|
|
|
option that is present in the Linux implementation.
|