I'm trying to stop a process by killing it, but to avoid the process zombies I must kill the ppid before killing the pid, here is my code to kill the 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
{..}
$descriptorspec = array(array("pipe", "r"), array("pipe", "w"), array("pipe", "a"));
proc_open("exec kill -9 $pid", $descriptorspec, $pipes); // killing the pid
return new JsonResponse('Process Stopped');
So, I tried this one to get the ppid, but it seems not working well :
$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
{..}
$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');
Is there any other way to get the ppid? or to kill the process without leaving any zombie process?