#47566 [Bgs]: PCNTL Waitpid exit status incorrect

From: Date: Thu, 05 Mar 2009 20:54:54 +0000
Subject: #47566 [Bgs]: PCNTL Waitpid exit status incorrect
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-134446@lists.php.net to get a copy of this message
ID: 47566 User updated by: james at jamesreno dot com Reported By: james at jamesreno dot com Status: Bogus Bug Type: PCNTL related Operating System: linux-2.6 PHP Version: 5.2.9 New Comment: exit(254); $pid = pcntl_waitpid(-1,$status); if (pcntl_wifexited($status)) { $status = pcntl_wexitstatus($status); echo $status; } Then why is $status, -2 rather than '254'? This method does not seem work *properly* either... Previous Comments: ------------------------------------------------------------------------ [2009-03-04 23:11:46] felipe@php.net 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 ------------------------------------------------------------------------ [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: ---------------- [james@localhost ~]$ php test.php CHILD: Exiting with exit code 128 PARENT: 7598/7598 exited 128 [james@localhost ~]$ echo $? 128 [james@localhost ~]$ Actual result: -------------- [james@localhost ~]$ php test.php CHILD: Exiting with exit code 128 PARENT: 7598/7598 exited 32768 [james@localhost ~]$ echo $? 128 [james@localhost ~]$ ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=47566&edit=1

« previous php.bugs (#134446) next »