php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #39992 proc_terminate() leaves children of child running
Submitted: 2006-12-30 15:52 UTC Modified: 2008-08-12 22:03 UTC
Votes:27
Avg. Score:4.5 ± 0.7
Reproduced:27 of 27 (100.0%)
Same Version:2 (7.4%)
Same OS:17 (63.0%)
From: nlopess@php.net Assigned:
Status: Open Package: Program Execution
PHP Version: 6CVS-2006-12-30 (CVS) OS: linux
Private report: No CVE-ID:
Have you experienced this issue?
Rate the importance of this bug to you:

 [2006-12-30 15:52 UTC] nlopess@php.net
Description:
------------
With the short reproduce code below, PHP fork()s a new process (sh), that itself forks a new one (php). proc_terminate() kill()s the sh process, but the php one doesn't get killed.
I'm not really sure what is causing this problem, but it is breaking run-tests.php on timeout.

Reproduce code:
---------------
<?php

$cmd='php -r "while(1){}" 2>&1';
$proc = proc_open($cmd, array(), $pipes);
var_dump(proc_terminate($proc));

?>


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-12-30 15:54 UTC] nlopess@php.net
Ah I forgot: removing the "2>&1" part everything works fine.
 [2008-08-12 16:28 UTC] jani@php.net
Nuno, is this still valid bug? I can't reproduce it even with PHP 5.2.6..
 [2008-08-12 22:03 UTC] nlopess@php.net
Yes, I'm still able to reproduce it. In some systems you may need higher proviledges in order to reproduce this bug.
 [2010-02-17 08:23 UTC] gryp at dakin dot be
We're having the same problem by starting java.
(the java process starts as root and forks itself to another userid)

the 'sh' gets killed but our java process keeps on running
 [2010-03-13 20:19 UTC] mast at imast dot ru
Well I've also just found this problem.
I run sh script via proc_open and if this script runs child processes that could 
hang, they will not be killed if you run proc_terminate().

To fix it I use:

// As soon proc is started
$status = proc_get_status($proc);
posix_setpgid($status['pid'], $status['pid']);

// When I need to kill it
posix_kill(-$status['pid'], 9); // sends SIGKILL to all processes inside group
proc_close($proc);

Why not to add this into proc_terminate() implementation?
 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Thu Apr 17 18:02:13 2014 UTC