If I have a parent coordinator program and a worker program, but the coordinator program is creating all of the needed worker processes. If I want to implement the alarm() method correctly to kill all of the processes and terminate the program after a certain amount of time.
Is this the correct way to implement it? The current way I have it, it does now print out the message corresponding printf() message for the worker processes being killed.
Note: I implemented the ignoring of interrupt signals so more worker processes could proceed without worry.
int main(int argc, char** argv)
{
signal(SIGINT, sig_ctrl);
signal(SIGALRM, sig_alarm);
alarm(5);
sleep(10);
//rest of program which creates the needed processes
}
void sig_ctrl(int sig)
{
printf("Hold on buddy, you're not terminating this program with CTRL^C.\n");
}
void sig_alarm(int sig)
{
sleep(0);
fflush(stdout);
printf("The alarm is sounding, all worker procceses will be...TERMINATED!");
raise(SIGTERM);
}