]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man2/clone.2
ffix
[thirdparty/man-pages.git] / man2 / clone.2
CommitLineData
fea681da
MK
1.\" Hey Emacs! This file is -*- nroff -*- source.
2.\"
3.\" Copyright (c) 1992 Drew Eckhardt <drew@cs.colorado.edu>, March 28, 1992
1130df60 4.\" and Copyright (c) Michael Kerrisk, 2001, 2002, 2005
fea681da
MK
5.\" May be distributed under the GNU General Public License.
6.\" Modified by Michael Haardt <michael@moria.de>
7.\" Modified 24 Jul 1993 by Rik Faith <faith@cs.unc.edu>
8.\" Modified 21 Aug 1994 by Michael Chastain <mec@shell.portal.com>:
9.\" New man page (copied from 'fork.2').
10.\" Modified 10 June 1995 by Andries Brouwer <aeb@cwi.nl>
11.\" Modified 25 April 1998 by Xavier Leroy <Xavier.Leroy@inria.fr>
12.\" Modified 26 Jun 2001 by Michael Kerrisk
13.\" Mostly upgraded to 2.4.x
14.\" Added prototype for sys_clone() plus description
15.\" Added CLONE_THREAD with a brief description of thread groups
c13182ef 16.\" Added CLONE_PARENT and revised entire page remove ambiguity
fea681da
MK
17.\" between "calling process" and "parent process"
18.\" Added CLONE_PTRACE and CLONE_VFORK
19.\" Added EPERM and EINVAL error codes
fd8a5be4 20.\" Renamed "__clone" to "clone" (which is the prototype in <sched.h>)
fea681da 21.\" various other minor tidy ups and clarifications.
305a0578 22.\" Modified 26 Jun 2001 by Michael Kerrisk <mtk-manpages@gmx.net>
d9bfdb9c 23.\" Updated notes for 2.4.7+ behavior of CLONE_THREAD
305a0578 24.\" Modified 15 Oct 2002 by Michael Kerrisk <mtk-manpages@gmx.net>
fea681da
MK
25.\" Added description for CLONE_NEWNS, which was added in 2.4.19
26.\" Slightly rephrased, aeb.
27.\" Modified 1 Feb 2003 - added CLONE_SIGHAND restriction, aeb.
28.\" Modified 1 Jan 2004 - various updates, aeb
29.\" Modified 2004-09-10 - added CLONE_PARENT_SETTID etc - aeb.
d9bfdb9c 30.\" 2005-04-12, mtk, noted the PID caching behavior of NPTL's getpid()
31830ef0 31.\" wrapper under BUGS.
fd8a5be4
MK
32.\" 2005-05-10, mtk, added CLONE_SYSVSEM, CLONE_UNTRACED, CLONE_STOPPED.
33.\" 2005-05-17, mtk, Substantially enhanced discussion of CLONE_THREAD.
fea681da 34.\"
360ed6b3 35.\" FIXME Document CLONE_NEWIPC, which is new in 2.6.18
185341d4 36.\" (also supported for unshare()?)
360ed6b3 37.\" FIXME Document CLONE_NEWUTS, which is new in 2.6.19
185341d4
MK
38.\" (also supported for unshare()?)
39.\" FIXME Document CLONE_NEWUSER, which is new in 2.6.23
40.\" (also supported for unshare()?)
360ed6b3 41.\"
cc4615cc 42.TH CLONE 2 2007-07-26 "Linux" "Linux Programmer's Manual"
fea681da 43.SH NAME
9b0e0996 44clone, __clone2 \- create a child process
fea681da 45.SH SYNOPSIS
c10859eb 46.nf
cc4615cc
MK
47.B #define _GNU_SOURCE
48.\" Actually _BSD_SOURCE || _SVID_SOURCE
49.\" See http://sources.redhat.com/bugzilla/show_bug.cgi?id=4749
fea681da 50.B #include <sched.h>
c10859eb 51
ff929e3b
MK
52.BI "int clone(int (*" "fn" ")(void *), void *" child_stack ,
53.BI " int " flags ", void *" "arg" ", ... "
54.BI " /* pid_t *" pid ", struct user_desc *" tls \
55", pid_t *" ctid " */ );"
c10859eb 56.fi
fea681da 57.SH DESCRIPTION
edcc65ff
MK
58.BR clone ()
59creates a new process, in a manner similar to
fea681da 60.BR fork (2).
735f354f 61It is actually a library function layered on top of the underlying
e511ffb6 62.BR clone ()
fea681da
MK
63system call, hereinafter referred to as
64.BR sys_clone .
65A description of
66.BR sys_clone
67is given towards the end of this page.
68
69Unlike
70.BR fork (2),
c13182ef 71these calls
fea681da
MK
72allow the child process to share parts of its execution context with
73the calling process, such as the memory space, the table of file
c13182ef
MK
74descriptors, and the table of signal handlers.
75(Note that on this manual
76page, "calling process" normally corresponds to "parent process".
77But see the description of
78.B CLONE_PARENT
fea681da
MK
79below.)
80
81The main use of
edcc65ff 82.BR clone ()
fea681da
MK
83is to implement threads: multiple threads of control in a program that
84run concurrently in a shared memory space.
85
86When the child process is created with
c13182ef 87.BR clone (),
fea681da
MK
88it executes the function
89application
c13182ef 90.IR fn ( arg ).
fea681da 91(This differs from
c13182ef 92.BR fork (2),
fea681da 93where execution continues in the child from the point
c13182ef
MK
94of the
95.BR fork (2)
fea681da
MK
96call.)
97The
98.I fn
99argument is a pointer to a function that is called by the child
100process at the beginning of its execution.
101The
102.I arg
103argument is passed to the
104.I fn
105function.
106
c13182ef 107When the
fea681da 108.IR fn ( arg )
c13182ef
MK
109function application returns, the child process terminates.
110The integer returned by
fea681da 111.I fn
c13182ef
MK
112is the exit code for the child process.
113The child process may also terminate explicitly by calling
fea681da
MK
114.BR exit (2)
115or after receiving a fatal signal.
116
117The
118.I child_stack
c13182ef
MK
119argument specifies the location of the stack used by the child process.
120Since the child and calling process may share memory,
fea681da 121it is not possible for the child process to execute in the
c13182ef
MK
122same stack as the calling process.
123The calling process must therefore
fea681da
MK
124set up memory space for the child stack and pass a pointer to this
125space to
edcc65ff 126.BR clone ().
fea681da
MK
127Stacks grow downwards on all processors that run Linux
128(except the HP PA processors), so
129.I child_stack
130usually points to the topmost address of the memory space set up for
131the child stack.
132
133The low byte of
134.I flags
fd8a5be4
MK
135contains the number of the
136.I "termination signal"
137sent to the parent when the child dies.
138If this signal is specified as anything other than
fea681da
MK
139.BR SIGCHLD ,
140then the parent process must specify the
c13182ef
MK
141.B __WALL
142or
fea681da 143.B __WCLONE
c13182ef
MK
144options when waiting for the child with
145.BR wait (2).
fea681da
MK
146If no signal is specified, then the parent process is not signaled
147when the child terminates.
148
149.I flags
fd8a5be4
MK
150may also be bitwise-or'ed with zero or more of the following constants,
151in order to specify what is shared between the calling process
fea681da 152and the child process:
fea681da
MK
153.TP
154.BR CLONE_PARENT " (since Linux 2.3.12)"
155If
156.B CLONE_PARENT
157is set, then the parent of the new child (as returned by
158.BR getppid (2))
159will be the same as that of the calling process.
160
161If
162.B CLONE_PARENT
163is not set, then (as with
164.BR fork (2))
165the child's parent is the calling process.
166
c13182ef 167Note that it is the parent process, as returned by
fea681da
MK
168.BR getppid (2),
169which is signaled when the child terminates, so that
c13182ef 170if
fea681da 171.B CLONE_PARENT
c13182ef 172is set, then the parent of the calling process, rather than the
fea681da 173calling process itself, will be signaled.
fea681da
MK
174.TP
175.B CLONE_FS
176If
177.B CLONE_FS
178is set, the caller and the child processes share the same file system
c13182ef
MK
179information.
180This includes the root of the file system, the current
181working directory, and the umask.
182Any call to
fea681da
MK
183.BR chroot (2),
184.BR chdir (2),
185or
186.BR umask (2)
edcc65ff 187performed by the calling process or the child process also affects the
fea681da
MK
188other process.
189
c13182ef 190If
fea681da
MK
191.B CLONE_FS
192is not set, the child process works on a copy of the file system
193information of the calling process at the time of the
edcc65ff 194.BR clone ()
fea681da
MK
195call.
196Calls to
197.BR chroot (2),
198.BR chdir (2),
199.BR umask (2)
200performed later by one of the processes do not affect the other process.
fea681da
MK
201.TP
202.B CLONE_FILES
203If
204.B CLONE_FILES
205is set, the calling process and the child processes share the same file
edcc65ff 206descriptor table.
c13182ef 207Any file descriptor created by the calling process or by the child
edcc65ff
MK
208process is also valid in the other process.
209Similarly, if one of the processes closes a file descriptor,
210or changes its associated flags (using the
211.BR fcntl (2)
212.B F_SETFD
213operation), the other process is also affected.
fea681da
MK
214
215If
216.B CLONE_FILES
217is not set, the child process inherits a copy of all file descriptors
218opened in the calling process at the time of
edcc65ff
MK
219.BR clone ().
220(The duplicated file descriptors in the child refer to the
c13182ef 221same open file descriptions (see
edcc65ff
MK
222.BR open (2))
223as the corresponding file descriptors in the calling process.)
224Subsequent operations that open or close file descriptors,
225or change file descriptor flags,
c13182ef 226performed by either the calling
edcc65ff 227process or the child process do not affect the other process.
fea681da 228.TP
c10859eb 229.BR CLONE_NEWNS " (since Linux 2.4.19)"
fea681da
MK
230Start the child in a new namespace.
231
c13182ef
MK
232Every process lives in a namespace.
233The
fea681da
MK
234.I namespace
235of a process is the data (the set of mounts) describing the file hierarchy
c13182ef
MK
236as seen by that process.
237After a
fea681da
MK
238.BR fork (2)
239or
240.BR clone (2)
241where the
242.B CLONE_NEWNS
243flag is not set, the child lives in the same namespace as the parent.
244The system calls
245.BR mount (2)
246and
247.BR umount (2)
248change the namespace of the calling process, and hence affect
249all processes that live in the same namespace, but do not affect
250processes in a different namespace.
251
252After a
253.BR clone (2)
254where the
255.B CLONE_NEWNS
256flag is set, the cloned child is started in a new namespace,
257initialized with a copy of the namespace of the parent.
258
0b9bdf82 259Only a privileged process (one having the \fBCAP_SYS_ADMIN\fP capability)
fea681da
MK
260may specify the
261.B CLONE_NEWNS
262flag.
263It is not permitted to specify both
264.B CLONE_NEWNS
265and
266.B CLONE_FS
267in the same
e511ffb6 268.BR clone ()
fea681da 269call.
fea681da
MK
270.TP
271.B CLONE_SIGHAND
272If
273.B CLONE_SIGHAND
274is set, the calling process and the child processes share the same table of
c13182ef
MK
275signal handlers.
276If the calling process or child process calls
fea681da 277.BR sigaction (2)
c13182ef
MK
278to change the behavior associated with a signal, the behavior is
279changed in the other process as well.
280However, the calling process and child
fea681da 281processes still have distinct signal masks and sets of pending
c13182ef
MK
282signals.
283So, one of them may block or unblock some signals using
fea681da
MK
284.BR sigprocmask (2)
285without affecting the other process.
286
287If
288.B CLONE_SIGHAND
289is not set, the child process inherits a copy of the signal handlers
290of the calling process at the time
edcc65ff 291.BR clone ()
c13182ef
MK
292is called.
293Calls to
fea681da
MK
294.BR sigaction (2)
295performed later by one of the processes have no effect on the other
296process.
29546c24
MK
297
298Since Linux 2.6.0-test6,
299.I flags
300must also include
301.B CLONE_VM
302if
303.B CLONE_SIGHAND
304is specified
fea681da
MK
305.TP
306.B CLONE_PTRACE
c13182ef 307If
fea681da 308.B CLONE_PTRACE
a69b6bda
MK
309is specified, and the calling process is being traced,
310then trace the child also (see
fea681da 311.BR ptrace (2)).
a69b6bda
MK
312.TP
313.BR CLONE_UNTRACED " (since Linux 2.5.46)"
c13182ef 314If
a69b6bda
MK
315.B CLONE_UNTRACED
316is specified, then a tracing process cannot force
317.B CLONE_PTRACE
318on this child process.
319.TP
320.BR CLONE_STOPPED " (since Linux 2.6.0-test2)"
321If
322.B CLONE_STOPPED
323is set, then the child is initially stopped (as though it was sent a
324.B SIGSTOP
325signal), and must be resumed by sending it a
326.B SIGCONT
327signal.
328.TP
fea681da
MK
329.B CLONE_VFORK
330If
331.B CLONE_VFORK
332is set, the execution of the calling process is suspended
333until the child releases its virtual memory
334resources via a call to
335.BR execve (2)
336or
337.BR _exit (2)
c13182ef 338(as with
fea681da
MK
339.BR vfork (2)).
340
c13182ef 341If
fea681da
MK
342.B CLONE_VFORK
343is not set then both the calling process and the child are schedulable
344after the call, and an application should not rely on execution occurring
345in any particular order.
fea681da
MK
346.TP
347.B CLONE_VM
348If
349.B CLONE_VM
350is set, the calling process and the child processes run in the same memory
c13182ef
MK
351space.
352In particular, memory writes performed by the calling process
fea681da
MK
353or by the child process are also visible in the other process.
354Moreover, any memory mapping or unmapping performed with
355.BR mmap (2)
356or
357.BR munmap (2)
358by the child or calling process also affects the other process.
359
360If
361.B CLONE_VM
362is not set, the child process runs in a separate copy of the memory
363space of the calling process at the time of
edcc65ff 364.BR clone ().
fea681da
MK
365Memory writes or file mappings/unmappings performed by one of the
366processes do not affect the other, as with
367.BR fork (2).
fea681da
MK
368.TP
369.BR CLONE_PID " (obsolete)"
370If
371.B CLONE_PID
c13182ef
MK
372is set, the child process is created with the same process ID as
373the calling process.
374This is good for hacking the system, but otherwise
375of not much use.
376Since 2.3.21 this flag can be
fea681da
MK
377specified only by the system boot process (PID 0).
378It disappeared in Linux 2.5.16.
fea681da
MK
379.TP
380.BR CLONE_THREAD " (since Linux 2.4.0-test8)"
381If
382.B CLONE_THREAD
383is set, the child is placed in the same thread group as the calling process.
fd8a5be4
MK
384To make the remainder of the discussion of
385.B CLONE_THREAD
386more readable, the term "thread" is used to refer to the
387processes within a thread group.
fea681da 388
fd8a5be4
MK
389Thread groups were a feature added in Linux 2.4 to support the
390POSIX threads notion of a set of threads that share a single PID.
391Internally, this shared PID is the so-called
392thread group identifier (TGID) for the thread group.
c13182ef 393Since Linux 2.4, calls to
fea681da 394.BR getpid (2)
fd8a5be4
MK
395return the TGID of the caller.
396
397The threads within a group can be distinguished by their (system-wide)
398unique thread IDs (TID).
399A new thread's TID is available as the function result
400returned to the caller of
401.BR clone (),
402and a thread can obtain
403its own TID using
404.BR gettid (2).
405
c13182ef 406When a call is made to
fd8a5be4
MK
407.BR clone ()
408without specifying
409.BR CLONE_THREAD ,
410then the resulting thread is placed in a new thread group
411whose TGID is the same as the thread's TID.
412This thread is the
413.I leader
414of the new thread group.
415
416A new thread created with
417.B CLONE_THREAD
418has the same parent process as the caller of
419.BR clone ()
c13182ef 420(i.e., like
fd8a5be4
MK
421.BR CLONE_PARENT ),
422so that calls to
423.BR getppid (2)
424return the same value for all of the threads in a thread group.
425When a
c13182ef 426.B CLONE_THREAD
fd8a5be4
MK
427thread terminates, the thread that created it using
428.BR clone ()
429is not sent a
430.B SIGCHLD
431(or other termination) signal;
432nor can the status of such a thread be obtained
433using
434.BR wait (2).
435(The thread is said to be
436.IR detached .)
437
e2fbf61d
MK
438After all of the threads in a thread group terminate
439the parent process of the thread group is sent a
fd8a5be4
MK
440.B SIGCHLD
441(or other termination) signal.
442
443If any of the threads in a thread group performs an
444.BR execve (2),
445then all threads other than the thread group leader are terminated,
446and the new program is executed in the thread group leader.
447
f7110f60
MK
448If one of the threads in a thread group creates a child using
449.BR fork (2),
450then any thread in the group can
451.BR wait (2)
452for that child.
453
edcc65ff 454Since Linux 2.5.35,
fd8a5be4
MK
455.I flags
456must also include
457.B CLONE_SIGHAND
458if
459.B CLONE_THREAD
460is specified.
e2fbf61d
MK
461
462Signals may be sent to a thread group as a whole (i.e., a TGID) using
463.BR kill (2),
464or to a specific thread (i.e., TID) using
465.BR tgkill (2).
466
467Signal dispositions and actions are process-wide:
468if an unhandled signal is delivered to a thread, then
469it will affect (terminate, stop, continue, be ignored in)
470all members of the thread group.
471
99408a60 472Each thread has its own signal mask, as set by
e2fbf61d 473.BR sigprocmask (2),
82a06020 474but signals can be pending either: for the whole process
e2fbf61d
MK
475(i.e., deliverable to any member of the thread group),
476when sent with
82a06020 477.BR kill (2);
e2fbf61d
MK
478or for an individual thread, when sent with
479.BR tgkill (2).
99408a60
MK
480A call to
481.BR sigpending (2)
482returns a signal set that is the union of the signals pending for the
483whole process and the signals that are pending for the calling thread.
e2fbf61d 484
c13182ef 485If
e2fbf61d
MK
486.BR kill (2)
487is used to send a signal to a thread group,
488and the thread group has installed a handler for the signal, then
489the handler will be invoked in exactly one, arbitrarily selected
490member of the thread group that has not blocked the signal.
c13182ef 491If multiple threads in a group are waiting to accept the same signal using
e2fbf61d
MK
492.BR sigwaitinfo (2),
493the kernel will arbitrarily select one of these threads
c13182ef 494to receive a signal sent using
e2fbf61d 495.BR kill (2).
a69b6bda
MK
496.TP
497.BR CLONE_SYSVSEM " (since Linux 2.5.10)"
498If
499.B CLONE_SYSVSEM
500is set, then the child and the calling process share
501a single list of System V semaphore undo values (see
502.BR semop (2)).
503If this flag is not set, then the child has a separate undo list,
504which is initially empty.
fea681da
MK
505.TP
506.BR CLONE_SETTLS " (since Linux 2.5.32)"
507The
508.I newtls
509parameter is the new TLS (Thread Local Storage) descriptor.
510(See
511.BR set_thread_area (2).)
fea681da
MK
512.TP
513.BR CLONE_PARENT_SETTID " (since Linux 2.5.49)"
514Store child thread ID at location
515.I parent_tidptr
516in parent and child memory.
682edefb
MK
517(In Linux 2.5.32-2.5.48 there was a flag
518.B CLONE_SETTID
519that did this.)
fea681da
MK
520.TP
521.BR CLONE_CHILD_SETTID " (since Linux 2.5.49)"
522Store child thread ID at location
523.I child_tidptr
524in child memory.
fea681da
MK
525.TP
526.BR CLONE_CHILD_CLEARTID " (since Linux 2.5.49)"
527Erase child thread ID at location
528.I child_tidptr
529in child memory when the child exits, and do a wakeup on the futex
530at that address.
531The address involved may be changed by the
532.BR set_tid_address (2)
c13182ef
MK
533system call.
534This is used by threading libraries.
fea681da
MK
535.SS "sys_clone"
536The
537.B sys_clone
538system call corresponds more closely to
539.BR fork (2)
540in that execution in the child continues from the point of the
c13182ef
MK
541call.
542Thus,
fea681da
MK
543.B sys_clone
544only requires the
545.I flags
c13182ef 546and
fea681da 547.I child_stack
c13182ef
MK
548arguments, which have the same meaning as for
549.BR clone ().
fea681da 550(Note that the order of these arguments differs from
c13182ef 551.BR clone ().)
fea681da 552
c13182ef 553Another difference for
fea681da
MK
554.B sys_clone
555is that the
556.I child_stack
c13182ef 557argument may be zero, in which case copy-on-write semantics ensure that the
fea681da 558child gets separate copies of stack pages when either process modifies
c13182ef
MK
559the stack.
560In this case, for correct operation, the
fea681da
MK
561.B CLONE_VM
562option should not be specified.
563
564Since Linux 2.5.49 the system call has five parameters.
565The two new parameters are
566.I parent_tidptr
567which points to the location (in parent and child memory) where
682edefb
MK
568the child thread ID will be written in case
569.B CLONE_PARENT_SETTID
fea681da
MK
570was specified, and
571.I child_tidptr
572which points to the location (in child memory) where the child thread ID
682edefb
MK
573will be written in case
574.B CLONE_CHILD_SETTID
575was specified.
fea681da 576.SH "RETURN VALUE"
0bfa087b
MK
577.\" gettid(2) returns current->pid;
578.\" getpid(2) returns current->tgid;
fea681da 579On success, the thread ID of the child process is returned
c13182ef
MK
580in the caller's thread of execution.
581On failure, a \-1 will be returned
fea681da
MK
582in the caller's context, no child process will be created, and
583.I errno
584will be set appropriately.
fea681da
MK
585.SH ERRORS
586.TP
587.B EAGAIN
588Too many processes are already running.
589.TP
590.B EINVAL
591.B CLONE_SIGHAND
592was specified, but
593.B CLONE_VM
2e8a7fb3
MK
594was not.
595(Since Linux 2.6.0-test6.)
fea681da
MK
596.TP
597.B EINVAL
598.B CLONE_THREAD
599was specified, but
600.B CLONE_SIGHAND
601was not. (Since Linux 2.5.35.)
29546c24
MK
602.\" .TP
603.\" .B EINVAL
604.\" Precisely one of
605.\" .B CLONE_DETACHED
606.\" and
607.\" .B CLONE_THREAD
608.\" was specified. (Since Linux 2.6.0-test6.)
fea681da
MK
609.TP
610.B EINVAL
611Both
612.B CLONE_FS
613and
614.B CLONE_NEWNS
615were specified in
616.IR flags .
617.TP
618.B EINVAL
c13182ef 619Returned by
edcc65ff 620.BR clone ()
c13182ef 621when a zero value is specified for
fea681da
MK
622.IR child_stack .
623.TP
624.B ENOMEM
625Cannot allocate sufficient memory to allocate a task structure for the
626child, or to copy those parts of the caller's context that need to be
627copied.
628.TP
629.B EPERM
630.B CLONE_NEWNS
0b9bdf82 631was specified by a non-root process (process without \fBCAP_SYS_ADMIN\fP).
fea681da
MK
632.TP
633.B EPERM
634.B CLONE_PID
635was specified by a process other than process 0.
a759cc87 636.SH VERSIONS
fea681da 637There is no entry for
edcc65ff 638.BR clone ()
a759cc87
MK
639in libc5.
640glibc2 provides
edcc65ff 641.BR clone ()
fea681da 642as described in this manual page.
a1d5f77c
MK
643.SH "CONFORMING TO"
644The
645.BR clone ()
646and
647.B sys_clone
648calls are Linux specific and should not be used in programs
649intended to be portable.
fea681da 650.SH NOTES
fd8a5be4
MK
651In the kernel 2.4.x series,
652.B CLONE_THREAD
653generally does not make the parent of the new thread the same
654as the parent of the calling process.
655However, for kernel versions 2.4.7 to 2.4.18 the
656.B CLONE_THREAD
657flag implied the
c13182ef 658.B CLONE_PARENT
fd8a5be4 659flag (as in kernel 2.6).
fea681da 660
c13182ef
MK
661For a while there was
662.B CLONE_DETACHED
a5053dcb 663(introduced in 2.5.32):
c13182ef 664parent wants no child-exit signal.
a5053dcb 665In 2.6.2 the need to give this
c13182ef
MK
666together with
667.B CLONE_THREAD
a5053dcb
MK
668disappeared.
669This flag is still defined, but has no effect.
670
a5a997ca
MK
671On x86,
672.BR clone ()
673should not be called through vsyscall, but directly through
674.IR "int $0x80" .
ff929e3b 675
22399250 676On ia64, a different system call is used:
ff929e3b
MK
677.nf
678
9b0e0996
MK
679.BI "int __clone2(int (*" "fn" ")(void *), "
680.BI " void *" child_stack_base ", size_t " stack_size ,
681.BI " int " flags ", void *" "arg" ", ... "
682.BI " /* pid_t *" pid ", struct user_desc *" tls \
ff929e3b
MK
683", pid_t *" ctid " */ );"
684.fi
685.PP
686The
9b0e0996 687.BR __clone2 ()
c13182ef 688system call operates in the same way as
ff929e3b
MK
689.BR clone (),
690except that
691.I child_stack_base
692points to the lowest address of the child's stack area,
693and
694.I stack_size
695specifies the size of the stack pointed to by
696.IR child_stack_base .
31830ef0
MK
697.SH BUGS
698Versions of the GNU C library that include the NPTL threading library
c13182ef 699contain a wrapper function for
0bfa087b 700.BR getpid (2)
31830ef0 701that performs caching of PIDs.
c13182ef 702In programs linked against such libraries, calls to
0bfa087b 703.BR getpid (2)
31830ef0
MK
704may return the same value, even when the threads were not created using
705.B CLONE_THREAD
706(and thus are not in the same thread group).
707To get the truth, it may be necessary to use code such as the following
708.nf
709
710 #include <syscall.h>
711
712 pid_t mypid;
713
714 mypid = syscall(SYS_getpid);
715.fi
fea681da
MK
716.SH "SEE ALSO"
717.BR fork (2),
2b44301c 718.BR futex (2),
fea681da
MK
719.BR getpid (2),
720.BR gettid (2),
f2d0bbf1 721.BR set_thread_area (2),
2b44301c 722.BR set_tid_address (2),
f2d0bbf1 723.BR tkill (2),
5cc01e9c 724.BR unshare (2),
fea681da 725.BR wait (2),
3616b7c0
MK
726.BR capabilities (7),
727.BR pthreads (7)