kill 被 "system" 调用吸收并且永远不会触发 pcntl_signal
kill is absorbed by "system" call and never triggers pcntl_signal
我有一个守护程序脚本,我试图通过避免线程来保持简单。
当我按 ctrl-c 或 kill pid 时,"system" 调用退出,但不调用 exitFunction。
declare(ticks = 100);
function exitFunction($signo) {
global $pidFile, $exit;
unlink($pidFile);
echo "Daemon is exiting (signal: $signo). Removing pidFile: $pidFile\n";
$exit = true;
};
//create the signal handler and shutdown function
pcntl_signal(SIGINT, "exitFunction");
pcntl_signal(SIGTERM, "exitFunction");
//create the pid file with our command
file_put_contents($pidFile, posix_getpid());
echo "pid: " . posix_getpid() . "\n";
echo "Time to start!\n";
while(!$exit) {
echo "running $command...\n";
system($command, $return);
echo "done $command\n";
if($return) {
echo "didn't find any domains with command, so sleeping for 60...\n";
sleep(60);
}
}
您需要将 declare(ticks=1);
添加为脚本的第一行。可以在 here.
中找到关于实际报价的更详细解释。
我有一个守护程序脚本,我试图通过避免线程来保持简单。
当我按 ctrl-c 或 kill pid 时,"system" 调用退出,但不调用 exitFunction。
declare(ticks = 100);
function exitFunction($signo) {
global $pidFile, $exit;
unlink($pidFile);
echo "Daemon is exiting (signal: $signo). Removing pidFile: $pidFile\n";
$exit = true;
};
//create the signal handler and shutdown function
pcntl_signal(SIGINT, "exitFunction");
pcntl_signal(SIGTERM, "exitFunction");
//create the pid file with our command
file_put_contents($pidFile, posix_getpid());
echo "pid: " . posix_getpid() . "\n";
echo "Time to start!\n";
while(!$exit) {
echo "running $command...\n";
system($command, $return);
echo "done $command\n";
if($return) {
echo "didn't find any domains with command, so sleeping for 60...\n";
sleep(60);
}
}
您需要将 declare(ticks=1);
添加为脚本的第一行。可以在 here.