- 论坛徽章:
- 1
|
10可用积分
本帖最后由 sentto2 于 2015-04-29 09:54 编辑
我有如下的小程序,来自于网上:
- #include<sys/types.h>
- #include<sys/stat.h>
- #include<unistd.h>
- #include<fcntl.h>
- #include<stdio.h>
- #include<stdlib.h>
- #include<errno.h>
- #include<string.h>
- #include<signal.h>
- void handler(int sig)
- {
- printf("rev sig=%d\n", sig);
- }
- int main(int argc, char *argv[])
- {
- struct sigaction act;
- act.sa_handler = handler;
- sigemptyset(&act.sa_mask);
- act.sa_flags = 0;
- sigaction(SIGINT, &act, NULL);
- for (; ;)
- pause();
- return 0;
- }
复制代码 我期待的是,程序运行时,我如果发送1号信号给它,那么它调用handler打印一条语句,继续pause,等待我再次发送信号给它,如此循环。
但是实际的运行结果是:
- x@a-VirtualBox:~$ ps -ef|grep a.out
- x 7912 6819 0 18:52 pts/1 00:00:00 ./a.out
- x 7914 7648 0 18:52 pts/17 00:00:00 grep --color=auto a.out
- x@a-VirtualBox:~$ kill -1 7912
复制代码 然后./a.out就退出了。
- x@a-VirtualBox:~$ ./a.out
- Hangup
复制代码 这是为什么呢? 我的理解某个地方有错? |
最佳答案
查看完整内容
SIGINT是Ctrl+C产生的信号,kill -1 不是这样信号吧Linux系统中 kill -1 是 SIGHUP信号
|