# include <stdio. h> # include <signal.h> # define INPUTLEN 100 void inthandler(); int main()
{ struct sigaction newhandler; sigset_t blocked; char x[INPUTLEN]; newhandler.sa_handler=inthandler; newhandler.sa_flags=SA_RESETHAND|SA_RESTART; sigemptyset(&blocked); sigaddset(&blocked,SIGQUIT); newhandler.sa_mask=blocked; if( sigaction( SIG1NT, &newhandler, NULL) = = - 1 ) perror("sigaction"); else whileC 1 ) { fgets(x,INLUTLEN,stdin); printf("input:%s",x); }
} void inthandler( int s) { printf( "Called with signal 屯 d\n飞的 J sleep(s); printf("done handling signal %d\n",s); }
原文:https://www.cnblogs.com/cs0915/p/13056704.html