c - Sending multiple SIGUSR1/SIGUSR2 signals -
i have following c files: parent & child. parent forks child, , sends multiple sigusr1/sigusr2 child, child receives them , prints output.
receiver.c:
void start_signalset(); void wypisz(int signo) { if (signo == sigusr1) printf("received signal1\n"); if (signo == sigusr2) printf("received signal2\n") start_signalset(); } void start_signalset() { if(signal(sigusr2, wypisz) == sig_err) { exit(0); } if(signal(sigusr1, wypisz) == sig_err) { exit(0); } } int main(int argc, char ** argv) { start_signalset(); while(is_active) { sigset_t pusty; sigemptyset(&pusty); sigsuspend(&pusty); } return 0; }
parent.c:
int main(int argc, char ** argv) { sigset_t nowy, stary; sigaddset(&nowy, sigusr1); sigaddset(&nowy, sigusr2); sigprocmask(sig_block, &nowy, &stary); pid_t pid; if((pid = fork()) == -1) {//error handling } else if(pid == 0) if(execlp("./receiver", "receiver", null) == -1) _exit(7); kill(pid, sigusr1); kill(pid, sigusr1); kill(pid, sigusr1); kill(pid, sigusr2); return 0; }
the problem in receiver 1 sigusr1 , sigusr2, no matter how many kills sent in parent. sample output is:
received signal2 received signal1
instead of 4 entries, have 2.
any ideas why?
Comments
Post a Comment