发送多个SIGUSR1 / SIGUSR2信号

时间:2015-04-22 18:09:16

标签: c unix ubuntu signals

我有以下C文件:parent&儿童。父对子进行分叉,并向子进程发送多个SIGUSR1 / SIGUSR2,子进程接收它们并打印输出。

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;
}

问题是在接收器中我只得到一个SIGUSR1和SIGUSR2,无论我在父母中发送了多少次杀戮。所以样本输出是:

Received SIGNAL2
Received SIGNAL1

而不是4个条目,我只有2个。

任何想法为什么?

0 个答案:

没有答案