2013-03-02 91 views
1
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

回答

5

由于按Ctrl-Z引起SIGTSTP,而不是一个SIGINT

+0

谢谢...我浪费了很多时间在这.. – shibani 2013-03-02 14:10:39