首页 > 编程语言 > 详细

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

时间:2017-10-30 16:45:26      阅读:284      评论:0      收藏:0      [点我收藏+]
 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

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

原文:http://www.cnblogs.com/chenanan/p/7754922.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!