Issue 6: Process::kil() not killing service process properly
Status:  Accepted
Owner: ----
Reported by mikey...@gmail.com, Aug 28, 2009
What steps will reproduce the problem?
1. sending a message
2. waiting for the PushMonitor to kill the service process
 

What is the expected output? What do you see instead?
Expect the service process to be killed, instead app just hangs


What version of the product are you using? On what operating system?
Debian 

Please provide any additional information below.

I suspect the code in process::kill() which seems to have been copied from the PHP docs doesn't get the child process IDs from the 
parent PID correctly.

The line :

$pids = preg_split('/\s+/', `ps -o pid --no-heading --ppid $ppid`);

makes no sense to me as the preg split should surely be on the output of the command 'ps -o pid --no-heading --ppid $ppid' not the 
command line itself.

Is there a reason we need to find child PIDs? From what I can see the PushService.php file doesnt open any child processes.

Ive replaced the function with the following code which works for me:

	public function kill()
	{
		global $debug;
		
		$status = proc_get_status($this->pointer);
		
		print_r($status);
		
		if($status['running'])
		{
			if($debug)
				echo 'proc is running...closing pipes.';
				
			fclose($this->pipes[0]);
			fclose($this->pipes[1]);
			fclose($this->pipes[2]);
						
			$ppid = $status['pid'];			
			
			proc_terminate($this->pointer);

			return (proc_close($this->pointer) == 0);
		}
         }


I'm not sure if I need the proc_close condition on return.



Aug 31, 2009
Project Member #1 alessand...@gmail.com
Actually, that piece of code has always been problematic. In some systems, it is working perfectly (as it is in my 
Debian Lenny server); however, some other Debian servers too are having problems (and they have solved the 
problem by using --ppid instead of -pid).
The reasons of this are still unknown.

I'm going to try your solution, and see if this makes some things better.
Status: Accepted
Sep 10, 2009
#2 vincent....@gmail.com
I was experiencing similar issues as mikeytrw on Centos 5.3 server, and wanted to confirm if child process 
from the parent(PushMonitor needed killing). It turns out that it's managed fine, and you dont need to kill all 
child processes that belong to the parent, since only one happens at a time. 

I stuck in the code fragment before i sent a message to see what child id's there are and forced it to fail by 
choosing an invalid server ip for the client.  it found the one child process and the ps command to find the 
process.  
                $moo = getmypid(); //get parent pid (PushMonitor.php)
                $pids = preg_split('/\s+/', `ps -F --ppid $moo`); //confirm what ps pulled up
                print_r($pids);


and i guess one modification on mikeytrw's code that i would put is 

replace:
proc_terminate($this->pointer);

with:

                        if(!proc_terminate($this->pointer)){
                          posix_kill($ppid, 9); //if it cannot terminate pointer,kill 9
                        }

i guess just incase it can't terminate for whatever reason, it can still kill the process. someone can correct me 
if this is redundant.