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

 ID:               51836
 User updated by:  pcdinh at gmail dot com
 Reported by:      pcdinh at gmail dot com
 Summary:          proc_get_status() caused child process exit
 Status:           Open
 Type:             Bug
-Package:          PCNTL related
+Package:          Program Execution
 Operating System: CentOS 5.4
 PHP Version:      5.2.13

 New Comment:

Re-categorised



PCNTL => Program Execution


Previous Comments:
------------------------------------------------------------------------
[2010-05-17 08:54:22] pcdinh at gmail dot com

I am sorry, just submit too fast



The expected result should read as follows:



Expected result:

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

[r...@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 08:51:20] 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:
----------------
[r...@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:
--------------
[r...@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


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



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

Reply via email to