ID:               47566
 Updated by:       fel...@php.net
 Reported By:      james at jamesreno dot com
-Status:           Open
+Status:           Bogus
 Bug Type:         PCNTL related
 Operating System: linux-2.6
 PHP Version:      5.2.9
 New Comment:

You need to use the pcntl_wexitstatus().

http://docs.php.net/manual/en/function.pcntl-wexitstatus.php
http://www.mkssoftware.com/docs/man3/waitpid.3.asp


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

[2009-03-04 21:59:01] james at jamesreno dot com

Description:
------------
The $status exitcode returned by pcntl_waitpid() is incorrectly casted
resulting in an invalid number being returned.

I believe the int is converted to a long in ext/pcntl/pcntl.c,
resulting in an invalid integer being returned to the parent.

        zval *z_status = NULL;
        int status;
        convert_to_long_ex(&z_status);
        status = Z_LVAL_P(z_status);
        child_id = waitpid((pid_t) pid, &status, options);
        Z_LVAL_P(z_status) = status;

z_status is a long, but status is an int...


Reproduce code:
---------------
<?
$pid = pcntl_fork();
if ($pid == -1) {
 echo "Unable to fork";
 exit;
} elseif ($pid) {
 $epid = pcntl_waitpid(-1,$status);
 echo "PARENT: {$pid}/{$epid} exited {$status}\n";
 exit(128);
} else {
 echo "CHILD: Exiting with exit code 128\n";
 exit(128);
}
?>

Expected result:
----------------
[ja...@localhost ~]$ php test.php
CHILD: Exiting with exit code 128
PARENT: 7598/7598 exited 128
[ja...@localhost ~]$ echo $?
128
[ja...@localhost ~]$


Actual result:
--------------
[ja...@localhost ~]$ php test.php
CHILD: Exiting with exit code 128
PARENT: 7598/7598 exited 32768
[ja...@localhost ~]$ echo $?
128
[ja...@localhost ~]$


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


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

Reply via email to