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       #include <linux/sched.h>    /* Definition of struct clone_args */
20       #include <sched.h>          /* Definition of CLONE_* constants */
21       #include <sys/syscall.h>    /* Definition of SYS_* constants */
22       #include <unistd.h>
23
24       long syscall(SYS_clone3, struct clone_args *cl_args, size_t size);
25
26       Note:  glibc provides no wrapper for clone3(), necessitating the use of
27       syscall(2).
28

DESCRIPTION

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