2013-03-02 2 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? 

code:Pour gérer les interruptions:

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

entrée par l'utilisateur: doit être une interruption sortie doit être: Pris SIGINT

Répondre

5

Parce que provoque Ctrl-Z un SIGTSTP, pas SIGINT.

+0

Merci ... J'ai perdu beaucoup de temps sur ce .. – shibani

Questions connexes