[BACK]Return to clone.2 CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / lib / libc / sys

File: [cvs.NetBSD.org] / src / lib / libc / sys / clone.2 (download)

Revision 1.13, Sun Jan 29 11:44:54 2012 UTC (12 years, 2 months ago) by wiz
Branch: MAIN
CVS Tags: yamt-pagecache-base9, yamt-pagecache-base8, yamt-pagecache-base7, yamt-pagecache-base6, yamt-pagecache-base5, yamt-pagecache-base4, tls-maxphys-base, tls-maxphys, tls-earlyentropy-base, tls-earlyentropy, riastradh-xf86-video-intel-2-7-1-pre-2-21-15, riastradh-drm2-base3, riastradh-drm2-base2, riastradh-drm2-base1, riastradh-drm2-base, riastradh-drm2, prg-localcount2-base3, prg-localcount2-base2, prg-localcount2-base1, prg-localcount2-base, prg-localcount2, phil-wifi-base, phil-wifi-20200421, phil-wifi-20200411, phil-wifi-20200406, phil-wifi-20191119, phil-wifi-20190609, phil-wifi, pgoyette-localcount-base, pgoyette-localcount-20170426, pgoyette-localcount-20170320, pgoyette-localcount-20170107, pgoyette-localcount-20161104, pgoyette-localcount-20160806, pgoyette-localcount-20160726, pgoyette-localcount, pgoyette-compat-merge-20190127, pgoyette-compat-base, pgoyette-compat-20190127, pgoyette-compat-20190118, pgoyette-compat-1226, pgoyette-compat-1126, pgoyette-compat-1020, pgoyette-compat-0930, pgoyette-compat-0906, pgoyette-compat-0728, pgoyette-compat-0625, pgoyette-compat-0521, pgoyette-compat-0502, pgoyette-compat-0422, pgoyette-compat-0415, pgoyette-compat-0407, pgoyette-compat-0330, pgoyette-compat-0322, pgoyette-compat-0315, pgoyette-compat, perseant-stdc-iso10646-base, perseant-stdc-iso10646, netbsd-9-base, netbsd-9-2-RELEASE, netbsd-9-1-RELEASE, netbsd-9-0-RELEASE, netbsd-9-0-RC2, netbsd-9-0-RC1, netbsd-8-base, netbsd-8-2-RELEASE, netbsd-8-1-RELEASE, netbsd-8-1-RC1, netbsd-8-0-RELEASE, netbsd-8-0-RC2, netbsd-8-0-RC1, netbsd-8, netbsd-7-nhusb-base-20170116, netbsd-7-nhusb-base, netbsd-7-nhusb, netbsd-7-base, netbsd-7-2-RELEASE, netbsd-7-1-RELEASE, netbsd-7-1-RC2, netbsd-7-1-RC1, netbsd-7-1-2-RELEASE, netbsd-7-1-1-RELEASE, netbsd-7-1, netbsd-7-0-RELEASE, netbsd-7-0-RC3, netbsd-7-0-RC2, netbsd-7-0-RC1, netbsd-7-0-2-RELEASE, netbsd-7-0-1-RELEASE, netbsd-7-0, netbsd-7, netbsd-6-base, netbsd-6-1-RELEASE, netbsd-6-1-RC4, netbsd-6-1-RC3, netbsd-6-1-RC2, netbsd-6-1-RC1, netbsd-6-1-5-RELEASE, netbsd-6-1-4-RELEASE, netbsd-6-1-3-RELEASE, netbsd-6-1-2-RELEASE, netbsd-6-1-1-RELEASE, netbsd-6-1, netbsd-6-0-RELEASE, netbsd-6-0-RC2, netbsd-6-0-RC1, netbsd-6-0-6-RELEASE, netbsd-6-0-5-RELEASE, netbsd-6-0-4-RELEASE, netbsd-6-0-3-RELEASE, netbsd-6-0-2-RELEASE, netbsd-6-0-1-RELEASE, netbsd-6-0, netbsd-6, matt-nb8-mediatek-base, matt-nb8-mediatek, matt-nb6-plus-nbase, matt-nb6-plus-base, matt-nb6-plus, localcount-20160914, is-mlppp-base, is-mlppp, bouyer-socketcan-base1, bouyer-socketcan-base, bouyer-socketcan, agc-symver-base, agc-symver
Branch point for: netbsd-9
Changes since 1.12: +3 -2 lines

Add Nm for __clone, man page is already linked to that name.
Noted by Abhinav Upadhyay.

.\"	$NetBSD: clone.2,v 1.13 2012/01/29 11:44:54 wiz Exp $
.\"
.\" 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.
.\"
.\" 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 May 4, 2010
.Dt CLONE 2
.Os
.Sh NAME
.Nm clone ,
.Nm __clone
.Nd spawn new process with options
.Sh LIBRARY
.Lb libc
.Sh SYNOPSIS
.In sched.h
.Ft pid_t
.Fn clone "int (*func)(void *arg)" "void *stack" "int flags" "void *arg"
.Ft pid_t
.Fn __clone "int (*func)(void *arg)" "void *stack" "int flags" "void *arg"
.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
context to the child.
The stack pointer for the child process will be set to
.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
is created.
The lower 8 bits of
.Ar flags
specify the signal that is to be sent to the parent when the child
exits.
The following flags may also be specified by bitwise-or'ing
them with the signal value:
.Bl -tag -width "CLONE_SIGHAND" -offset 2n
.It Dv CLONE_VM
Share the virtual address space with the parent.
The address space is shared in the same way as
.Xr vfork 2 .
.It Dv CLONE_FS
Share the
.Dq file system information
with the parent.
This include the current working directory and file creation mask.
.It Dv CLONE_FILES
Share the file descriptor table with the parent.
.It Dv CLONE_SIGHAND
Share the signal handler set with the parent.
Note that the signal mask
is never shared between the parent and the child, even if
.Dv CLONE_SIGHAND
is set.
.It Dv CLONE_VFORK
Preserve the synchronization semantics of
.Xr vfork 2 ;
the parent blocks until the child exits.
.El
.Pp
The
.Nm
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.
.Pp
If the child process's entry point returns, the value it returns
is passed to
.Xr _exit 2 ,
and the child process exits.
Note that if the child process wants to exit directly, it should use
.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
applications.
It is provided as a means to port software
originally written for the Linux operating system to
.Nx .
.Sh RETURN VALUES
Same as for
.Xr fork 2 .
.Sh ERRORS
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 ,
.Xr vfork 2 ,
.Xr wait 2
.Sh HISTORY
The
.Fn clone
function call appeared in
.Nx 1.6 .
It is compatible with the Linux function call of the same name
with respect to the described options.
.Sh BUGS
The
.Nx
implementation of
.Fn clone
does not implement the following
.Ar flags
that are present in the Linux implementation:
.Pp
.Bl -bullet -offset indent -compact
.It
.Dv CLONE_CHILD_CLEARTID
.It
.Dv CLONE_CHILD_SETTID
.It
.Dv CLONE_IO
.It
.Dv CLONE_NEWIPC
.It
.Dv CLONE_NEWNET
.It
.Dv CLONE_NEWNS
.It
.Dv CLONE_NEWPID
.It
.Dv CLONE_NEWUTS
.It
.Dv CLONE_PARENT
.It
.Dv CLONE_PARENT_SETTID
.It
.Dv CLONE_PID
.It
.Dv CLONE_PTRACE
.It
.Dv CLONE_SETTLS
.It
.Dv CLONE_STOPPED
.It
.Dv CLONE_SYSVSEM
.It
.Dv CLONE_THREAD
.It
.Dv CLONE_UNTRACED
.El