xref: /minix3/lib/libc/sys/clone.2 (revision f14fb602092e015ff630df58e17c2a9cd57d29b3)
1*f14fb602SLionel Sambuc.\"	$NetBSD: clone.2,v 1.13 2012/01/29 11:44:54 wiz Exp $
22fe8fb19SBen Gras.\"
32fe8fb19SBen Gras.\" Copyright (c) 2001 The NetBSD Foundation, Inc.
42fe8fb19SBen Gras.\" All rights reserved.
52fe8fb19SBen Gras.\"
62fe8fb19SBen Gras.\" This code is derived from software contributed to The NetBSD Foundation
72fe8fb19SBen Gras.\" by Jason R. Thorpe.
82fe8fb19SBen Gras.\"
92fe8fb19SBen Gras.\" Redistribution and use in source and binary forms, with or without
102fe8fb19SBen Gras.\" modification, are permitted provided that the following conditions
112fe8fb19SBen Gras.\" are met:
122fe8fb19SBen Gras.\" 1. Redistributions of source code must retain the above copyright
132fe8fb19SBen Gras.\"    notice, this list of conditions and the following disclaimer.
142fe8fb19SBen Gras.\" 2. Redistributions in binary form must reproduce the above copyright
152fe8fb19SBen Gras.\"    notice, this list of conditions and the following disclaimer in the
162fe8fb19SBen Gras.\"    documentation and/or other materials provided with the distribution.
172fe8fb19SBen Gras.\"
182fe8fb19SBen Gras.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
192fe8fb19SBen Gras.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
202fe8fb19SBen Gras.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
212fe8fb19SBen Gras.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
222fe8fb19SBen Gras.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
232fe8fb19SBen Gras.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
242fe8fb19SBen Gras.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
252fe8fb19SBen Gras.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
262fe8fb19SBen Gras.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
272fe8fb19SBen Gras.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
282fe8fb19SBen Gras.\" POSSIBILITY OF SUCH DAMAGE.
292fe8fb19SBen Gras.\"
302fe8fb19SBen Gras.Dd May 4, 2010
312fe8fb19SBen Gras.Dt CLONE 2
322fe8fb19SBen Gras.Os
332fe8fb19SBen Gras.Sh NAME
34*f14fb602SLionel Sambuc.Nm clone ,
35*f14fb602SLionel Sambuc.Nm __clone
362fe8fb19SBen Gras.Nd spawn new process with options
372fe8fb19SBen Gras.Sh LIBRARY
382fe8fb19SBen Gras.Lb libc
392fe8fb19SBen Gras.Sh SYNOPSIS
402fe8fb19SBen Gras.In sched.h
412fe8fb19SBen Gras.Ft pid_t
422fe8fb19SBen Gras.Fn clone "int (*func)(void *arg)" "void *stack" "int flags" "void *arg"
432fe8fb19SBen Gras.Ft pid_t
442fe8fb19SBen Gras.Fn __clone "int (*func)(void *arg)" "void *stack" "int flags" "void *arg"
452fe8fb19SBen Gras.Sh DESCRIPTION
462fe8fb19SBen GrasThe
472fe8fb19SBen Gras.Nm
482fe8fb19SBen Grassystem call (and associated library support code) creates a new process
492fe8fb19SBen Grasin a way that allows the caller to specify several options for the new
502fe8fb19SBen Grasprocess creation.
512fe8fb19SBen Gras.Pp
522fe8fb19SBen GrasUnlike
532fe8fb19SBen Gras.Xr fork 2
542fe8fb19SBen Grasor
552fe8fb19SBen Gras.Xr vfork 2 ,
562fe8fb19SBen Grasin which the child process returns to the call site,
572fe8fb19SBen Gras.Nm
582fe8fb19SBen Grascauses the child process to begin execution at the function specified
592fe8fb19SBen Grasby
602fe8fb19SBen Gras.Ar func .
612fe8fb19SBen GrasThe argument
622fe8fb19SBen Gras.Ar arg
632fe8fb19SBen Grasis passed to the entry point, as a means for the parent to provide
642fe8fb19SBen Grascontext to the child.
652fe8fb19SBen GrasThe stack pointer for the child process will be set to
662fe8fb19SBen Gras.Ar stack .
672fe8fb19SBen GrasNote that the
682fe8fb19SBen Gras.Nm
692fe8fb19SBen Grasinterface requires that the application know the stack direction
702fe8fb19SBen Grasfor the architecture, and that the caller initialize the
712fe8fb19SBen Gras.Ar stack
722fe8fb19SBen Grasargument as appropriate for the stack direction.
732fe8fb19SBen Gras.Pp
742fe8fb19SBen GrasThe
752fe8fb19SBen Gras.Ar flags
762fe8fb19SBen Grasargument specifies several options that control how the child process
772fe8fb19SBen Grasis created.
782fe8fb19SBen GrasThe lower 8 bits of
792fe8fb19SBen Gras.Ar flags
802fe8fb19SBen Grasspecify the signal that is to be sent to the parent when the child
812fe8fb19SBen Grasexits.
822fe8fb19SBen GrasThe following flags may also be specified by bitwise-or'ing
832fe8fb19SBen Grasthem with the signal value:
842fe8fb19SBen Gras.Bl -tag -width "CLONE_SIGHAND" -offset 2n
852fe8fb19SBen Gras.It Dv CLONE_VM
862fe8fb19SBen GrasShare the virtual address space with the parent.
872fe8fb19SBen GrasThe address space is shared in the same way as
882fe8fb19SBen Gras.Xr vfork 2 .
892fe8fb19SBen Gras.It Dv CLONE_FS
902fe8fb19SBen GrasShare the
912fe8fb19SBen Gras.Dq file system information
922fe8fb19SBen Graswith the parent.
932fe8fb19SBen GrasThis include the current working directory and file creation mask.
942fe8fb19SBen Gras.It Dv CLONE_FILES
952fe8fb19SBen GrasShare the file descriptor table with the parent.
962fe8fb19SBen Gras.It Dv CLONE_SIGHAND
972fe8fb19SBen GrasShare the signal handler set with the parent.
982fe8fb19SBen GrasNote that the signal mask
992fe8fb19SBen Grasis never shared between the parent and the child, even if
1002fe8fb19SBen Gras.Dv CLONE_SIGHAND
1012fe8fb19SBen Grasis set.
1022fe8fb19SBen Gras.It Dv CLONE_VFORK
1032fe8fb19SBen GrasPreserve the synchronization semantics of
1042fe8fb19SBen Gras.Xr vfork 2 ;
1052fe8fb19SBen Grasthe parent blocks until the child exits.
1062fe8fb19SBen Gras.El
1072fe8fb19SBen Gras.Pp
1082fe8fb19SBen GrasThe
1092fe8fb19SBen Gras.Nm
1102fe8fb19SBen Grascall returns the pid of the child in the parent's context.
1112fe8fb19SBen GrasThe child is provided no return value, since it begins execution at
1122fe8fb19SBen Grasa different address.
1132fe8fb19SBen Gras.Pp
1142fe8fb19SBen GrasIf the child process's entry point returns, the value it returns
1152fe8fb19SBen Grasis passed to
1162fe8fb19SBen Gras.Xr _exit 2 ,
1172fe8fb19SBen Grasand the child process exits.
1182fe8fb19SBen GrasNote that if the child process wants to exit directly, it should use
1192fe8fb19SBen Gras.Xr _exit 2 ,
1202fe8fb19SBen Grasand not
1212fe8fb19SBen Gras.Xr exit 3 ,
1222fe8fb19SBen Grassince
1232fe8fb19SBen Gras.Xr exit 3
1242fe8fb19SBen Graswill flush and close standard I/O channels, and thereby corrupt the
1252fe8fb19SBen Grasparent process's standard I/O data structures (even with
1262fe8fb19SBen Gras.Xr fork 2
1272fe8fb19SBen Grasit is wrong to call
1282fe8fb19SBen Gras.Xr exit 3
1292fe8fb19SBen Grassince buffered data would then be flushed twice).
1302fe8fb19SBen Gras.Pp
1312fe8fb19SBen GrasNote that
1322fe8fb19SBen Gras.Nm
1332fe8fb19SBen Grasis not intended to be used for new native
1342fe8fb19SBen Gras.Nx
1352fe8fb19SBen Grasapplications.
1362fe8fb19SBen GrasIt is provided as a means to port software
1372fe8fb19SBen Grasoriginally written for the Linux operating system to
1382fe8fb19SBen Gras.Nx .
1392fe8fb19SBen Gras.Sh RETURN VALUES
1402fe8fb19SBen GrasSame as for
1412fe8fb19SBen Gras.Xr fork 2 .
1422fe8fb19SBen Gras.Sh ERRORS
1432fe8fb19SBen GrasSame as for
1442fe8fb19SBen Gras.Xr fork 2 .
1452fe8fb19SBen Gras.Sh SEE ALSO
1462fe8fb19SBen Gras.Xr chdir 2 ,
1472fe8fb19SBen Gras.Xr chroot 2 ,
1482fe8fb19SBen Gras.Xr fork 2 ,
1492fe8fb19SBen Gras.Xr sigaction 2 ,
1502fe8fb19SBen Gras.Xr sigprocmask 2 ,
1512fe8fb19SBen Gras.Xr umask 2 ,
1522fe8fb19SBen Gras.Xr vfork 2 ,
1532fe8fb19SBen Gras.Xr wait 2
1542fe8fb19SBen Gras.Sh HISTORY
1552fe8fb19SBen GrasThe
1562fe8fb19SBen Gras.Fn clone
1572fe8fb19SBen Grasfunction call appeared in
1582fe8fb19SBen Gras.Nx 1.6 .
1592fe8fb19SBen GrasIt is compatible with the Linux function call of the same name
1602fe8fb19SBen Graswith respect to the described options.
1612fe8fb19SBen Gras.Sh BUGS
1622fe8fb19SBen GrasThe
1632fe8fb19SBen Gras.Nx
1642fe8fb19SBen Grasimplementation of
1652fe8fb19SBen Gras.Fn clone
1662fe8fb19SBen Grasdoes not implement the following
1672fe8fb19SBen Gras.Ar flags
1682fe8fb19SBen Grasthat are present in the Linux implementation:
1692fe8fb19SBen Gras.Pp
1702fe8fb19SBen Gras.Bl -bullet -offset indent -compact
1712fe8fb19SBen Gras.It
1722fe8fb19SBen Gras.Dv CLONE_CHILD_CLEARTID
1732fe8fb19SBen Gras.It
1742fe8fb19SBen Gras.Dv CLONE_CHILD_SETTID
1752fe8fb19SBen Gras.It
1762fe8fb19SBen Gras.Dv CLONE_IO
1772fe8fb19SBen Gras.It
1782fe8fb19SBen Gras.Dv CLONE_NEWIPC
1792fe8fb19SBen Gras.It
1802fe8fb19SBen Gras.Dv CLONE_NEWNET
1812fe8fb19SBen Gras.It
1822fe8fb19SBen Gras.Dv CLONE_NEWNS
1832fe8fb19SBen Gras.It
1842fe8fb19SBen Gras.Dv CLONE_NEWPID
1852fe8fb19SBen Gras.It
1862fe8fb19SBen Gras.Dv CLONE_NEWUTS
1872fe8fb19SBen Gras.It
1882fe8fb19SBen Gras.Dv CLONE_PARENT
1892fe8fb19SBen Gras.It
1902fe8fb19SBen Gras.Dv CLONE_PARENT_SETTID
1912fe8fb19SBen Gras.It
1922fe8fb19SBen Gras.Dv CLONE_PID
1932fe8fb19SBen Gras.It
1942fe8fb19SBen Gras.Dv CLONE_PTRACE
1952fe8fb19SBen Gras.It
1962fe8fb19SBen Gras.Dv CLONE_SETTLS
1972fe8fb19SBen Gras.It
1982fe8fb19SBen Gras.Dv CLONE_STOPPED
1992fe8fb19SBen Gras.It
2002fe8fb19SBen Gras.Dv CLONE_SYSVSEM
2012fe8fb19SBen Gras.It
2022fe8fb19SBen Gras.Dv CLONE_THREAD
2032fe8fb19SBen Gras.It
2042fe8fb19SBen Gras.Dv CLONE_UNTRACED
2052fe8fb19SBen Gras.El
206