Current Location: Home> Function Categories> proc_get_status

proc_get_status

Get information about processes opened by the proc_open() function
Name:proc_get_status
Category:Program execution
Programming Language:php
One-line Description:Get the status information of the process opened by the proc_open() function

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:

  • process: The process resource returned by proc_open().

Return value:

  • Returns an associative array containing process status information. The array contains the following key values:
    • command: The command line of the process.
    • pid: The process ID.
    • running: Boolean value of whether the process is running.
    • signed: Boolean value of whether the process is terminated by a signal.
    • stopped: Boolean value of whether the process is suspended.
    • exitcode: The exit code of the process. If the process is still running, it is a negative value.
    • termig: The signal number of the process terminated.
    • stopsig: The signal number of the process paused.

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.

Similar Functions
Popular Articles