On Mon, Sep 28, 2009 at 09:09:42PM +0800, ?? ? wrote: > > For example, > > the some thread maked by PT in parent process marked by PP > invoked syscall fork(), cfork() is invoked in the kernel > state which create child process marked by CP, CP's proc > struct(as,p_exec,p_user,klwp_t/kthread pairs) is duplicated by PP's > proc.
To re-write: Some thread (PT) in a process (PP) invoked the "fork" syscall, which causes the kernel function cfork() to be called. This creates a child process (CP), whose state is a duplicate of PP's. > Besides the kernel stack of CP's kthread is equal to the kernel > statck of PT,so CP's current thread is dispatched by cpu to execute > the code after fork() in PT thread code. > > Question:CP has no any user thread(ulwp_t), why not duplicate ulwp_t? > > Is PT's ulwp_t shared by PP and CP? if so, it is not conform > ulwp_t:klwp_t:kthread_t=1:1:1?! I'm not sure exactly what you're asking here. Assuming we're talking about fork1() (which only creates one thread in CP), cfork() will create a single thread (CT) in the child, using the "forklwp()" call, which creates threads and associated LWPs, and duplicates the *userland* thread state from PT. The kernel thread stack is not copied or shared between PT and CT; the CT starts out with an empty stack in lwp_rtt_initial(), an assembly routine which sets up the stack, does some initial dtrace probes, and returns to userland. Does that answer your question? Cheers, - jonathan
