Re: how fork returns value

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

On Sun, Oct 5, 2008 at 1:55 PM, Lal <learner.kernel@xxxxxxxxx> wrote:
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


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux