Re: when parent process keeps forking child but doesnot wait...
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > Re: when parent process keeps forking child but doesnot wait...




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    Re: when parent process keeps forking child but doesnot wait...  
Hubble


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
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 ]



    Sponsored Links  




 





   All times are GMT. The time now is 06:12 PM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register