信号的转存,进程的挂起/激活(二)

#include   
#include   

void sig_int(int signo) {
    printf("got signal:%d\n", signo);
}

int main(void) {
    printf("\nprogram start\n");


    sigset_t sig_usr1;

    signal(SIGUSR1, sig_int);
    signal(SIGUSR2, sig_int);

    sigemptyset(&sig_usr1);
    sigaddset(&sig_usr1, SIGUSR1);


    printf("in critical region\n");

    sigsuspend(&sig_usr1); //忽略以前设置,挂起usr1信号,先放行其他,最后放行usr1,恢复以前设置,返回

    printf("out critical region\n");


    printf("program exit\n");
    return 0;
}

运行:

[mofan@localhost Debug]$ ./a.out &
[1] 57657
[mofan@localhost Debug]$
program start
in critical region
[mofan@localhost Debug]$ kill -USR1 57657
[mofan@localhost Debug]$ kill -USR1 57657
[mofan@localhost Debug]$ kill -USR2 57657
got signal:12
got signal:10
out critical region
program exit

转载于:https://www.cnblogs.com/axun/p/6530132.html

你可能感兴趣的:(信号的转存,进程的挂起/激活(二))