C signals and processes
Posted
by Gary
on Stack Overflow
See other posts from Stack Overflow
or by Gary
Published on 2010-04-23T12:31:02Z
Indexed on
2010/04/23
12:33 UTC
Read the original article
Hit count: 419
Hi, so basically I want "cmd_limit" to take a number in seconds which is the maximum time we'll wait for the child process (safe to assume there's only one) to finish. If the child process does finish during the sleep, I want cmd_limit to return pass and not run the rest of the cmd_limit code. Could anyone help me do this, here's what I've got so far..
int cmd_limit( int limit, int pid ) {
signal( SIGCHLD, child_died );
sleep( limit );
kill( pid, SIGKILL );
printf("killin'\n");
return PASS;
}
void child_died( int sig ) {
int stat_loc; /* child return information */
int status; /* child return status */
waitpid( -1, &stat_loc, WNOHANG );
if( WIFEXITED(stat_loc) ) { // program exited normally
status = WEXITSTATUS( stat_loc ); /* get child exit status */
}
printf("child died: %s\n", signal);
}
© Stack Overflow or respective owner