hi Lal,
thanks for the analysis and clearing the doubt. so, parent process returns while child is added in to runqueue. right?
Regards,
mitul modi
thanks for the analysis and clearing the doubt. so, parent process returns while child is added in to runqueue. right?
Regards,
mitul modi
On Sun, Oct 5, 2008 at 1:55 PM, Lal <learner.kernel@xxxxxxxxx> wrote:
> On Wed, Oct 1, 2008 at 6:12 PM, srimugunthan dhandapaniThe parent process and child process get their return values
> <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.
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