一个简单的signal实例(c语言)


 1 #include <signal.h>
 2 #include <unistd.h>
 3 
 4 
 5 void sig_hander(int signum)
 6 {
 7     printf("catch the signal %d\n",signum);
 8     return ;
 9 }
10 
11 
12 int main(int argc,char **argv)
13 {
14     pid_t pid;
15     pid = getpid();
16     printf("pid[%d]\n",getpid());
17     if(signal(SIGINT,sig_hander)==SIG_ERR)
18     {
19         printf("catch error!\n");
20         return -1;
21     }
22     while(1);
23     return 0;
24 }

执行:

momo@momo:mydev/cc $ a.out
pid[8675]
^Ccatch the signal 2
^Ccatch the signal 2
^Ccatch the signal 2


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM