summaryrefslogtreecommitdiffstats
path: root/man2/clone.2
diff options
context:
space:
mode:
Diffstat (limited to 'man2/clone.2')
-rw-r--r--man2/clone.2217
1 files changed, 109 insertions, 108 deletions
diff --git a/man2/clone.2 b/man2/clone.2
index 8e5eae806..f0c60b9e3 100644
--- a/man2/clone.2
+++ b/man2/clone.2
@@ -72,14 +72,14 @@ Standard C library
glibc provides no wrapper for
.BR clone3 (),
necessitating the use of
-.BR syscall (2).
+.MR syscall 2 .
.SH DESCRIPTION
These system calls
create a new ("child") process, in a manner similar to
-.BR fork (2).
+.MR fork 2 .
.P
By contrast with
-.BR fork (2),
+.MR fork 2 ,
these system calls provide more precise control over what pieces of execution
context are shared between the calling process and the child process.
For example, using these system calls, the caller can control whether
@@ -87,7 +87,7 @@ or not the two processes share the virtual address space,
the table of file descriptors, and the table of signal handlers.
These system calls also allow the new child process to be placed
in separate
-.BR namespaces (7).
+.MR namespaces 7 .
.P
Note that in this manual
page, "calling process" normally corresponds to "parent process".
@@ -120,10 +120,10 @@ wrapper function,
it commences execution by calling the function pointed to by the argument
.IR fn .
(This differs from
-.BR fork (2),
+.MR fork 2 ,
where execution continues in the child from the point
of the
-.BR fork (2)
+.MR fork 2
call.)
The
.I arg
@@ -137,7 +137,7 @@ The integer returned by
.I fn
is the exit status for the child process.
The child process may also terminate explicitly by calling
-.BR exit (2)
+.MR exit 2
or after receiving a fatal signal.
.P
The
@@ -176,7 +176,7 @@ cleaner separation in the use of various arguments;
and the ability to specify the size of the child's stack area.
.P
As with
-.BR fork (2),
+.MR fork 2 ,
.BR clone3 ()
returns in both the parent and the child.
It returns 0 in the child process and returns the PID of the child
@@ -298,7 +298,7 @@ then the parent process must specify the
or
.B __WCLONE
options when waiting for the child with
-.BR wait (2).
+.MR wait 2 .
If no signal (i.e., zero) is specified, then the parent process is not signaled
when the child terminates.
.\"
@@ -431,7 +431,7 @@ or
in child memory when the child exits, and do a wakeup on the futex
at that address.
The address involved may be changed by the
-.BR set_tid_address (2)
+.MR set_tid_address 2
system call.
This is used by threading libraries.
.TP
@@ -495,11 +495,11 @@ Any file descriptor created by the calling process or by the child
process is also valid in the other process.
Similarly, if one of the processes closes a file descriptor,
or changes its associated flags (using the
-.BR fcntl (2)
+.MR fcntl 2
.B F_SETFD
operation), the other process is also affected.
If a process sharing a file descriptor table calls
-.BR execve (2),
+.MR execve 2 ,
its file descriptor table is duplicated (unshared).
.IP
If
@@ -515,7 +515,7 @@ that the duplicated file descriptors in the child refer to the same
open file descriptions as the corresponding file descriptors
in the calling process,
and thus share file offsets and file status flags (see
-.BR open (2)).
+.MR open 2 ).
.TP
.BR CLONE_FS " (since Linux 2.0)"
If
@@ -525,10 +525,10 @@ information.
This includes the root of the filesystem, the current
working directory, and the umask.
Any call to
-.BR chroot (2),
-.BR chdir (2),
+.MR chroot 2 ,
+.MR chdir 2 ,
or
-.BR umask (2)
+.MR umask 2
performed by the calling process or the child process also affects the
other process.
.IP
@@ -537,10 +537,10 @@ If
is not set, the child process works on a copy of the filesystem
information of the calling process at the time of the clone call.
Calls to
-.BR chroot (2),
-.BR chdir (2),
+.MR chroot 2 ,
+.MR chdir 2 ,
or
-.BR umask (2)
+.MR umask 2
performed later by one of the processes do not affect the other process.
.TP
.BR CLONE_INTO_CGROUP " (since Linux 5.7)"
@@ -569,7 +569,7 @@ or the
.B O_PATH
flag.)
Note that all of the usual restrictions (described in
-.BR cgroups (7))
+.MR cgroups 7 )
on placing a process into a version 2 cgroup apply.
.IP
Among the possible use cases for
@@ -593,7 +593,7 @@ The
flag also allows the creation of
frozen child processes by spawning them into a frozen cgroup.
(See
-.BR cgroups (7)
+.MR cgroups 7
for a description of the freezer controller.)
.IP \[bu]
For threaded applications (or even thread implementations which
@@ -608,7 +608,7 @@ If
is set, then the new process shares an I/O context with
the calling process.
If this flag is not set, then (as with
-.BR fork (2))
+.MR fork 2 )
the new process has its own I/O context.
.IP
.\" The following based on text from Jens Axboe
@@ -622,7 +622,8 @@ For some I/O schedulers,
if two processes share an I/O context,
they will be allowed to interleave their disk access.
If several threads are doing I/O on behalf of the same process
-.RB ( aio_read (3),
+\%(\c
+.MR aio_read 3 ,
for instance), they should employ
.B CLONE_IO
to get better I/O performance.
@@ -635,11 +636,11 @@ option, this flag is a no-op.
.BR CLONE_NEWCGROUP " (since Linux 4.6)"
Create the process in a new cgroup namespace.
If this flag is not set, then (as with
-.BR fork (2))
+.MR fork 2 )
the process is created in the same cgroup namespaces as the calling process.
.IP
For further information on cgroup namespaces, see
-.BR cgroup_namespaces (7).
+.MR cgroup_namespaces 7 .
.IP
Only a privileged process
.RB ( CAP_SYS_ADMIN )
@@ -652,12 +653,12 @@ If
.B CLONE_NEWIPC
is set, then create the process in a new IPC namespace.
If this flag is not set, then (as with
-.BR fork (2)),
+.MR fork 2 ),
the process is created in the same IPC namespace as
the calling process.
.IP
For further information on IPC namespaces, see
-.BR ipc_namespaces (7).
+.MR ipc_namespaces 7 .
.IP
Only a privileged process
.RB ( CAP_SYS_ADMIN )
@@ -674,12 +675,12 @@ If
.B CLONE_NEWNET
is set, then create the process in a new network namespace.
If this flag is not set, then (as with
-.BR fork (2))
+.MR fork 2 )
the process is created in the same network namespace as
the calling process.
.IP
For further information on network namespaces, see
-.BR network_namespaces (7).
+.MR network_namespaces 7 .
.IP
Only a privileged process
.RB ( CAP_SYS_ADMIN )
@@ -697,9 +698,9 @@ is not set, the child lives in the same mount
namespace as the parent.
.IP
For further information on mount namespaces, see
-.BR namespaces (7)
+.MR namespaces 7
and
-.BR mount_namespaces (7).
+.MR mount_namespaces 7 .
.IP
Only a privileged process
.RB ( CAP_SYS_ADMIN )
@@ -724,14 +725,14 @@ If
.B CLONE_NEWPID
is set, then create the process in a new PID namespace.
If this flag is not set, then (as with
-.BR fork (2))
+.MR fork 2 )
the process is created in the same PID namespace as
the calling process.
.IP
For further information on PID namespaces, see
-.BR namespaces (7)
+.MR namespaces 7
and
-.BR pid_namespaces (7).
+.MR pid_namespaces 7 .
.IP
Only a privileged process
.RB ( CAP_SYS_ADMIN )
@@ -754,13 +755,13 @@ If
.B CLONE_NEWUSER
is set, then create the process in a new user namespace.
If this flag is not set, then (as with
-.BR fork (2))
+.MR fork 2 )
the process is created in the same user namespace as the calling process.
.IP
For further information on user namespaces, see
-.BR namespaces (7)
+.MR namespaces 7
and
-.BR user_namespaces (7).
+.MR user_namespaces 7 .
.IP
Before Linux 3.8, use of
.B CLONE_NEWUSER
@@ -794,12 +795,12 @@ is set, then create the process in a new UTS namespace,
whose identifiers are initialized by duplicating the identifiers
from the UTS namespace of the calling process.
If this flag is not set, then (as with
-.BR fork (2))
+.MR fork 2 )
the process is created in the same UTS namespace as
the calling process.
.IP
For further information on UTS namespaces, see
-.BR uts_namespaces (7).
+.MR uts_namespaces 7 .
.IP
Only a privileged process
.RB ( CAP_SYS_ADMIN )
@@ -810,17 +811,17 @@ can employ
If
.B CLONE_PARENT
is set, then the parent of the new child (as returned by
-.BR getppid (2))
+.MR getppid 2 )
will be the same as that of the calling process.
.IP
If
.B CLONE_PARENT
is not set, then (as with
-.BR fork (2))
+.MR fork 2 )
the child's parent is the calling process.
.IP
Note that it is the parent process, as returned by
-.BR getppid (2),
+.MR getppid 2 ,
which is signaled when the child terminates, so that
if
.B CLONE_PARENT
@@ -873,7 +874,7 @@ a PID file descriptor referring to the child process is allocated
and placed at a specified location in the parent's memory.
The close-on-exec flag is set on this new file descriptor.
PID file descriptors can be used for the purposes described in
-.BR pidfd_open (2).
+.MR pidfd_open 2 .
.RS
.IP \[bu] 3
When using
@@ -920,7 +921,7 @@ If
.B CLONE_PTRACE
is specified, and the calling process is being traced,
then trace the child also (see
-.BR ptrace (2)).
+.MR ptrace 2 ).
.TP
.BR CLONE_SETTLS " (since Linux 2.5.32)"
The TLS (Thread Local Storage) descriptor is set to
@@ -934,12 +935,12 @@ On x86,
is interpreted as a
.I struct user_desc\~*
(see
-.BR set_thread_area (2)).
+.MR set_thread_area 2 ).
On x86-64 it is the new value to be set for the %fs base register
(see the
.B ARCH_SET_FS
argument to
-.BR arch_prctl (2)).
+.MR arch_prctl 2 ).
On architectures with a dedicated TLS register, it is the new value
of that register.
.IP
@@ -952,14 +953,14 @@ If
is set, the calling process and the child process share the same table of
signal handlers.
If the calling process or child process calls
-.BR sigaction (2)
+.MR sigaction 2
to change the behavior associated with a signal, the behavior is
changed in the other process as well.
However, the calling process and child
processes still have distinct signal masks and sets of pending
signals.
So, one of them may block or unblock signals using
-.BR sigprocmask (2)
+.MR sigprocmask 2
without affecting the other process.
.IP
If
@@ -967,7 +968,7 @@ If
is not set, the child process inherits a copy of the signal handlers
of the calling process at the time of the clone call.
Calls to
-.BR sigaction (2)
+.MR sigaction 2
performed later by one of the processes have no effect on the other
process.
.IP
@@ -1010,13 +1011,13 @@ is set, then the child and the calling process share
a single list of System V semaphore adjustment
.RI ( semadj )
values (see
-.BR semop (2)).
+.MR semop 2 ).
In this case, the shared list accumulates
.I semadj
values across all processes sharing the list,
and semaphore adjustments are performed only when the last process
that is sharing the list terminates (or ceases sharing the list using
-.BR unshare (2)).
+.MR unshare 2 ).
If this flag is not set, then the child has a separate
.I semadj
list that is initially empty.
@@ -1036,7 +1037,7 @@ POSIX threads notion of a set of threads that share a single PID.
Internally, this shared PID is the so-called
thread group identifier (TGID) for the thread group.
Since Linux 2.4, calls to
-.BR getpid (2)
+.MR getpid 2
return the TGID of the caller.
.IP
The threads within a group can be distinguished by their (system-wide)
@@ -1045,7 +1046,7 @@ A new thread's TID is available as the function result
returned to the caller,
and a thread can obtain
its own TID using
-.BR gettid (2).
+.MR gettid 2 .
.IP
When a clone call is made without specifying
.BR CLONE_THREAD ,
@@ -1061,7 +1062,7 @@ has the same parent process as the process that made the clone call
(i.e., like
.BR CLONE_PARENT ),
so that calls to
-.BR getppid (2)
+.MR getppid 2
return the same value for all of the threads in a thread group.
When a
.B CLONE_THREAD
@@ -1070,7 +1071,7 @@ thread terminates, the thread that created it is not sent a
(or other termination) signal;
nor can the status of such a thread be obtained
using
-.BR wait (2).
+.MR wait 2 .
(The thread is said to be
.IR detached .)
.IP
@@ -1080,14 +1081,14 @@ the parent process of the thread group is sent a
(or other termination) signal.
.IP
If any of the threads in a thread group performs an
-.BR execve (2),
+.MR execve 2 ,
then all threads other than the thread group leader are terminated,
and the new program is executed in the thread group leader.
.IP
If one of the threads in a thread group creates a child using
-.BR fork (2),
+.MR fork 2 ,
then any thread in the group can
-.BR wait (2)
+.MR wait 2
for that child.
.IP
Since Linux 2.5.35, the
@@ -1110,7 +1111,7 @@ it will affect (terminate, stop, continue, be ignored in)
all members of the thread group.
.IP
Each thread has its own signal mask, as set by
-.BR sigprocmask (2).
+.MR sigprocmask 2 .
.IP
A signal may be process-directed or thread-directed.
A process-directed signal is targeted at a thread group (i.e., a TGID),
@@ -1118,15 +1119,15 @@ and is delivered to an arbitrarily selected thread from among those
that are not blocking the signal.
A signal may be process-directed because it was generated by the kernel
for reasons other than a hardware exception, or because it was sent using
-.BR kill (2)
+.MR kill 2
or
-.BR sigqueue (3).
+.MR sigqueue 3 .
A thread-directed signal is targeted at (i.e., delivered to)
a specific thread.
A signal may be thread directed because it was sent using
-.BR tgkill (2)
+.MR tgkill 2
or
-.BR pthread_sigqueue (3),
+.MR pthread_sigqueue 3 ,
or because the thread executed a machine language instruction that triggered
a hardware exception
(e.g., invalid memory access triggering
@@ -1135,7 +1136,7 @@ or a floating-point exception triggering
.BR SIGFPE ).
.IP
A call to
-.BR sigpending (2)
+.MR sigpending 2
returns a signal set that is the union of the pending process-directed
signals and the signals that are pending for the calling thread.
.IP
@@ -1144,7 +1145,7 @@ and the thread group has installed a handler for the signal, then
the handler is invoked in exactly one, arbitrarily selected
member of the thread group that has not blocked the signal.
If multiple threads in a group are waiting to accept the same signal using
-.BR sigwaitinfo (2),
+.MR sigwaitinfo 2 ,
the kernel will arbitrarily select one of these threads
to receive the signal.
.TP
@@ -1161,11 +1162,11 @@ If
is set, the execution of the calling process is suspended
until the child releases its virtual memory
resources via a call to
-.BR execve (2)
+.MR execve 2
or
-.BR _exit (2)
+.MR _exit 2
(as with
-.BR vfork (2)).
+.MR vfork 2 ).
.IP
If
.B CLONE_VFORK
@@ -1181,9 +1182,9 @@ space.
In particular, memory writes performed by the calling process
or by the child process are also visible in the other process.
Moreover, any memory mapping or unmapping performed with
-.BR mmap (2)
+.MR mmap 2
or
-.BR munmap (2)
+.MR munmap 2
by the child or calling process also affects the other process.
.IP
If
@@ -1192,7 +1193,7 @@ is not set, the child process runs in a separate copy of the memory
space of the calling process at the time of the clone call.
Memory writes or file mappings/unmappings performed by one of the
processes do not affect the other, as with
-.BR fork (2).
+.MR fork 2 .
.IP
If the
.B CLONE_VM
@@ -1200,7 +1201,7 @@ flag is specified and the
.B CLONE_VFORK
flag is not specified,
then any alternate signal stack that was established by
-.BR sigaltstack (2)
+.MR sigaltstack 2
is cleared in the child process.
.SH RETURN VALUE
.\" gettid(2) returns current->pid;
@@ -1218,14 +1219,14 @@ is set to indicate the error.
was specified in
.IR cl_args.flags ,
but the restrictions (described in
-.BR cgroups (7))
+.MR cgroups 7 )
on placing the child process into the version 2 cgroup referred to by
.I cl_args.cgroup
are not met.
.TP
.B EAGAIN
Too many processes are already running; see
-.BR fork (2).
+.MR fork 2 .
.TP
.BR EBUSY " (" clone3 "() only)"
.B CLONE_INTO_CGROUP
@@ -1281,11 +1282,11 @@ was not.
was specified in the
.I flags
mask, but the current process previously called
-.BR unshare (2)
+.MR unshare 2
with the
.B CLONE_NEWPID
flag or used
-.BR setns (2)
+.MR setns 2
to reassociate itself with a PID namespace.
.TP
.B EINVAL
@@ -1468,7 +1469,7 @@ was specified in the
mask,
but the limit on the nesting depth of PID namespaces
would have been exceeded; see
-.BR pid_namespaces (7).
+.MR pid_namespaces 7 .
.TP
.BR ENOSPC " (since Linux 4.9; beforehand " EUSERS )
.B CLONE_NEWUSER
@@ -1477,7 +1478,7 @@ was specified in the
mask, and the call would cause the limit on the number of
nested user namespaces to be exceeded.
See
-.BR user_namespaces (7).
+.MR user_namespaces 7 .
.IP
From Linux 3.11 to Linux 4.8, the error diagnosed in this case was
.BR EUSERS .
@@ -1490,7 +1491,7 @@ but doing so would have caused the limit defined by the corresponding file in
.I /proc/sys/user
to be exceeded.
For further details, see
-.BR namespaces (7).
+.MR namespaces 7 .
.TP
.BR EOPNOTSUPP " (" clone3 "() only)"
.B CLONE_INTO_CGROUP
@@ -1524,7 +1525,7 @@ was specified in the
mask,
but either the effective user ID or the effective group ID of the caller
does not have a mapping in the parent namespace (see
-.BR user_namespaces (7)).
+.MR user_namespaces 7 ).
.TP
.BR EPERM " (since Linux 3.9)"
.\" commit 3151527ee007b73a0ebd296010f1c0454a919c7d
@@ -1582,7 +1583,7 @@ should not be called through vsyscall, but directly through
The raw
.BR clone ()
system call corresponds more closely to
-.BR fork (2)
+.MR fork 2
in that execution in the child continues from the point of the
call.
As such, the
@@ -1750,18 +1751,18 @@ is to implement threads: multiple flows of control in a program that
run concurrently in a shared address space.
.P
The
-.BR kcmp (2)
+.MR kcmp 2
system call can be used to test whether two processes share various
resources such as a file descriptor table,
System V semaphore undo operations, or a virtual address space.
.P
Handlers registered using
-.BR pthread_atfork (3)
+.MR pthread_atfork 3
are not executed during a clone call.
.SH BUGS
GNU C library versions 2.3.4 up to and including 2.24
contained a wrapper function for
-.BR getpid (2)
+.MR getpid 2
that performed caching of PIDs.
This caching relied on support in the glibc wrapper for
.BR clone (),
@@ -1771,7 +1772,7 @@ In particular,
if a signal was delivered to the child immediately after the
.BR clone ()
call, then a call to
-.BR getpid (2)
+.MR getpid 2
in a handler for the signal could return the PID
of the calling process ("the parent"),
if the clone wrapper had not yet had a chance to update the PID
@@ -1779,7 +1780,7 @@ cache in the child.
(This discussion ignores the case where the child was created using
.BR CLONE_THREAD ,
when
-.BR getpid (2)
+.MR getpid 2
.I should
return the same value in the child and in the process that called
.BR clone (),
@@ -1804,7 +1805,7 @@ mypid = syscall(SYS_getpid);
.\" http://sourceware.org/bugzilla/show_bug.cgi?id=6910
.P
Because of the stale-cache problem, as well as other problems noted in
-.BR getpid (2),
+.MR getpid 2 ,
the PID caching feature was removed in glibc 2.25.
.SH EXAMPLES
The following program demonstrates the use of
@@ -1815,22 +1816,22 @@ Both parent and child then display the system hostname,
making it possible to see that the hostname
differs in the UTS namespaces of the parent and child.
For an example of the use of this program, see
-.BR setns (2).
+.MR setns 2 .
.P
Within the sample program, we allocate the memory that is to
be used for the child's stack using
-.BR mmap (2)
+.MR mmap 2
rather than
-.BR malloc (3)
+.MR malloc 3
for the following reasons:
.IP \[bu] 3
-.BR mmap (2)
+.MR mmap 2
allocates a block of memory that starts on a page
boundary and is a multiple of the page size.
This is useful if we want to establish a guard page (a page with protection
.BR PROT_NONE )
at the end of the stack using
-.BR mprotect (2).
+.MR mprotect 2 .
.IP \[bu]
We can specify the
.B MAP_STACK
@@ -1931,19 +1932,19 @@ main(int argc, char *argv[])
.EE
.\" SRC END
.SH SEE ALSO
-.BR fork (2),
-.BR futex (2),
-.BR getpid (2),
-.BR gettid (2),
-.BR kcmp (2),
-.BR mmap (2),
-.BR pidfd_open (2),
-.BR set_thread_area (2),
-.BR set_tid_address (2),
-.BR setns (2),
-.BR tkill (2),
-.BR unshare (2),
-.BR wait (2),
-.BR capabilities (7),
-.BR namespaces (7),
-.BR pthreads (7)
+.MR fork 2 ,
+.MR futex 2 ,
+.MR getpid 2 ,
+.MR gettid 2 ,
+.MR kcmp 2 ,
+.MR mmap 2 ,
+.MR pidfd_open 2 ,
+.MR set_thread_area 2 ,
+.MR set_tid_address 2 ,
+.MR setns 2 ,
+.MR tkill 2 ,
+.MR unshare 2 ,
+.MR wait 2 ,
+.MR capabilities 7 ,
+.MR namespaces 7 ,
+.MR pthreads 7