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 ]
|