From: andy dot shellam at mailnetwork dot co dot uk Operating system: Unix (FreeBSD) PHP version: 5.2.1 PHP Bug Type: POSIX related Bug description: proc_get_status - PID is -1 out
Description: ------------ proc_get_status when run with a proc_open'd resource returns a PID that is one less than shown in ps output. E.g. to kill a process opened by proc_open, you need to add 1 to the PID returned by proc_get_status for it to work. This is because proc_get_status returns the PID of the shell that then runs the command - not the command process itself. Reproduce code: --------------- Create a bash script that loops endlessly to simulate a long-running: #!/usr/local/bin/bash while [ 0 -eq 0 ]; do let 0 done In PHP, run this script (from CLI): #!/usr/local/php/bin/php <?php $descriptorspec = array( 0 => array("pipe", "r"), // stdin is a pipe that the child will read from 1 => array("pipe", "w"), // stdout is a pipe that the child will write to 2 => array("file", "/tmp/error-output.txt", "a") // stderr is a file to write to ); $cwd = '/tmp'; $env = array('some_option' => 'aeiou'); $process = proc_open('/tmp/loop.sh', $descriptorspec, $pipes, $cwd, $env, Array("bypass_shell" => TRUE)); if (is_resource($process)) { $procinfo = proc_get_status($process); echo "Opened process ID is: " . $procinfo['pid'] . "\n"; } ?> Expected result: ---------------- Opened process ID is: 40609 (from ps output): [EMAIL PROTECTED] ~]$ sudo ps auxwww|grep loop.sh root 40609 48.2 0.2 3036 1672 p0 R+ 1:06PM 0:05.94 /usr/local/bin/bash /tmp/loop.sh root 40608 0.0 0.1 1632 988 p0 S+ 1:06PM 0:00.00 sh -c /tmp/loop.sh Actual result: -------------- Opened process ID is: 40608 [EMAIL PROTECTED] ~]$ sudo ps auxwww|grep loop.sh root 40609 48.2 0.2 3036 1672 p0 R+ 1:06PM 0:05.94 /usr/local/bin/bash /tmp/loop.sh root 40608 0.0 0.1 1632 988 p0 S+ 1:06PM 0:00.00 sh -c /tmp/loop.sh As you can see, the PID returned by proc_get_info is the shell that is then used to start the actual command - if you kill the shell's PID, the command carries on running. Kill the shell PID+1, and it kills both off. This is similar to http://bugs.php.net/bug.php?id=40070, however the bypass_shell does not work on Unix. -- Edit bug report at http://bugs.php.net/?id=41003&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=41003&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=41003&r=trysnapshot52 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=41003&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=41003&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=41003&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=41003&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=41003&r=needscript Try newer version: http://bugs.php.net/fix.php?id=41003&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=41003&r=support Expected behavior: http://bugs.php.net/fix.php?id=41003&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=41003&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=41003&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=41003&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=41003&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=41003&r=dst IIS Stability: http://bugs.php.net/fix.php?id=41003&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=41003&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=41003&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=41003&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=41003&r=mysqlcfg