Function name: proc_get_status()
Function description: The proc_get_status() function is used to obtain the status information of the process opened by the proc_open() function.
Applicable version: PHP 4 >= 4.3.0, PHP 5, PHP 7
Syntax: array proc_get_status ( resource $process )
parameter:
Return value:
Example:
$descriptors = array( 0 => array('pipe', 'r'), // 标准输入1 => array('pipe', 'w'), // 标准输出2 => array('pipe', 'w') // 标准错误输出); $process = proc_open('ls -l', $descriptors, $pipes); if (is_resource($process)) { // 获取进程状态信息$status = proc_get_status($process); echo "Command: " . $status['command'] . "\n"; echo "PID: " . $status['pid'] . "\n"; echo "Running: " . ($status['running'] ? 'Yes' : 'No') . "\n"; echo "Signaled: " . ($status['signaled'] ? 'Yes' : 'No') . "\n"; echo "Stopped: " . ($status['stopped'] ? 'Yes' : 'No') . "\n"; echo "Exit Code: " . $status['exitcode'] . "\n"; echo "Termination Signal: " . $status['termsig'] . "\n"; echo "Stop Signal: " . $status['stopsig'] . "\n"; // 关闭进程proc_close($process); }
In the above example, we use proc_open() to open a process and get the status information of the process through proc_get_status(). Then, we print the process's command line, process ID, whether it is running, whether it is terminated by the signal, whether it is suspended, exit code, terminate signal and pause signal. Finally, we closed the process using proc_close().
Note that processes opened with proc_open() need to be explicitly closed via proc_close() to avoid resource leakage.