Re: clone()

H. Peter Anvin (hpa@transmeta.com)
3 May 1997 18:26:02 GMT


Followup to: <Pine.LNX.3.96.970503205420.20745A-100000@vipe.technion.ac.il>
By author: Andi Gutmans <andi@vipe.technion.ac.il>
In newsgroup: linux.dev.kernel
>
> 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
of.

-hpa

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