标签:
1 #include<stdio.h> 2 #include<signal.h> 3 void SignHandler(int iSignNum) 4 { 5 printf("\nCapture signal number is:%d\n",iSignNum); 6 } 7 int main(void) 8 { 9 int i; 10 signal(SIGINT,SignHandler); 11 while(1) 12 { 13 for(i=0;i<10;i++) 14 { 15 printf("%d\n",i); 16 sleep(1); 17 } 18 19 } 20 return 0; 21 }
程序运行结果如下
1 0 2 1 3 2 4 3 5 4 6 5 7 6 8 7 9 8 10 9 11 0 12 1 13 2 14 3 15 4 16 5 17 6 18 7 19 8 20 ^C 21 Capture signal number is:2 22 9 23 0 24 1 25 2 26 3 27 ^C 28 Capture signal number is:2 29 4 30 5 31 6 32 7 33 8 34 9 35 0 36 1 37 ^C 38 Capture signal number is:2 39 2 40 3 41 4 42 5 43 6 44 7 45 8 46 9 47 0 48 1 49 2 50 3 51 ^C 52 Capture signal number is:2 53 4 54 5 55 6 56 7 57 8 58 9 59 0 60 1 61 2 62 3 63 ^\Quit (core dumped)
充分说明了信号相当于另外一个进程?它和主进程不中断
标签:
原文地址:http://www.cnblogs.com/wireless-dragon/p/5181116.html