Re: how fork returns value | |
| [Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] | |
> 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
[Newbies FAQ] [Kernel List] [Site Home] [IETF Annouce] [Git] [Networking] [Security] [Bugtraq] [Rubini] [Photo] [Yosemite] [MIPS Linux] [ARM Linux] [Linux Security] [Linux Networking] [Linux RAID] [Linux SCSI] [Linux ACPI] [DDR & Rambus] [UNIX Filesystems] [Linux Resources]
![]() |
![]() |