在php中杀死进程父级

在php中杀死进程父级,php,kill,kill-process,sigkill,Php,Kill,Kill Process,Sigkill,我试图通过杀死进程来停止进程,但为了避免进程僵尸,我必须在杀死pid之前杀死ppid,下面是我杀死pid的代码: $descriptorspec = array(array("pipe", "r"), array("pipe", "w"), array("pipe", "a")); $process = proc_open("MyProcessCommand", $descriptorspec, $pipes); $status = proc_get_status

我试图通过杀死进程来停止进程,但为了避免进程僵尸,我必须在杀死pid之前杀死ppid,下面是我杀死pid的代码:

$descriptorspec = array(array("pipe", "r"), array("pipe", "w"), array("pipe", "a"));
        $process = proc_open("MyProcessCommand", $descriptorspec, $pipes);
        $status = proc_get_status($process);
        $pid = $status['pid'];//Get the process id
{..}

因此,我尝试了这个方法来获取ppid,但似乎效果不好:

$descriptorspec = array(array("pipe", "r"), array("pipe", "w"), array("pipe", "a"));
            $process = proc_open("MyProcessCommand", $descriptorspec, $pipes);
            $status = proc_get_status($process);
            $pid = $status['pid'];//Get the process id
{..}

有没有其他办法获得ppid?或者在不留下任何僵尸进程的情况下终止进程?

使用此选项,它将起作用

    $ppid=shell_exec("ps -o ppid= $pid");
    $int = (int)$ppid;
    var_dump($int);
    shell_exec("exec kill -9 $ppid");
    usleep(300);
    shell_exec("exec kill -9 $pid");

proc\u open()
启动一个shell,并将其第一个参数作为新进程传递给要启动的shell。shell等待已启动进程的终止并退出。你确定如果你杀死了进程,它会变成僵尸吗?Shell通常不会忽略其子对象的终止。是的,请查看
ps axf
8217的结果?S 0:01 \\uUr/usr/sbin/httpd 8437?z0:00 | \[php]8221?S 0:01\\ uU/usr/sbin/httpd 8338?z0:00 | \[php]8290?S 0:01 \\uUr/usr/sbin/httpd
    $descriptorspec = array(array("pipe", "r"), array("pipe", "w"), array("pipe", "a"));

$ppid = proc_open("exec ps -o ppid= $pid", $descriptorspec, $pipes);

         proc_open("exec kill -9 $ppid", $descriptorspec, $pipes);
         proc_open("exec kill -9 $pid", $descriptorspec, $pipes); // killing the pid
                return new JsonResponse('Process Stopped');
    $ppid=shell_exec("ps -o ppid= $pid");
    $int = (int)$ppid;
    var_dump($int);
    shell_exec("exec kill -9 $ppid");
    usleep(300);
    shell_exec("exec kill -9 $pid");