php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #32210 proc_get_status "running"-field true after execution of command
Submitted: 2005-03-07 00:46 UTC Modified: 2005-03-07 17:19 UTC
From: joh at deworks dot net Assigned: wez
Status: Closed Package: Program Execution
PHP Version: 5CVS-2005-03-07 (dev) OS: Linux
Private report: No CVE-ID:
 [2005-03-07 00:46 UTC] joh at deworks dot net
Description:
------------
The "running" field of the status array returned by proc_get_status() is always TRUE after the execution of the command is finished. As the manual says, running should be "TRUE if the process is still running, FALSE if it has terminated". What is strange is that at some point of the command execution, it's false. Maybe it's value is the opposite of what the manual says?

Reproduce code:
---------------
(Best run from the command line)

$handle = proc_open("ls", array(2 => array("pipe", "r")), $pipes);

while (true) {
	$status = proc_get_status($handle); 				var_dump($status["running"]);
	sleep(1);
}

Expected result:
----------------
bool(false)
<output of the command>
bool(true)
bool(false)
bool(false)
...

Actual result:
--------------
bool(true)
<output of the command>
bool(false)
bool(true)
bool(true)
...

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-03-07 02:06 UTC] tony2001@php.net
It really looks that proc_get_status() doesn't take into account the result of waitpid() and still returns TRUE even when child process is already dead.

Wez, take a look at the patch, plz.

Index: proc_open.c
===================================================================
RCS file: /repository/php-src/ext/standard/proc_open.c,v
retrieving revision 1.31
diff -u -p -d -r1.31 proc_open.c
--- proc_open.c 21 Feb 2005 09:50:48 -0000      1.31
+++ proc_open.c 7 Mar 2005 01:04:08 -0000
@@ -414,6 +414,10 @@ PHP_FUNCTION(proc_get_status)
                        stopsig = WSTOPSIG(wstatus);
                }
        }
+       else if (wait_pid == -1) {
+               /* -1 means such child doesn't exist i.e. it already exited */
+               running = 0;
+       }
 #endif

        add_assoc_bool(return_value, "running", running); 
 [2005-03-07 17:19 UTC] iliaa@php.net
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
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Sun Apr 20 13:01:59 2014 UTC