In the main function I created a "sigaction sigact" which connects to a handler, and I removed the SIGUSR1 signal from the blocked sigact.sa_mask set. The SIGUSR1 is the signal I want to get twice from TWO children before going further. How do I wait for both the children process to get the SIGUSR1 signals from?
void handler(...){...}
int main()
{
int pipe1[2];
int pipe2[2];
char buf;
struct sigaction sigact;
sigact.sa_handler = handler;
sigfillset(&sigact.sa_mask);
sigact.sa_flags = 0;
sigdelset(&sigact.sa_mask,SIGUSR1);
sigaction(SIGUSR1,&sigact,NULL);
pid = fork();
if(pid == 0){
...
sleep(3); // the sleep is just a must-have of the homework
kill(getppid(),SIGUSR1); // CHILD1
...
}else{
pid1 = fork();
if(pid1 == 0){
...
sleep(3);
kill(getppid(),SIGUSR1); // CHILD2
...
}else{
...
sigsuspend(&sigact.sa_mask); // PARENT
sigsuspend(&sigact.sa_mask); // WAIT FOR SIGUSR1 FROM CHILD1 AND
... // CHILD2 BEFORE GOING FURTHER
... // (The two sigsuspends were my best idea,
... // doesn't work)
// DO OTHER THINGS AFTER TWO SIGNALS CAME
// (e.g. sending children data with pipes,
// just homework stuff...)
}
}
return 0;
}
As You can see I'm trying with two sigsuspends but they won't work, it waits forever. It would work by using only one sigsuspend but I need feedback from both children.
How do you wait for 2 signals?