php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #47763 proc_get_status->wrong PID
Submitted: 2009-03-24 15:44 UTC Modified: 2009-03-25 16:24 UTC
From: ies_clan at hotmail dot com Assigned:
Status: Not a bug Package: Filesystem function related
PHP Version: 5.2.9 OS: Windows XP SP3
Private report: No CVE-ID: None
 [2009-03-24 15:44 UTC] ies_clan at hotmail dot com
Description:
------------
The function proc_get_status returns a wrong PID

Reproduce code:
---------------
<?php
$cmd = 'notepad';
$descriptorspec = array( 0 => array('pipe', 'r' ), 1 => array('pipe', 'w' ), 2 => array('pipe', 'w' ) );
$process = proc_open($cmd, $descriptorspec, $pipes);
$status = proc_get_status( $process );
echo 'PID = ', $status['pid'], "\n";
passthru( 'tasklist /fi "imagename eq notepad.exe"');
echo "\n\n";
passthru( 'tasklist /fi "pid eq ' . $status['pid'] . '"' );
echo "\n\n";
proc_terminate($process);
?>


Expected result:
----------------
PID = 2408

Abbildname                  PID Sitzungsname      Sitz.-Nr. Speichernutzung
========================= ===== ================ ========== ===============
notepad.exe                2408 Console                   0         2.560 K



Abbildname                  PID Sitzungsname      Sitz.-Nr. Speichernutzung
========================= ===== ================ ========== ===============
cmd.exe                    2336 Console                   0         2.560 K




Actual result:
--------------
PID = 2336

Abbildname                  PID Sitzungsname      Sitz.-Nr. Speichernutzung
========================= ===== ================ ========== ===============
notepad.exe                2408 Console                   0         2.560 K



Abbildname                  PID Sitzungsname      Sitz.-Nr. Speichernutzung
========================= ===== ================ ========== ===============
cmd.exe                    2336 Console                   0         2.560 K




Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-03-25 16:24 UTC] mattwil@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

That's the expected behavior because cmd.exe has been used to launch notepad. To get the result you're expecting, use the bypass_shell option of proc_open()'s 4th parameter (http://php.net/proc_open):

$process = proc_open($cmd, $descriptorspec, $pipes, array('bypass_shell' => TRUE));
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 22:01:28 2024 UTC