1CLONE(2)                   Linux Programmer's Manual                  CLONE(2)
2
3
4

NAME

6       clone, __clone2, clone3 - create a child process
7

SYNOPSIS

9       /* Prototype for the glibc wrapper function */
10
11       #define _GNU_SOURCE
12       #include <sched.h>
13
14       int clone(int (*fn)(void *), void *stack, int flags, void *arg, ...
15                 /* pid_t *parent_tid, void *tls, pid_t *child_tid */ );
16
17       /* For the prototype of the raw clone() system call, see NOTES */
18
19       long clone3(struct clone_args *cl_args, size_t size);
20
21       Note: There is not yet a glibc wrapper for clone3(); see NOTES.
22

DESCRIPTION

24       These  system calls create a new ("child") process, in a manner similar
25       to fork(2).
26
27       By contrast with fork(2), these system calls provide more precise  con‐
28       trol over what pieces of execution context are shared between the call‐
29       ing process and the child process.  For  example,  using  these  system
30       calls,  the  caller  can control whether or not the two processes share
31       the virtual address space, the table of file descriptors, and the table
32       of  signal  handlers.   These  system  calls  also  allow the new child
33       process to be placed in separate namespaces(7).
34
35       Note that in this manual page, "calling process"  normally  corresponds
36       to  "parent  process".   But  see  the descriptions of CLONE_PARENT and
37       CLONE_THREAD below.
38
39       This page describes the following interfaces:
40
41       *  The glibc clone() wrapper function and the underlying system call on
42          which  it  is  based.  The main text describes the wrapper function;
43          the differences for the raw system call are described toward the end
44          of this page.
45
46       *  The newer clone3() system call.
47
48       In the remainder of this page, the terminology "the clone call" is used
49       when noting details that apply to all of these interfaces,
50
51   The clone() wrapper function
52       When the child process is created with the clone() wrapper function, it
53       commences  execution by calling the function pointed to by the argument
54       fn.  (This differs from fork(2), where execution continues in the child
55       from the point of the fork(2) call.)  The arg argument is passed as the
56       argument of the function fn.
57
58       When the fn(arg) function returns, the child process  terminates.   The
59       integer  returned  by fn is the exit status for the child process.  The
60       child process may also terminate explicitly by calling exit(2) or after
61       receiving a fatal signal.
62
63       The  stack  argument  specifies  the  location of the stack used by the
64       child process.  Since the child and calling process may  share  memory,
65       it  is  not possible for the child process to execute in the same stack