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