1 .\" Copyright (c) 1992 Drew Eckhardt <drew@cs.colorado.edu>, March 28, 1992
2 .\" and Copyright (c) Michael Kerrisk, 2001, 2002, 2005, 2013
4 .\" %%%LICENSE_START(GPL_NOVERSION_ONELINE)
5 .\" May be distributed under the GNU General Public License.
8 .\" Modified by Michael Haardt <michael@moria.de>
9 .\" Modified 24 Jul 1993 by Rik Faith <faith@cs.unc.edu>
10 .\" Modified 21 Aug 1994 by Michael Chastain <mec@shell.portal.com>:
11 .\" New man page (copied from 'fork.2').
12 .\" Modified 10 June 1995 by Andries Brouwer <aeb@cwi.nl>
13 .\" Modified 25 April 1998 by Xavier Leroy <Xavier.Leroy@inria.fr>
14 .\" Modified 26 Jun 2001 by Michael Kerrisk
15 .\" Mostly upgraded to 2.4.x
16 .\" Added prototype for sys_clone() plus description
17 .\" Added CLONE_THREAD with a brief description of thread groups
18 .\" Added CLONE_PARENT and revised entire page remove ambiguity
19 .\" between "calling process" and "parent process"
20 .\" Added CLONE_PTRACE and CLONE_VFORK
21 .\" Added EPERM and EINVAL error codes
22 .\" Renamed "__clone" to "clone" (which is the prototype in <sched.h>)
23 .\" various other minor tidy ups and clarifications.
24 .\" Modified 26 Jun 2001 by Michael Kerrisk <mtk.manpages@gmail.com>
25 .\" Updated notes for 2.4.7+ behavior of CLONE_THREAD
26 .\" Modified 15 Oct 2002 by Michael Kerrisk <mtk.manpages@gmail.com>
27 .\" Added description for CLONE_NEWNS, which was added in 2.4.19
28 .\" Slightly rephrased, aeb.
29 .\" Modified 1 Feb 2003 - added CLONE_SIGHAND restriction, aeb.
30 .\" Modified 1 Jan 2004 - various updates, aeb
31 .\" Modified 2004-09-10 - added CLONE_PARENT_SETTID etc. - aeb.
32 .\" 2005-04-12, mtk, noted the PID caching behavior of NPTL's getpid()
33 .\" wrapper under BUGS.
34 .\" 2005-05-10, mtk, added CLONE_SYSVSEM, CLONE_UNTRACED, CLONE_STOPPED.
35 .\" 2005-05-17, mtk, Substantially enhanced discussion of CLONE_THREAD.
36 .\" 2008-11-18, mtk, order CLONE_* flags alphabetically
37 .\" 2008-11-18, mtk, document CLONE_NEWPID
38 .\" 2008-11-19, mtk, document CLONE_NEWUTS
39 .\" 2008-11-19, mtk, document CLONE_NEWIPC
40 .\" 2008-11-19, Jens Axboe, mtk, document CLONE_IO
42 .TH CLONE 2 2017-09-15 "Linux" "Linux Programmer's Manual"
44 clone, __clone2 \- create a child process
47 /* Prototype for the glibc wrapper function */
49 .B #define _GNU_SOURCE
52 .BI "int clone(int (*" "fn" ")(void *), void *" child_stack ,
53 .BI " int " flags ", void *" "arg" ", ... "
54 .BI " /* pid_t *" ptid ", void *" newtls \
55 ", pid_t *" ctid " */ );"
57 /* For the prototype of the raw system call, see NOTES */
61 creates a new process, in a manner similar to
64 This page describes both the glibc
66 wrapper function and the underlying system call on which it is based.
67 The main text describes the wrapper function;
68 the differences for the raw system call
69 are described toward the end of this page.
74 allows the child process to share parts of its execution context with
75 the calling process, such as the virtual address space, the table of file
76 descriptors, and the table of signal handlers.
77 (Note that on this manual
78 page, "calling process" normally corresponds to "parent process".
79 But see the description of
85 is to implement threads: multiple flows of control in a program that
86 run concurrently in a shared address space.
88 When the child process is created with
90 it executes the function
94 where execution continues in the child from the point
100 argument is a pointer to a function that is called by the child
101 process at the beginning of its execution.
104 argument is passed to the
110 function returns, the child process terminates.
111 The integer returned by
113 is the exit status for the child process.
114 The child process may also terminate explicitly by calling
116 or after receiving a fatal signal.
120 argument specifies the location of the stack used by the child process.
121 Since the child and calling process may share memory,
122 it is not possible for the child process to execute in the
123 same stack as the calling process.
124 The calling process must therefore
125 set up memory space for the child stack and pass a pointer to this
128 Stacks grow downward on all processors that run Linux
129 (except the HP PA processors), so
131 usually points to the topmost address of the memory space set up for
136 contains the number of the
137 .I "termination signal"
138 sent to the parent when the child dies.
139 If this signal is specified as anything other than
141 then the parent process must specify the
145 options when waiting for the child with
147 If no signal is specified, then the parent process is not signaled
148 when the child terminates.
151 may also be bitwise-ORed with zero or more of the following constants,
152 in order to specify what is shared between the calling process
153 and the child process:
155 .BR CLONE_CHILD_CLEARTID " (since Linux 2.5.49)"
156 Clear (zero) the child thread ID at the location
158 in child memory when the child exits, and do a wakeup on the futex
160 The address involved may be changed by the
161 .BR set_tid_address (2)
163 This is used by threading libraries.
165 .BR CLONE_CHILD_SETTID " (since Linux 2.5.49)"
166 Store the child thread ID at the location
168 in the child's memory.
169 The store operation completes before
171 returns control to user space.
173 .BR CLONE_FILES " (since Linux 2.0)"
176 is set, the calling process and the child process share the same file
178 Any file descriptor created by the calling process or by the child
179 process is also valid in the other process.
180 Similarly, if one of the processes closes a file descriptor,
181 or changes its associated flags (using the
184 operation), the other process is also affected.
185 If a process sharing a file descriptor table calls
187 its file descriptor table is duplicated (unshared).
191 is not set, the child process inherits a copy of all file descriptors
192 opened in the calling process at the time of
194 Subsequent operations that open or close file descriptors,
195 or change file descriptor flags,
196 performed by either the calling
197 process or the child process do not affect the other process.
199 that the duplicated file descriptors in the child refer to the same open file
200 descriptions as the corresponding file descriptors in the calling process,
201 and thus share file offsets and file status flags (see
204 .BR CLONE_FS " (since Linux 2.0)"
207 is set, the caller and the child process share the same filesystem
209 This includes the root of the filesystem, the current
210 working directory, and the umask.
216 performed by the calling process or the child process also affects the
221 is not set, the child process works on a copy of the filesystem
222 information of the calling process at the time of the
230 performed later by one of the processes do not affect the other process.
232 .BR CLONE_IO " (since Linux 2.6.25)"
235 is set, then the new process shares an I/O context with
237 If this flag is not set, then (as with
239 the new process has its own I/O context.
241 .\" The following based on text from Jens Axboe
242 The I/O context is the I/O scope of the disk scheduler (i.e.,
243 what the I/O scheduler uses to model scheduling of a process's I/O).
244 If processes share the same I/O context,
245 they are treated as one by the I/O scheduler.
246 As a consequence, they get to share disk time.
247 For some I/O schedulers,
248 .\" the anticipatory and CFQ scheduler
249 if two processes share an I/O context,
250 they will be allowed to interleave their disk access.
251 If several threads are doing I/O on behalf of the same process
253 for instance), they should employ
255 to get better I/O performance.
258 If the kernel is not configured with the
260 option, this flag is a no-op.
262 .BR CLONE_NEWCGROUP " (since Linux 4.6)"
263 Create the process in a new cgroup namespace.
264 If this flag is not set, then (as with
266 the process is created in the same cgroup namespaces as the calling process.
267 This flag is intended for the implementation of containers.
269 For further information on cgroup namespaces, see
270 .BR cgroup_namespaces (7).
272 Only a privileged process
273 .RB ( CAP_SYS_ADMIN )
275 .BR CLONE_NEWCGROUP .
278 .BR CLONE_NEWIPC " (since Linux 2.6.19)"
281 is set, then create the process in a new IPC namespace.
282 If this flag is not set, then (as with
284 the process is created in the same IPC namespace as
286 This flag is intended for the implementation of containers.
288 An IPC namespace provides an isolated view of System\ V IPC objects (see
290 and (since Linux 2.6.30)
291 .\" commit 7eafd7c74c3f2e67c27621b987b28397110d643f
292 .\" https://lwn.net/Articles/312232/
295 .BR mq_overview (7)).
296 The common characteristic of these IPC mechanisms is that IPC
297 objects are identified by mechanisms other than filesystem
300 Objects created in an IPC namespace are visible to all other processes
301 that are members of that namespace,
302 but are not visible to processes in other IPC namespaces.
304 When an IPC namespace is destroyed
305 (i.e., when the last process that is a member of the namespace terminates),
306 all IPC objects in the namespace are automatically destroyed.
308 Only a privileged process
309 .RB ( CAP_SYS_ADMIN )
312 This flag can't be specified in conjunction with
315 For further information on IPC namespaces, see
318 .BR CLONE_NEWNET " (since Linux 2.6.24)"
319 (The implementation of this flag was completed only
320 by about kernel version 2.6.29.)
324 is set, then create the process in a new network namespace.
325 If this flag is not set, then (as with
327 the process is created in the same network namespace as
329 This flag is intended for the implementation of containers.
331 A network namespace provides an isolated view of the networking stack
332 (network device interfaces, IPv4 and IPv6 protocol stacks,
333 IP routing tables, firewall rules, the
337 directory trees, sockets, etc.).
338 A physical network device can live in exactly one
340 A virtual network device ("veth") pair provides a pipe-like abstraction
341 .\" FIXME . Add pointer to veth(4) page when it is eventually completed
342 that can be used to create tunnels between network namespaces,
343 and can be used to create a bridge to a physical network device
344 in another namespace.
346 When a network namespace is freed
347 (i.e., when the last process in the namespace terminates),
348 its physical network devices are moved back to the
349 initial network namespace (not to the parent of the process).
350 For further information on network namespaces, see
353 Only a privileged process
354 .RB ( CAP_SYS_ADMIN )
358 .BR CLONE_NEWNS " (since Linux 2.4.19)"
361 is set, the cloned child is started in a new mount namespace,
362 initialized with a copy of the namespace of the parent.
365 is not set, the child lives in the same mount
366 namespace as the parent.
368 Only a privileged process
369 .RB ( CAP_SYS_ADMIN )
372 It is not permitted to specify both
376 .\" See https://lwn.net/Articles/543273/
381 For further information on mount namespaces, see
384 .BR mount_namespaces (7).
386 .BR CLONE_NEWPID " (since Linux 2.6.24)"
387 .\" This explanation draws a lot of details from
388 .\" http://lwn.net/Articles/259217/
389 .\" Authors: Pavel Emelyanov <xemul@openvz.org>
390 .\" and Kir Kolyshkin <kir@openvz.org>
392 .\" The primary kernel commit is 30e49c263e36341b60b735cbef5ca37912549264
393 .\" Author: Pavel Emelyanov <xemul@openvz.org>
396 is set, then create the process in a new PID namespace.
397 If this flag is not set, then (as with
399 the process is created in the same PID namespace as
401 This flag is intended for the implementation of containers.
403 For further information on PID namespaces, see
406 .BR pid_namespaces (7).
408 Only a privileged process
409 .RB ( CAP_SYS_ADMIN )
412 This flag can't be specified in conjunction with
418 (This flag first became meaningful for
423 semantics were merged in Linux 3.5,
424 and the final pieces to make the user namespaces completely usable were
425 merged in Linux 3.8.)
429 is set, then create the process in a new user namespace.
430 If this flag is not set, then (as with
432 the process is created in the same user namespace as the calling process.
434 For further information on user namespaces, see
437 .BR user_namespaces (7)
439 Before Linux 3.8, use of
441 required that the caller have three capabilities:
446 .\" Before Linux 2.6.29, it appears that only CAP_SYS_ADMIN was needed
447 Starting with Linux 3.8,
448 no privileges are needed to create a user namespace.
450 This flag can't be specified in conjunction with
454 For security reasons,
455 .\" commit e66eded8309ebf679d3d3c1f5820d1f2ca332c71
456 .\" https://lwn.net/Articles/543273/
457 .\" The fix actually went into 3.9 and into 3.8.3. However, user namespaces
458 .\" were, for practical purposes, unusable in earlier 3.8.x because of the
459 .\" various filesystems that didn't support userns.
461 cannot be specified in conjunction with
464 For further information on user namespaces, see
465 .BR user_namespaces (7).
467 .BR CLONE_NEWUTS " (since Linux 2.6.19)"
470 is set, then create the process in a new UTS namespace,
471 whose identifiers are initialized by duplicating the identifiers
472 from the UTS namespace of the calling process.
473 If this flag is not set, then (as with
475 the process is created in the same UTS namespace as
477 This flag is intended for the implementation of containers.
479 A UTS namespace is the set of identifiers returned by
481 among these, the domain name and the hostname can be modified by
482 .BR setdomainname (2)
486 Changes made to the identifiers in a UTS namespace
487 are visible to all other processes in the same namespace,
488 but are not visible to processes in other UTS namespaces.
490 Only a privileged process
491 .RB ( CAP_SYS_ADMIN )
495 For further information on UTS namespaces, see
498 .BR CLONE_PARENT " (since Linux 2.3.12)"
501 is set, then the parent of the new child (as returned by
503 will be the same as that of the calling process.
507 is not set, then (as with
509 the child's parent is the calling process.
511 Note that it is the parent process, as returned by
513 which is signaled when the child terminates, so that
516 is set, then the parent of the calling process, rather than the
517 calling process itself, will be signaled.
519 .BR CLONE_PARENT_SETTID " (since Linux 2.5.49)"
520 Store the child thread ID at the location
522 in the parent's memory.
523 (In Linux 2.5.32-2.5.48 there was a flag
526 The store operation completes before
528 returns control to user space.
530 .BR CLONE_PID " (obsolete)"
533 is set, the child process is created with the same process ID as
535 This is good for hacking the system, but otherwise
537 Since 2.3.21 this flag can be
538 specified only by the system boot process (PID 0).
539 It disappeared in Linux 2.5.16.
540 Since then, the kernel silently ignores it without error.
542 .BR CLONE_PTRACE " (since Linux 2.2)"
545 is specified, and the calling process is being traced,
546 then trace the child also (see
549 .BR CLONE_SETTLS " (since Linux 2.5.32)"
550 The TLS (Thread Local Storage) descriptor is set to
553 The interpretation of
555 and the resulting effect is architecture dependent.
559 .IR "struct user_desc *"
561 .BR set_thread_area (2)).
562 On x86_64 it is the new value to be set for the %fs base register
567 On architectures with a dedicated TLS register, it is the new value
570 .BR CLONE_SIGHAND " (since Linux 2.0)"
573 is set, the calling process and the child process share the same table of
575 If the calling process or child process calls
577 to change the behavior associated with a signal, the behavior is
578 changed in the other process as well.
579 However, the calling process and child
580 processes still have distinct signal masks and sets of pending
582 So, one of them may block or unblock signals using
584 without affecting the other process.
588 is not set, the child process inherits a copy of the signal handlers
589 of the calling process at the time
594 performed later by one of the processes have no effect on the other
597 Since Linux 2.6.0-test6,
605 .BR CLONE_STOPPED " (since Linux 2.6.0-test2)"
608 is set, then the child is initially stopped (as though it was sent a
610 signal), and must be resumed by sending it a
616 from Linux 2.6.25 onward,
619 altogether in Linux 2.6.38.
620 Since then, the kernel silently ignores it without error.
621 .\" glibc 2.8 removed this defn from bits/sched.h
622 Starting with Linux 4.6, the same bit was reused for the
626 .BR CLONE_SYSVSEM " (since Linux 2.5.10)"
629 is set, then the child and the calling process share
630 a single list of System V semaphore adjustment
634 In this case, the shared list accumulates
636 values across all processes sharing the list,
637 and semaphore adjustments are performed only when the last process
638 that is sharing the list terminates (or ceases sharing the list using
640 If this flag is not set, then the child has a separate
642 list that is initially empty.
644 .BR CLONE_THREAD " (since Linux 2.4.0-test8)"
647 is set, the child is placed in the same thread group as the calling process.
648 To make the remainder of the discussion of
650 more readable, the term "thread" is used to refer to the
651 processes within a thread group.
653 Thread groups were a feature added in Linux 2.4 to support the
654 POSIX threads notion of a set of threads that share a single PID.
655 Internally, this shared PID is the so-called
656 thread group identifier (TGID) for the thread group.
657 Since Linux 2.4, calls to
659 return the TGID of the caller.
661 The threads within a group can be distinguished by their (system-wide)
662 unique thread IDs (TID).
663 A new thread's TID is available as the function result
664 returned to the caller of
666 and a thread can obtain
670 When a call is made to
674 then the resulting thread is placed in a new thread group
675 whose TGID is the same as the thread's TID.
678 of the new thread group.
680 A new thread created with
682 has the same parent process as the caller of
688 return the same value for all of the threads in a thread group.
691 thread terminates, the thread that created it using
695 (or other termination) signal;
696 nor can the status of such a thread be obtained
699 (The thread is said to be
702 After all of the threads in a thread group terminate
703 the parent process of the thread group is sent a
705 (or other termination) signal.
707 If any of the threads in a thread group performs an
709 then all threads other than the thread group leader are terminated,
710 and the new program is executed in the thread group leader.
712 If one of the threads in a thread group creates a child using
714 then any thread in the group can
725 (and note that, since Linux 2.6.0-test6,
731 Signals may be sent to a thread group as a whole (i.e., a TGID) using
733 or to a specific thread (i.e., TID) using
736 Signal dispositions and actions are process-wide:
737 if an unhandled signal is delivered to a thread, then
738 it will affect (terminate, stop, continue, be ignored in)
739 all members of the thread group.
741 Each thread has its own signal mask, as set by
743 but signals can be pending either: for the whole process
744 (i.e., deliverable to any member of the thread group),
747 or for an individual thread, when sent with
751 returns a signal set that is the union of the signals pending for the
752 whole process and the signals that are pending for the calling thread.
756 is used to send a signal to a thread group,
757 and the thread group has installed a handler for the signal, then
758 the handler will be invoked in exactly one, arbitrarily selected
759 member of the thread group that has not blocked the signal.
760 If multiple threads in a group are waiting to accept the same signal using
762 the kernel will arbitrarily select one of these threads
763 to receive a signal sent using
766 .BR CLONE_UNTRACED " (since Linux 2.5.46)"
769 is specified, then a tracing process cannot force
771 on this child process.
773 .BR CLONE_VFORK " (since Linux 2.2)"
776 is set, the execution of the calling process is suspended
777 until the child releases its virtual memory
778 resources via a call to
787 is not set, then both the calling process and the child are schedulable
788 after the call, and an application should not rely on execution occurring
789 in any particular order.
791 .BR CLONE_VM " (since Linux 2.0)"
794 is set, the calling process and the child process run in the same memory
796 In particular, memory writes performed by the calling process
797 or by the child process are also visible in the other process.
798 Moreover, any memory mapping or unmapping performed with
802 by the child or calling process also affects the other process.
806 is not set, the child process runs in a separate copy of the memory
807 space of the calling process at the time of
809 Memory writes or file mappings/unmappings performed by one of the
810 processes do not affect the other, as with
815 wrapper function makes some changes
816 in the memory pointed to by
818 (changes required to set the stack up correctly for the child)
825 is used to recursively create children,
826 do not use the buffer employed for the parent's stack
827 as the stack of the child.
829 .SS C library/kernel differences
832 system call corresponds more closely to
834 in that execution in the child continues from the point of the
842 wrapper function are omitted.
844 Unlike the glibc wrapper function, the raw
848 to be specified as NULL,
849 with the meaning that the child uses the stack that was
850 duplicated from the parent.
853 the parent's memory because of the use of the
855 flag, then chaos is likely to result if
857 is specified as NULL.)
859 The order of the arguments also differs in the raw system call,
860 and there are variations in the arguments across architectures,
861 as detailed in the following paragraphs.
863 The raw system call interface on x86-64 and some other architectures
864 (including sh, tile, and alpha) is roughly:
868 .BI "long clone(unsigned long " flags ", void *" child_stack ,
869 .BI " int *" ptid ", int *" ctid ,
870 .BI " unsigned long " newtls );
874 On x86-32, and several other common architectures
875 (including score, ARM, ARM 64, PA-RISC, arc, Power PC, xtensa,
877 .\" CONFIG_CLONE_BACKWARDS
878 the order of the last two arguments is reversed:
882 .BI "long clone(unsigned long " flags ", void *" child_stack ,
883 .BI " int *" ptid ", unsigned long " newtls ,
888 On the cris and s390 architectures,
889 .\" CONFIG_CLONE_BACKWARDS2
890 the order of the first two arguments is reversed:
894 .BI "long clone(void *" child_stack ", unsigned long " flags ,
895 .BI " int *" ptid ", int *" ctid ,
896 .BI " unsigned long " newtls );
900 On the microblaze architecture,
901 .\" CONFIG_CLONE_BACKWARDS3
902 an additional argument is supplied:
906 .BI "long clone(unsigned long " flags ", void *" child_stack ,
907 .BI " int " stack_size , "\fR /* Size of stack */"
908 .BI " int *" ptid ", int *" ctid ,
909 .BI " unsigned long " newtls );
913 Another difference for the raw system call is that the
915 argument may be zero, in which case copy-on-write semantics ensure that the
916 child gets separate copies of stack pages when either process modifies
918 In this case, for correct operation, the
920 option should not be specified.
922 .SS blackfin, m68k, and sparc
923 .\" Mike Frysinger noted in a 2013 mail:
924 .\" these arches don't define __ARCH_WANT_SYS_CLONE:
925 .\" blackfin ia64 m68k sparc
926 The argument-passing conventions on
927 blackfin, m68k, and sparc are different from the descriptions above.
928 For details, see the kernel (and glibc) source.
930 On ia64, a different interface is used:
933 .BI "int __clone2(int (*" "fn" ")(void *), "
934 .BI " void *" child_stack_base ", size_t " stack_size ,
935 .BI " int " flags ", void *" "arg" ", ... "
936 .BI " /* pid_t *" ptid ", struct user_desc *" tls \
937 ", pid_t *" ctid " */ );"
940 The prototype shown above is for the glibc wrapper function;
941 the raw system call interface has no
945 argument, and changes the order of the arguments so that
947 is the first argument, and
949 is the last argument.
952 operates in the same way as
956 points to the lowest address of the child's stack area,
959 specifies the size of the stack pointed to by
960 .IR child_stack_base .
961 .SS Linux 2.4 and earlier
962 In Linux 2.4 and earlier,
964 does not take arguments
970 .\" gettid(2) returns current->pid;
971 .\" getpid(2) returns current->tgid;
972 On success, the thread ID of the child process is returned
973 in the caller's thread of execution.
974 On failure, \-1 is returned
975 in the caller's context, no child process will be created, and
977 will be set appropriately.
981 Too many processes are already running; see
989 (Since Linux 2.6.0-test6.)
996 (Since Linux 2.5.35.)
1000 .\" .B CLONE_DETACHED
1004 .\" (Since Linux 2.6.0-test6.)
1007 .\" commit e66eded8309ebf679d3d3c1f5820d1f2ca332c71
1015 .BR EINVAL " (since Linux 3.9)"
1036 and one (or both) of
1044 Returned by the glibc
1046 wrapper function when
1050 is specified as NULL.
1056 but the kernel was not configured with the
1066 but the kernel was not configured with the
1074 but the kernel was not configured with the
1082 but the kernel was not configured with the
1088 is not aligned to a suitable boundary for this architecture.
1089 For example, on aarch64,
1091 must be a multiple of 16.
1094 Cannot allocate sufficient memory to allocate a task structure for the
1095 child, or to copy those parts of the caller's context that need to be
1098 .BR ENOSPC " (since Linux 3.7)"
1099 .\" commit f2302505775fd13ba93f034206f1e2a587017929
1101 was specified in flags,
1102 but the limit on the nesting depth of PID namespaces
1103 would have been exceeded; see
1104 .BR pid_namespaces (7).
1106 .BR ENOSPC " (since Linux 4.9; beforehand " EUSERS )
1110 and the call would cause the limit on the number of
1111 nested user namespaces to be exceeded.
1113 .BR user_namespaces (7).
1115 From Linux 3.11 to Linux 4.8, the error diagnosed in this case was
1118 .BR ENOSPC " (since Linux 4.9)"
1119 One of the values in
1121 specified the creation of a new user namespace,
1122 but doing so would have caused the limit defined by the corresponding file in
1125 For further details, see
1129 .BR CLONE_NEWCGROUP ,
1136 was specified by an unprivileged process (process without \fBCAP_SYS_ADMIN\fP).
1140 was specified by a process other than process 0.
1146 but either the effective user ID or the effective group ID of the caller
1147 does not have a mapping in the parent namespace (see
1148 .BR user_namespaces (7)).
1150 .BR EPERM " (since Linux 3.9)"
1151 .\" commit 3151527ee007b73a0ebd296010f1c0454a919c7d
1155 and the caller is in a chroot environment
1156 .\" FIXME What is the rationale for this restriction?
1157 (i.e., the caller's root directory does not match the root directory
1158 of the mount namespace in which it resides).
1160 .BR ERESTARTNOINTR " (since Linux 2.6.17)"
1161 .\" commit 4a2c7a7837da1b91468e50426066d988050e4d56
1162 System call was interrupted by a signal and will be restarted.
1163 (This can be seen only during a trace.)
1165 .BR EUSERS " (Linux 3.11 to Linux 4.8)"
1169 and the limit on the number of nested user namespaces would be exceeded.
1170 See the discussion of the
1174 .\" There is no entry for
1179 .\" as described in this manual page.
1182 is Linux-specific and should not be used in programs
1183 intended to be portable.
1187 system call can be used to test whether two processes share various
1188 resources such as a file descriptor table,
1189 System V semaphore undo operations, or a virtual address space.
1192 Handlers registered using
1193 .BR pthread_atfork (3)
1194 are not executed during a call to
1197 In the Linux 2.4.x series,
1199 generally does not make the parent of the new thread the same
1200 as the parent of the calling process.
1201 However, for kernel versions 2.4.7 to 2.4.18 the
1205 flag (as in Linux 2.6.0 and later).
1207 For a while there was
1209 (introduced in 2.5.32):
1210 parent wants no child-exit signal.
1211 In Linux 2.6.2, the need to give this flag together with
1214 This flag is still defined, but has no effect.
1218 should not be called through vsyscall, but directly through
1221 GNU C library versions 2.3.4 up to and including 2.24
1222 contained a wrapper function for
1224 that performed caching of PIDs.
1225 This caching relied on support in the glibc wrapper for
1227 but limitations in the implementation
1228 meant that the cache was not up to date in some circumstances.
1230 if a signal was delivered to the child immediately after the
1232 call, then a call to
1234 in a handler for the signal could return the PID
1235 of the calling process ("the parent"),
1236 if the clone wrapper had not yet had a chance to update the PID
1238 (This discussion ignores the case where the child was created using
1243 return the same value in the child and in the process that called
1245 since the caller and the child are in the same thread group.
1246 The stale-cache problem also does not occur if the
1250 To get the truth, it was sometimes necessary to use code such as the following:
1254 #include <syscall.h>
1258 mypid = syscall(SYS_getpid);
1261 .\" See also the following bug reports
1262 .\" https://bugzilla.redhat.com/show_bug.cgi?id=417521
1263 .\" http://sourceware.org/bugzilla/show_bug.cgi?id=6910
1265 Because of the stale-cache problem, as well as other problems noted in
1267 the PID caching feature was removed in glibc 2.25.
1269 The following program demonstrates the use of
1271 to create a child process that executes in a separate UTS namespace.
1272 The child changes the hostname in its UTS namespace.
1273 Both parent and child then display the system hostname,
1274 making it possible to see that the hostname
1275 differs in the UTS namespaces of the parent and child.
1276 For an example of the use of this program, see
1281 #include <sys/wait.h>
1282 #include <sys/utsname.h>
1289 #define errExit(msg) do { perror(msg); exit(EXIT_FAILURE); \\
1292 static int /* Start function for cloned child */
1293 childFunc(void *arg)
1297 /* Change hostname in UTS namespace of child */
1299 if (sethostname(arg, strlen(arg)) == \-1)
1300 errExit("sethostname");
1302 /* Retrieve and display hostname */
1304 if (uname(&uts) == \-1)
1306 printf("uts.nodename in child: %s\\n", uts.nodename);
1308 /* Keep the namespace open for a while, by sleeping.
1309 This allows some experimentation\-\-for example, another
1310 process might join the namespace. */
1314 return 0; /* Child terminates now */
1317 #define STACK_SIZE (1024 * 1024) /* Stack size for cloned child */
1320 main(int argc, char *argv[])
1322 char *stack; /* Start of stack buffer */
1323 char *stackTop; /* End of stack buffer */
1328 fprintf(stderr, "Usage: %s <child\-hostname>\\n", argv[0]);
1332 /* Allocate stack for child */
1334 stack = malloc(STACK_SIZE);
1337 stackTop = stack + STACK_SIZE; /* Assume stack grows downward */
1339 /* Create child that has its own UTS namespace;
1340 child commences execution in childFunc() */
1342 pid = clone(childFunc, stackTop, CLONE_NEWUTS | SIGCHLD, argv[1]);
1345 printf("clone() returned %ld\\n", (long) pid);
1347 /* Parent falls through to here */
1349 sleep(1); /* Give child time to change its hostname */
1351 /* Display hostname in parent\(aqs UTS namespace. This will be
1352 different from hostname in child\(aqs UTS namespace. */
1354 if (uname(&uts) == \-1)
1356 printf("uts.nodename in parent: %s\\n", uts.nodename);
1358 if (waitpid(pid, NULL, 0) == \-1) /* Wait for child */
1360 printf("child has terminated\\n");
1371 .BR set_thread_area (2),
1372 .BR set_tid_address (2),
1377 .BR capabilities (7),