Bug #39992 [Com]: proc_terminate() leaves children of child running
| From: | php at mattwhitlock dot name | Date: | Sun, 06 Mar 2016 02:30:02 +0000 |
| Subject: | Bug #39992 [Com]: proc_terminate() leaves children of child running | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-199617@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=39992&edit=1
ID: 39992
Comment by: php at mattwhitlock dot name
Reported by: nlopess@php.net
Summary: proc_terminate() leaves children of child running
Status: Open
Type: Bug
Package: Program Execution
Operating System: linux
PHP Version: 6CVS-2006-12-30 (CVS)
Block user comment: N
Private report: N
New Comment:
An easy workaround...
Instead of:
$proc = proc_open('cat', ...);
Use this:
$proc = proc_open('exec cat', ...);
It tells the shell to replace its own process with the command being executed rather than forking a
child process. This way you can properly kill the command using proc_terminate($proc).
Previous Comments:
------------------------------------------------------------------------
[2014-10-17 12:12:52] alanevans+phpnet at gmail dot com
I've happened on this same issue also, though I also find that proc_get_status returns only the
pid of some /bin/sh wrapper.
I've tried on PHP 5.5 and 5.6,
Interesting to note is that the behaviour on OSX is quite easy to handle: there is no /bin/sh
wrapper process at all in that case, but on Ubuntu (currently tested on lucid), you only ever have
access to the /bin/sh proc: the process you actually started and the one that you care about is left
running.
I'm going to work around this by having child processes write their own pids to a file and use
those for signalling.
------------------------------------------------------------------------
[2010-03-13 20:19:57] 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?
------------------------------------------------------------------------
[2010-02-17 08:23:48] 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
------------------------------------------------------------------------
[2008-08-12 22:03:45] 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.
------------------------------------------------------------------------
[2008-08-12 16:28:58] jani@php.net
Nuno, is this still valid bug? I can't reproduce it even with PHP 5.2.6..
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=39992
--
Edit this bug report at https://bugs.php.net/bug.php?id=39992&edit=1