为什么我的父进程不等待其子进程完成执行?
我有最基本的脚本:
$pid = pcntl_fork();
if ($pid == -1) {
die('could not fork');
} else if ($pid) {
// we are the parent
echo "parent done";
pcntl_wait($status); //Protect against Zombie children
echo "all done";
} else {
// we are the child
echo "Child finished";
}
当我运行这个脚本时,输出始终是“Child finish”。我在 lighttpd 服务器上运行它。
I have the most basic script:
$pid = pcntl_fork();
if ($pid == -1) {
die('could not fork');
} else if ($pid) {
// we are the parent
echo "parent done";
pcntl_wait($status); //Protect against Zombie children
echo "all done";
} else {
// we are the child
echo "Child finished";
}
When I run this, the output is always "Child finished". I'm running this on a lighttpd server.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可能是您从孩子那里收到信号,但它不是退出状态,请尝试以下操作:
确保状态是退出状态(SIGCHILD)。
Could be that your getting a signal from the child but it's not the exit status try some thing like:
To make sure the status is the exit one (SIGCHILD).