Subject: Re: clone()
To: Andrew Doran <>
From: Emmanuel Dreyfus <>
List: tech-kern
Date: 09/16/2007 06:31:27
Andrew Doran <> wrote:

> Are there any other potential problems with this?

I see one problem: On Linux, clone() really produces processes, and this
is what we reproduce. NPTL is implemented in the Linux kernel as a layer
on the top of existing kernel code. Kernel PID are shown to userland as
TID, and the PID of the parent process of the thread group is presented
to userland as the PID.

Here are example taken from Linux code. As, in linux/kernel/timer.c:
asmlinkage long sys_gettid(void)
        return current->pid;    
asmlinkage long sys_getpid(void)
        return current->tgid; 

If you grep through the sources, you'll see that tgid is the PID of the
parent process. Example in linux/kernel/fork.c:copy_process()
        p->tgid = p->pid;        
        if (clone_flags & CLONE_THREAD)
                p->tgid = current->tgid;

p is the process structure for the newly created process, current is the

Changing clone() to produce LWP will actually cause the emulated
behaviour to drift away from what Linux does. I'm affraid this will open
a large can of worms. You will have to rewrite our NPTL emulation, and
of course check that no regression occured. I would not want to be in
your shoes :-)

> How would it affect Irix emulation?

I have trouble to tell, I don't remember the odd details of IRIX
threading. However, a quick look to the code shows that COMPAT_IRIX uses
fork1() and not clone().

Emmanuel Dreyfus