Re: Multiple forks get re-executedby PrakashK (Pilgrim)
|on Jul 10, 2001 at 00:18 UTC||Need Help??|
You must explicitly terminate the child process that fork
created, once it's job is done. Otherwise, it continues to
In your pseudo-code, the code after fork is executed by both the parent and the child. If you want only one of them to do "stuff" (usually child -- that's why you forked, right?), you must explicitly check the return code of fork to determine the identity of the process and assign "work" to it.
fork returns the pid of the child process to the parent, and returns 0 to the child process.
Please see below:
In practice, you should check for possible errors in the fork call. Please see the camel book for an example (p. 715 in 3rd edition).