php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #51836 proc_get_status() caused child process exit
Submitted: 2010-05-17 08:51 UTC Modified: 2010-05-18 12:47 UTC
From: pcdinh at gmail dot com Assigned:
Status: Not a bug Package: Program Execution
PHP Version: 5.2.13 OS: CentOS 5.4
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: pcdinh at gmail dot com
New email:
PHP Version: OS:

 

 [2010-05-17 08:51 UTC] pcdinh at gmail dot com
Description:
------------
I write a script that is able to launch another process which runs in 100 seconds

The master process will check the child process in a loop to see if it is still running.

The child process is able to launch and run correctly. However, when I asign the resource returned by proc_get_status() to an array and return that array from a function, proc_get_status() does not work correctly any more. It caused the child process exit right after the first call.

Called in the same scope
========================
$process = proc_open('/usr/local/php5-fcgi/bin/php process1.php', $descriptors, $pipes);

// $process and proc_get_status() in same scope ==> OK
$status = proc_get_status($process); 

if (true === $status['running'])
{
  echo "Started process Id\n";
}
else
{
  echo "Unable to start a process\n";
}

Called from different scope and against a reference
===================================================

Return from a function
======================
return array(
        'pid' => $status['pid'],
        'handle' => $process
    );

Called against a reference
==========================

foreach ($running as $pid => $info)
{
   // first call will cause child process exit after that
   $status = proc_get_status($info['handle']); 
   sleep(1);
}

Test script:
---------------
You can read the sample code here: http://gist.github.com/403467

It contains 2 files: a master process named test3.php and a child process named process1.php

Expected result:
----------------
[root@clipserver test]# ./test3.php
Parent process ID: 30283
Started process Id
Process Id 30284 is running
Command used /usr/local/php5-fcgi/bin/php process1.php
Process Id 30284 is running
Command used /usr/local/php5-fcgi/bin/php process1.php
Process Id 30284 is running
Command used /usr/local/php5-fcgi/bin/php process1.php
Process Id 30284 is running
Command used /usr/local/php5-fcgi/bin/php process1.php
Process Id 30284 is running
Command used /usr/local/php5-fcgi/bin/php process1.php
Process Id 30284 is running
Command used /usr/local/php5-fcgi/bin/php process1.php
Process Id 30284 is running
Command used /usr/local/php5-fcgi/bin/php process1.php
Process Id 30284 is running
Command used /usr/local/php5-fcgi/bin/php process1.php
Process Id 30284 is running
Command used /usr/local/php5-fcgi/bin/php process1.php
Process Id 30284 is running
Command used /usr/local/php5-fcgi/bin/php process1.php
Process 30284 is running
Caught a SIGCHLD signal, a worker process exiting
Child process 30284 exited with status 0
Command used
Termination signal:
Is stopped:
Stop signal:
Process 30284 is not running
Process 30284 is not running
Process 30284 is not running

Actual result:
--------------
[root@clipserver test]# ./test3.php
Parent process ID: 30283
Started process Id
Process Id 30284 is running
Command used /usr/local/php5-fcgi/bin/php process1.php
Process Id 30284 is running
Command used /usr/local/php5-fcgi/bin/php process1.php
Process Id 30284 is running
Command used /usr/local/php5-fcgi/bin/php process1.php
Process Id 30284 is running
Command used /usr/local/php5-fcgi/bin/php process1.php
Process Id 30284 is running
Command used /usr/local/php5-fcgi/bin/php process1.php
Process Id 30284 is running
Command used /usr/local/php5-fcgi/bin/php process1.php
Process Id 30284 is running
Command used /usr/local/php5-fcgi/bin/php process1.php
Process Id 30284 is running
Command used /usr/local/php5-fcgi/bin/php process1.php
Process Id 30284 is running
Command used /usr/local/php5-fcgi/bin/php process1.php
Process Id 30284 is running
Command used /usr/local/php5-fcgi/bin/php process1.php
Process 30284 is running
Caught a SIGCHLD signal, a worker process exiting
Child process 30284 exited with status 0
Command used
Termination signal:
Is stopped:
Stop signal:
Process 30284 is not running
Process 30284 is not running
Process 30284 is not running

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-05-17 08:54 UTC] pcdinh at gmail dot com
I am sorry, just submit too fast

The expected result should read as follows:

Expected result:
----------------
[root@clipserver test]# ./test3.php
Parent process ID: 30283
Started process Id
Process Id 30284 is running
Command used /usr/local/php5-fcgi/bin/php process1.php
Process Id 30284 is running
Command used /usr/local/php5-fcgi/bin/php process1.php
Process Id 30284 is running
Command used /usr/local/php5-fcgi/bin/php process1.php
Process Id 30284 is running
Command used /usr/local/php5-fcgi/bin/php process1.php
Process Id 30284 is running
Command used /usr/local/php5-fcgi/bin/php process1.php
Process Id 30284 is running
Command used /usr/local/php5-fcgi/bin/php process1.php
Process Id 30284 is running
Command used /usr/local/php5-fcgi/bin/php process1.php
Process Id 30284 is running
Command used /usr/local/php5-fcgi/bin/php process1.php
Process Id 30284 is running
Command used /usr/local/php5-fcgi/bin/php process1.php
Process Id 30284 is running
Command used /usr/local/php5-fcgi/bin/php process1.php
Process 30284 is running
Process 30284 is running
Process 30284 is running
Process 30284 is running
Process 30284 is running


Child process 30284 should run in 100 seconds before it can exit.
 [2010-05-17 09:40 UTC] pcdinh at gmail dot com
-Package: PCNTL related +Package: Program Execution
 [2010-05-17 09:40 UTC] pcdinh at gmail dot com
Re-categorised

PCNTL => Program Execution
 [2010-05-18 12:47 UTC] mike@php.net
-Status: Open +Status: Bogus
 [2010-05-18 12:47 UTC] mike@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

As you keep no reference to the opened pipes of the child, you close it's stdin/stdout, which causes the child to exit because you do not set ignore_user_abort() in the child.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 20 01:01:28 2024 UTC