drvpv7995 2013-10-23 15:55 采纳率: 100%
浏览 52
已采纳

来自pcnt​​l_fork的进程没有终止

I am running a web service which involved with daemons by php+apache2. So I tried pcntl_fork function. But there is a question that the child process are not terminating even I used exit(0) in the child process's code which result in a lot of apache2 processes.

I'm wondering if there is a way to shutdown those useless apache2 processes?

PS: because I'm not very aware of the mechanism of signal, so I tried to make daemon by a single call to a agent script which will exit as soon as the child is created.

switch ($_GET['action']){
    case "new":
        $pid = pcntl_fork();
        switch ($pid){
            case -1: 
                echo "failed to create daemon";
                exit;
            case 0:
                //Code here
                exit(0);
                break;
            default:
                echo "Daemon PID:$pid";
        }
}

And I'm planning to use a file to control the daemon. For example I will append a line like "exit" to the daemon's control file such as "1.txt" to let it shutdown itself.

PPS: After reading this topic: pcntl_fork() results in defunct parent process, I'm curious about that if the zombie process bug caused the bug.

  • 写回答

1条回答 默认 最新

  • duangai1368 2013-10-23 16:03
    关注

    You should have to use this function:

    http://php.net/manual/en/function.pcntl-wait.php

    But generally under Apache forking is probably not a good idea.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型
  • ¥50 buildozer打包kivy app失败
  • ¥30 在vs2022里运行python代码
  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题