- 论坛徽章:
- 0
|
一个简单的截获 SIGINT 的程序
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
#include <syslog.h>
void fun_ctrl_c(int signal)
{
syslog (LOG_ALERT, "Hello Ctrl-C, exit.\n");
exit (0);
}
int main(void)
{
daemon (0, 0);
signal (SIGINT, fun_ctrl_c);
syslog (LOG_ALERT, "signal test is running.\n");
while (1)
{
sleep (1);
}
} |
在 root 下直接运行没有问题,killall -2 signal 也能杀掉,syslog 里也有日志记录
但是如果用 apache 的 php 去运行的话,进程中的 signal 不再接收 SIGINT 信号了,这可能是怎么造成的?
PHP 代码如下:
<?php
shell_exec("/tmp/signal");
?> |
|
|