04-24-07 06:20 AM
On 24 Apr., 06:16, djh...@gmail.com wrote:
> In my case, parent receives a request and forks itself and lets the
> child perform a task.
> But parent doesnot wait for child to complete and exit.
> This kind of behavior is normal ,right?
>
> But, when I ps , looks like it displays all those completed and
> exited child processes-->which is bothering me. Do I need to worry
> about it?
Yes. The Zombie Processes (state Z) occupy space in the process table.
The easiest way to solve this is to use double forking:
pid1=fork();
if (pid1==0) { /* son */
pid2=fork();
if (pid2==0) /* son of son */
{ do_work();
_exit(0);
}
/* son */
_exit(0);
}
/* parent, error checking pid<0 */
wait(&status);
Here, parent can wait since its son exists immediately after creating
his own son. Init process takes care of sons son after son has exited.
Hubble.
[ Post a follow-up to this message ]
|