Re: clone()

H. Peter Anvin (
3 May 1997 18:26:02 GMT

Followup to: <>
By author: Andi Gutmans <>
In newsgroup:
> From the clone() man page (man-pages 1.15):
> - clone is an alternate interface to fork, with more options. fork
> - is equivalent to clone(0, SIGCLD|COPYVM).
> COPYVM is not defined any place on my system... I did a grep on all .h
> files and i have linuxthreads 0.5 installed.

It's actually called CLONE_VM (the proper invocation would be
clone(0, SIGCHLD|CLONE_VM)) and is defined in <linux/sched.h>, which,
among other places, in included from <pthread.h>.

WARNING: Last I checked, clone() isn't a C library function, and you
MUST NOT invoke it from C code using syscall() unless you have the
CLONE_VM flag, since you will end up with multiple threads
threading(!) on the same stack. An assembly wrapper is *mandatory*.

You're much better off forgetting about clone() and just use the POSIX
thread API. clone() isn't meant to be an interface, but a mechanism
for libraries like LinuxThreads to implement a reasonable API on top


Always looking for a few good BOsFH.  **  Linux - the OS of global cooperation
        I am Baha'i -- ask me about it or see