RE: [LIP] fork()...

"Sameer Oak" <[email protected]>
Newsgroups gmane.user-groups.linux.india.programmers
Message-ID <[email protected]>
thanks Uday.

> So that you could determine whether you are in the child or the parent
> process.

> if (!fork ()) {
> 	/* this is the code that the child is supposed to run, use getpid to
> get the process id */
> 	/* you would proabably want to exec something here */
> }
> /* parent code runs here */

> At fork a new child process is created with exactly the same process image
> as the parent, now the only way to tell whether you are a child or parent
> process is by examining the return code from fork.
...
this reason is known to me.
i think there're few more.

these are the reasons what i think:
1> fork() returns -1 with errno set to EAGAIN(violating the upper limit of
processes user can create, if UID is not 0)
or ENOMEM(if not sufficient memory for the new process to have it's bss,
text and other data)if it was not successful.
0 or some +ve value are returned if fork() was successful. 0 also indicates
a success as almost all system calls do.
i guess this's one of the reasons.

2> also, the other reason is there're processes with PID starting from 1.
almost all UNIX systems
have 1 for init(some systems have 2 for page-daemon). the scheduler is not
given any no, since it's initially init 0
and after spawning init(what is also known as init 1), it becomes scheduler.
since there's no process with PID 0 existing, 0 can safely be used to
indicate the success status of
the fork() system call along with the PID of the newly created child.

any comments???


*********************************************************
Disclaimer:          

This message (including any attachments) contains 
confidential information intended for a specific 
individual and purpose, and is protected by law. 
If you are not the intended recipient, you should 
delete this message and are hereby notified that 
any disclosure, copying, or distribution of this
message, or the taking of any action based on it, 
is strictly prohibited.

*********************************************************
Visit us at http://www.mahindrabt.com



-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.