hi
i m writin a program in which i keep track of all the child processes the program has generated and if a child process has an abnormal termination i need to do certain task related to that child process.
for handlin child process i used waitpid:
temp_cpid=waitpid(-1,&stat,WUNTRACED);
during normal termination temp_cpid return the pid of the terminated child process but in case of abnormal termination it returns -1 so hoe to determine the pid of the abnormally terminated process?
ny help will b appreciated
thanx
The macro
WIFSIGNALED(stat)
will return the signal the child process handled.
Hi,
Thanks for the ftp C reply,
May be you could try this to track all the child process
#include<signal.h>
static void handle_child_process(int sig)
{
/* this will print all the child proccess status code termination values */
int stat;
printf("%d",wait(&stat));
}
int main()
{
struct sigaction child_signal;
memset(&chld_signal, 0, sizeof(struct sigaction));
child_signal.sa_handler = &handle_child_process;
sigaction(SIGCHLD, &child_signal, 0);
/*
your
code
here
wahtever
it is
*/
exit(EXIT_SUCCESS);
}
/*
do something like this
*/
Hi Mridula,
basically SIGCHLD is the signal that is generated as a result of termination of the child process. so you should bt looking to handle that
i got this nice info after some google.
http://www.wlug.org.nz/SIGCHLD
not sure if it applies to your ux version. but good info tho
i am afraid that the above statement would print
only the PIDS of the child process that are terminated and not the exit status of the child process.
int stat;
printf("%d",wait(&stat));
printf("%d",stat);