php-pcntlHow to use pcntl_wexitstatus in PHP?
PCNTL_WEXITSTATUS is a PHP function used to retrieve the exit status of a child process. It is part of the pcntl extension.
Example
<?php
$pid = pcntl_fork();
if ($pid == -1) {
die('could not fork');
} else if ($pid) {
// parent
$status = null;
pcntl_waitpid($pid, $status);
$exitStatus = pcntl_wexitstatus($status);
echo "Child exited with status $exitStatus\n";
} else {
// child
exit(3);
}
Output example
Child exited with status 3
Code explanation
pcntl_fork()
: creates a child processpcntl_waitpid($pid, $status)
: waits for the child process to finishpcntl_wexitstatus($status)
: retrieves the exit status of the child process
Helpful links
More of Php Pcntl
- How to use PCNTL alarm in PHP?
- How to use pcntl_wifexited in PHP?
- How to install PCNTL for PHP in Debian?
- How to use pcntl_signal in PHP?
- How to kill a process with PHP PCNTL?
- How to check if PCNTL is enabled in PHP?
- How to prevent zombie processes with the PCNTL_FORK function in PHP?
- How to use pcntl_waitpid in PHP?
- How to use shared memory with the PCNTL_FORK function in PHP?
See more codes...