#define CHILD_GID 1000
void parentHandler(int sig) {
//send SIGHUP to all members of CHILD_GID
killpg(CHILD_GID, SIGHUP);
}
void childHandler(int sig) {
printf("SIGHUP received\n");
exit(0);
}
int main(void) {
//lots of code before this
//set hte parent''s signal handler
signal(SIGINT, parentHandler);
//spawn 3 children
for(int i = 0; i < 3; i++) {
if(fork() == 0) {
//set the group gid for the child
setgid(CHILD_GID);
//set the child''s signal handler
signal(SIGHUP, childHandler);
}
}
//other code follows
Killing all Children
In my program, I''m when SIGINT is received by the parent, all the children will be killed (by sending them a SIGHUP), but the parent remains.
Now, how I''m currently doing this is calling setgid when I create each of the child processes, and then calling signal in the parent and child threads, providing their own respective signal functions.
The problem I''m having is, that I can get the parent to process to send a signal to the child processes. Am I completely misunderstanding the use of setgid and signal?
==========================================In a team, you either lead, follow or GET OUT OF THE WAY.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement