sigaction函数嵌套处理信号简单介绍

#include 
#include 
#include 

int temp = 0;

void handler_sigint(int signo)
{
    printf("receive signal!\n");
    sleep(3);
    temp += 2;
    printf("the value of temp is: %d!\n",temp);
    printf("in handler_sigint,after a sleep!\n");
}

int main()
{
    struct sigaction act;
    
    act.sa_handler = handler_sigint;
    act.sa_flags = SA_NOMASK;
   
    sigaction(SIGINT, &act, NULL);

    while(1)
    {
        printf("looping now!\n");
        sleep(3);
    }
    
    return 0;
}

你可能感兴趣的:(Linux)