1clone(2)                      System Calls Manual                     clone(2)
2
3
4

NAME

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

LIBRARY

9       Standard C library (libc, -lc)
10

SYNOPSIS

12       /* Prototype for the glibc wrapper function */
13
14       #define _GNU_SOURCE
15       #include <sched.h>
16
17       int clone(int (*fn)(void *_Nullable), void *stack, int flags,
18                 void *_Nullable arg, ...  /* pid_t *_Nullable parent_tid,
19                                              void *_Nullable tls,
20                                              pid_t *_Nullable child_tid */ );
21
22       /* For the prototype of the raw clone() system call, see NOTES */
23
24       #include <linux/sched.h>    /* Definition of struct clone_args */
25       #include <sched.h>          /* Definition of CLONE_* constants */
26       #include <sys/syscall.h>    /* Definition of SYS_* constants */
27       #include <unistd.h>
28
29       long syscall(SYS_clone3, struct clone_args *cl_args, size_t size);
30
31       Note:  glibc provides no wrapper for clone3(), necessitating the use of
32       syscall(2).
33

DESCRIPTION

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