|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #39322 proc_terminate(): loosing process resource
Submitted: 2006-10-31 16:22 UTC Modified: 2007-02-14 19:22 UTC
Avg. Score:5.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:1 (50.0%)
From: c dot affolter at stepping-stone dot ch Assigned:
Status: Closed Package: Program Execution
PHP Version: * OS: *
Private report: No CVE-ID:
 [2006-10-31 16:22 UTC] c dot affolter at stepping-stone dot ch
After sending a signal via proc_terminate() to a process, the process resource gets closed immediately.
This means that calling proc_get_status() afterwards, will throw a warning about an invalid process resource.

This behaviour is somewhat cumbersomely, since you're unable to check if it was your signal which has caused the process to terminate or if the process has stopped.

Is this a bug or an undocumented behaviour?

Sending a signal via the shell or through posix_kill(), will retain the status for the first proc_get_status() call. 

Reproduce code:
$descriptors = array(
    0 => array('pipe', 'r'),
    1 => array('pipe', 'w'),
    2 => array('pipe', 'w'));

$pipes = array();

$process = proc_open('/bin/sleep 120', $descriptors, $pipes);



Expected result:
array(8) {
  string(14) "/bin/sleep 120"

Actual result:
Warning: proc_get_status(): 7 is not a valid process resource in ...


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2006-11-08 14:55 UTC]
Reclassified as docu problem.
 [2007-01-23 22:18 UTC] viraptor+phpbug at gmail dot com
I'd rather like to see proc_terminate act like documented:

"proc_terminate() allows you terminate the process and continue with other tasks. You may poll the process (to see if it has stopped yet) by using the proc_get_status() function."

If a known workaround is to send posix_kill, which does... exactly what proc_terminate is supposed to do, why not implement proc_terminate as:

stat = proc_get_status(proc);
if(stat['running']) posix_kill(stat['pid'], sig);

+ update the $proc options as needed. That would be much more useful.
Additionaly not every signal actually kills process, so resource should not be destroyed after SIGTERM.
Please correct code, not docs.
 [2007-01-23 22:26 UTC]
I agree proc_terminate() shouldn't destruct the resource (I also come across theis problem myself..)
 [2007-02-14 19:22 UTC]
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
Thank you for the report, and for helping us make PHP better.

 [2011-09-07 18:09 UTC]
Automatic comment from SVN on behalf of rasmus
Log: This test was added to verify that bug 39322 was fixed, which the test
does test for and this works. However, it consistently failed because
it relied on a SIGHUP not terminating a sh -c /usr/bin/nohup sleep 50
process which doesn't work because the SIGHUP goes to the sh process
not the nohup'ed sleep process. So, I have sped up the test and removed
the nohup and instead of trying to SIGHUP I am just doing the equivalent
of a kill 0 on it to verify that the resource sticks around.
PHP Copyright © 2001-2015 The PHP Group
All rights reserved.
Last updated: Tue Oct 06 14:01:33 2015 UTC