On Thu, Oct 2, 2008 at 3:55 PM, Mitul Modi <mituld.modi@xxxxxxxxx> wrote: > > > On Wed, Oct 1, 2008 at 6:12 PM, srimugunthan dhandapani > <muggy.mit@xxxxxxxxx> wrote: >> >> hi all, >> I want to understand how the fork call return 0 in child and 'pid of >> child' in the parent. >> Presently my (naive)understanding is that the %eax value is stored >> differently for the child and the parent. >> Both the child and the parent returns from fork to the same instruction >> address, but will have different return values according to %eax. The parent process and child process get their return values differently. As Peter Teoh explained, kernel writes the child process's pid directly to parent process user space pointer. In function copy_process if (clone_flags & CLONE_PARENT_SETTID) if (put_user(p->pid, parent_tidptr)) While child process gets return value from %eax. In function copy_thread childregs = task_pt_regs(p); *childregs = *regs; childregs->eax = 0; childregs->esp = esp; Therefore, after fork system call in application, parent process returns with child process' pid while child process returns with 0. -Lal -- To unsubscribe from this list: send an email with "unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx Please read the FAQ at http://kernelnewbies.org/FAQ