处理中断:

时间:2013-03-02 14:05:46

标签: c

In the following program:

Ctrl+z and ctrl+c both are interrupts.
The code is supposed to handle any interrupt.


Then why does only one of them(ctrl+c) work?

代码:

#include <signal.h>
#include<stdio.h>
void handler(int sig)
{
    printf("Caught SIGINT\n");
    exit(0);
}

int main() 
{
    printf("\nYou can press ctrl+c to test this program\n");
    if (signal(SIGINT, handler) == SIG_ERR) 
    perror("signal error");

    pause(); /* wait for the receipt of a signal */

    exit(0);
}

用户输入:必须是中断 输出必须是:抓住sigint

2 个答案:

答案 0 :(得分:7)

因为Ctrl-Z会导致SIGTSTP,而不是SIGINT

答案 1 :(得分:4)