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