CLONE(2) Linux Programmer's Manual CLONE(2)
NAME
clone, __clone2 - create a child process
SYNOPSIS
#include <sched.h>
int clone(int (*fn)(void *), void *child_stack,
int flags, void *arg, ...
/* pid_t *pid, struct user_desc *tls, pid_t *ctid */ );
int __clone2(int (*fn)(void *), void *child_stack_base,
size_t stack_size, int flags, void *arg, ...
/* pid_t *pid, func-
tion termi-
nates. The integer returned by fn is the exit code for the child pro-
cess. The child process may also terminate explicitly by calling
exit(2) or after receiving a fatal signal.
The child_stack argument specifies the location of the stack used by
the child process. Since the child and calling process may share mem-
ory, con-
stants, in order to specify what is shared between the calling process
and the child process: call-
ing) per-
formed later by one of the processes do not affect the other
process.
CLONE_FILES
If CLONE_FILES is set, the calling process and the child pro-
cesses share the same file descriptor table. Any file descrip-
tor created by the calling process or by the child process is
also valid in the other process. Similarly, if one of the pro-
cesses corre-
sponding file descriptors in the calling process.) Subsequent
operations that open or close file descriptors, or change file
descriptor flags, performed by either the calling process or the
child process do not affect the other process.
CLONE names-
pace capabil-
ity) may specify the CLONE_NEWNS flag. It is not permitted to
specify both CLONE_NEWNS and CLONE_FS in the same clone() call.
CLONE_SIGHAND
If CLONE_SIGHAND is set, the calling process and the child pro-
cesses share the same table of signal handlers. If the calling
process or child process calls sigaction(2) to change the behav-
i. per-
formed_THREAD (since Linux 2.4.0-test8)
If CLONE_THREAD is set, the child is placed in the same thread
group as the calling process. To make the remainder of the dis-
cussion (sys-
tem-wide) unique thread IDs (TID). A new thread's TID is avail-
able pro-
cess termina-
tion) signal.
If any of the threads in a thread group performs an execve(2),
then all threads other than the thread group leader are termi-
nated,han-
dled signal is delivered to a thread, then it will affect (ter-
minate, sig-
nal using sigwaitinfo(2), the kernel will arbitrarily select one
of these threads to receive a signal sent using kill(2). sepa-
rate. argu-
ments.
Since Linux 2.5.49 the system call has five parameters. The two new
parameters are parent_tidptr which points to the location (in x86, clone() should not be called through vsyscall, but directly
through int $0x80.
On IA-64, a different system call is used:
int __clone2(int (*fn)(void *), void *child_stack_base,
size_t stack_size, int flags, void *arg, ...
/* pid_t *pid,.
In programs linked against such libraries, calls to getpid(2) may
return the same value, even when the threads were not created using
CLONE_THREAD (and thus are not in the same thread group).)
Linux 2.6 2007-06-01 CLONE(2)