php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #35169 proc_get_status lost exitcode after second call
Submitted: 2005-11-09 11:18 UTC Modified: 2005-11-29 15:57 UTC
From: c dot affolter at stepping-stone dot ch Assigned: wez (profile)
Status: Closed Package: Documentation problem
PHP Version: 5.1.0RC4 OS: Linux version 2.4.21
Private report: No CVE-ID: None
 [2005-11-09 11:18 UTC] c dot affolter at stepping-stone dot ch
Description:
------------
After a process (via proc_open()) has exited, proc_get_status() returns the actual exit code (within array['exitcode']) of that process.

If proc_get_status() gets called a second time, the previous exit code will be lost (-1), because the internal waitpid() function won't return the pid a second time.

So, either this is a bug and proc_get_status() has to keep track of the exitcode value (as it does for 'command', 'pid' and 'running') or this behaviour should be mentioned in the documentation.

Reproduce code:
---------------
#!/usr/bin/env php
<?php
$descriptors = array(
    0 => array('pipe', 'r'),
    1 => array('pipe', 'w'),
    2 => array('pipe', 'w'));

$pipes = array();
$ressource = proc_open('/bin/true', $descriptors, $pipes);
echo stream_get_contents($pipes[1]);

// first call exitcode == 0
var_dump(proc_get_status($ressource));

// second call exitcode == -1
var_dump(proc_get_status($ressource));

fclose($pipes[1]);
proc_close($ressource);
?>

Expected result:
----------------
array(8) {
  ["command"]=>
  string(9) "/bin/true"
  ["pid"]=>
  int(31590)
  ["running"]=>
  bool(false)
  ["signaled"]=>
  bool(false)
  ["stopped"]=>
  bool(false)
  ["exitcode"]=>
  int(0)
  ["termsig"]=>
  int(0)
  ["stopsig"]=>
  int(0)
}
array(8) {
  ["command"]=>
  string(9) "/bin/true"
  ["pid"]=>
  int(31590)
  ["running"]=>
  bool(false)
  ["signaled"]=>
  bool(false)
  ["stopped"]=>
  bool(false)
  ["exitcode"]=>
  int(0)
  ["termsig"]=>
  int(0)
  ["stopsig"]=>
  int(0)
}

Actual result:
--------------
array(8) {
  ["command"]=>
  string(9) "/bin/true"
  ["pid"]=>
  int(31590)
  ["running"]=>
  bool(false)
  ["signaled"]=>
  bool(false)
  ["stopped"]=>
  bool(false)
  ["exitcode"]=>
  int(0)
  ["termsig"]=>
  int(0)
  ["stopsig"]=>
  int(0)
}
array(8) {
  ["command"]=>
  string(9) "/bin/true"
  ["pid"]=>
  int(31590)
  ["running"]=>
  bool(false)
  ["signaled"]=>
  bool(false)
  ["stopped"]=>
  bool(false)
  ["exitcode"]=>
  int(-1)
  ["termsig"]=>
  int(0)
  ["stopsig"]=>
  int(0)
}

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-11-09 12:53 UTC] sniper@php.net
Wez, how is it? Bug or undocumented behaviour?
 [2005-11-10 19:52 UTC] iliaa@php.net
This is a not a bug, but an undocumented behaviour.
 [2005-11-29 15:57 UTC] vrana@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.

Only first call of this function return real value, next calls return -1.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon Jul 07 05:01:36 2025 UTC