码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2017-10-30 17:04:05      阅读:125      评论:0      收藏:0      [点我收藏+]

标签:c语言   ^c   erro   ror   code   tpi   argc   hand   gnu   

 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语言)

标签:c语言   ^c   erro   ror   code   tpi   argc   hand   gnu   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!