0
這是一個簡化的程序。PHP分叉進程不完全退出併成爲殭屍
test.php是一個守護程序,總是在那裏運行。 它叉進程來處理一些任務。 完成工作後,分叉進程退出。 但分叉進程退出時,它變成殭屍。
如何使分叉進程完全退出而不會變成殭屍?
#!/usr/bin/php
<?php
while (1) {
sleep(1);
$pid = pcntl_fork();
if (!$pid) {
$mypid = getmypid();
sleep(5);
print "pid=$mypid finish work \n";
exit();
}
sleep(1);
} // while
?>
./test.php
... daemon running ...
$ ps -ef | grep mqp
ubuntu 10084 10073 0 12:21 pts/0 00:00:00 /usr/bin/php ./test.php
ubuntu 10085 10073 0 12:21 pts/0 00:00:00 /usr/bin/php ./test.php
ubuntu 10074 10073 0 12:21 pts/0 00:00:00 [test.php] <defunct>
ubuntu 10075 10073 0 12:21 pts/0 00:00:00 [test.php] <defunct>
殭屍成爲這樣的時候,父母不收集死兒童肉。 – DRC 2014-12-05 18:00:48