monitor and restart child process
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 > monitor and restart child process




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

    monitor and restart child process  
nadav


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


 
06-13-06 06:23 PM

i have a program that has 2 forked children. i have a couple of
quesitons.

in the main i fork 2 children:

something like:

int main ()
{

pid_t procA;
pid_t procB

if  ( (procA = fork() ) == 0 )
{
run_procA();
}

if  ( (procB = fork() ) == 0 )
{
run_procB();
}

while (1)
{
}

return 0;
}


Question -
1. i use the while(1) in order to keep the parent alive so he can wait
for signal from the children (in case they terminate), i have code for
that.
is their another way i can use rather then this busy wait?

2. i want to restart any child process when he terminates (if he
terminates...) , what is the best way?

i have a signal catcher function that handles signals from the child ,
correntlly it is used to avoid aombie and only wait for SIGINIT , so i
know when they crash.

i am new at this so thank alot for any response.
btw - i write in c.
thanks.






[ Post a follow-up to this message ]



    Re: monitor and restart child process  
Duncan Muirhead


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


 
06-13-06 06:23 PM

On Tue, 13 Jun 2006 07:02:58 -0700, nadav wrote:

> i have a program that has 2 forked children. i have a couple of
> quesitons.
>
> in the main i fork 2 children:
>
> something like:
>
> int main ()
> {
>
> pid_t procA;
> pid_t procB
>
> if  ( (procA = fork() ) == 0 )
> {
>    run_procA();
> }
>
> if  ( (procB = fork() ) == 0 )
> {
>    run_procB();
> }
>
> while (1)
> {
> }
>
> return 0;
> }
>
>
> Question -
> 1. i use the while(1) in order to keep the parent alive so he can wait
> for signal from the children (in case they terminate), i have code for
> that.
> is their another way i can use rather then this busy wait?
>
> 2. i want to restart any child process when he terminates (if he
> terminates...) , what is the best way?
>
> i have a signal catcher function that handles signals from the child ,
> correntlly it is used to avoid aombie and only wait for SIGINIT , so i
> know when they crash.
>
> i am new at this so thank alot for any response.
> btw - i write in c.
> thanks.
try
man 2 wait







[ Post a follow-up to this message ]



    Re: monitor and restart child process  
SM Ryan


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


 
06-14-06 06:28 AM

# Question -
# 1. i use the while(1) in order to keep the parent alive so he can wait
# for signal from the children (in case they terminate), i have code for
# that.
# is their another way i can use rather then this busy wait?

Use a blocking wait().

# 2. i want to restart any child process when he terminates (if he
# terminates...) , what is the best way?

You can do something like
pid_t procA = -1,procB = -1;
for (;;) {
if (procA<0) {
procA = fork();
if (procA<0) perror...
else if (procA==0) ...
}
if (procB<0) {
procB = fork();
if (procB<0) perror...
else if (procB==0) ...
}
int s; pid_t w = wait(&s);
if (w==procA) {
reportStatus("A",s);
procA = -1;
}else if (w==procB) {
reportStatus("B",s);
procB = -1;
}else (w<0 && errno!=EINTR) perror...
}

# i have a signal catcher function that handles signals from the child ,
# correntlly it is used to avoid aombie and only wait for SIGINIT , so i
# know when they crash.

Catching SIGCHLD is not what releases the child process, its the wait
that captures the final status that sends the child to its final reward,
the great bit dump in the sky.

--
SM Ryan http://www.rawbw.com/~wyrmwif/
There are subtler ways of badgering a witness.





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 12:34 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