Hello Again,
I've found a problem today with this implemantation. My program dies allways after 108 seconds. I've done this:
At main():
Code:
struct sigaction act;
/* Assign sig_chld as our SIGCHLD handler */
act.sa_handler = sig_chld;
/* We don't want to block any other signals */
sigemptyset(&act.sa_mask);
/* We're only interested in children that have terminated */
act.sa_flags = SA_NOCLDSTOP;
Inside for(; at main():
Code:
/* sleep */
usleep(100000); //100ms
/* Make these values effective. */
if (sigaction(SIGCHLD, &act, NULL) < 0) {
fprintf(stderr, "sigaction failed\n");
return 0;
}
function:
Code:
/*
* The signal handler function -- only gets called when a SIGCHLD
* is received, ie when a child terminates
*/
void sig_chld(int signo)
{
int status, child_val;
/* Wait for any child without blocking */
if (waitpid(-1, &status, WNOHANG) < 0)
{
/*
* calling standard I/O functions like fprintf() in a
* signal handler is not recommended.
*/
//fprintf(stderr, "waitpid failed\n"); //only for DEBUG
return;
}
/*
* We now have the info in 'status' and can manipulate it using
* the macros in wait.h.
*/
if (WIFEXITED(status)) /* did child exit normally? */
{
child_val = WEXITSTATUS(status); /* get child's exit status */
printf("child's exited normally with status %d\n", child_val);
}
}
I've done some debuging but didn't found anything logical !
Any help ?
Thanks,