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);
}