#22999 [Opn->Asn]: proc_close() sometimes returns -1 when called process exited with status of 0

From: Date: Tue, 01 Apr 2003 11:00:38 +0000
Subject: #22999 [Opn->Asn]: proc_close() sometimes returns -1 when called process exited with status of 0
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-36906@lists.php.net to get a copy of this message
 ID:               22999
 Updated by:       wez@php.net
 Reported By:      phil at concretecomputing dot co dot uk
-Status:           Open
+Status:           Assigned
 Bug Type:         Filesystem function related
 Operating System: sun os
 PHP Version:      4.3.1
-Assigned To:      
+Assigned To:      wez
 New Comment:

This is a known issue when compiling with
--enable-sigchild.

I will see if it can be fixed.


Previous Comments:
------------------------------------------------------------------------

[2003-04-01 04:17:36] phil at concretecomputing dot co dot uk

I'm trying to run a command via proc_open(). The command always
succeeds (exits with status of 0), so I would expect that proc_close()
would always return 0. Most of the time it does, but sometimes it
returns -1.

Here is a script which reproduces the problem. On my system, if you run
the script many times, most times the status reported will be 0, but
occasionally it will be -1.

<?

$inputArray = 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("pipe", "w")                             // stderr is a
pipe that the child will write to
);

$process = proc_open("ps -ef", $inputArray, $outputArray);             
  

if (is_resource($process)) {

  fclose($outputArray[0]);

  // Grab the output
  $output="";
  while(!feof($outputArray[1])) {
    $output .= fgets($outputArray[1], 1024);       
  }

  // Extract any error output
  $errorOutput = "";
  while(!feof($outputArray[2])) {
    $errorOutput .= fgets($outputArray[2], 1024);
  }

  // It is important that you close any pipes before calling
proc_close() in order to avoid a deadlock
  fclose($outputArray[1]);
  fclose($outputArray[2]);

  $status = proc_close($process);    

  echo "proc_close() return result: $status<br>\n";            
  echo "ps error output: [$errorOutput]<br>\n";
  echo "ps output: [$output]<br>\n";                 
}

echo "Done<br>\n";

?>


PHP is compiled as follows:

'./configure' '--with-apxs=/usr/local/apache1.3.27-nerens3.4/bin/apxs'
'--without-mysql' '--enable-track-vars' '--enable-sigchild'
'--with-oci8=/opt/oracle/product/9.0.1' '--enable-apc' '--with-xml'
'--with-expat-dir=/usr/local/expat' '--with-zlib=/usr/local/zlib'
'--with-curl=/usr/local/curl' '--with-mhash=/usr/local/mhash'
'--with-mcrypt=/usr/local/libmcrypt' 

I have tried to have a look at what is going on using truss and I think
it may be caused by another function within php doing a wait() and
getting the exit status for the child so that the wait() in proc_close
returns with ECHLD.

While testing using the above script, I have found that if I add a call
to sleep after the proc_open() call then proc_close() _always_ returns
-1 (and the sleep() call has no effect)

------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=22999&edit=1



Thread (10 messages)

« previous php.bugs (#36906) next »