Current Location: Home> Function Categories> proc_close

proc_close

Close the process opened by proc_open() and return the process exit code
Name:proc_close
Category:Program execution
Programming Language:php
One-line Description:Close the process opened by the proc_open() function and return the process's exit status code

Function name: proc_close()

Applicable version: PHP 4 >= 4.3.0, PHP 5, PHP 7

Function description: proc_close() is used to close a process opened by the proc_open() function and return the process's exit status code.

Syntax: int proc_close(resource $process)

parameter:

  • $process: The process resource returned by the proc_open() function.

Return value:

  • If the process is successfully closed, the process's exit status code is returned.
  • If the shutdown process fails or the process does not exit, return -1.

Example:

 // 打开进程$descriptors = array( 0 => array('pipe', 'r'), // 标准输入1 => array('pipe', 'w'), // 标准输出2 => array('pipe', 'w') // 标准错误输出); $process = proc_open('ls', $descriptors, $pipes); if (is_resource($process)) { // 关闭进程$exitCode = proc_close($process); if ($exitCode === -1) { echo "无法关闭进程或进程未退出。"; } else { echo "进程已成功关闭,退出状态码为:" . $exitCode; } } else { echo "无法打开进程。"; }

Notes:

  • The proc_close() function can only be used to close processes opened by the proc_open() function.
  • After the process is closed, you can use the proc_get_status() function to obtain the detailed information of the process, such as the process's exit status code, etc.
Similar Functions
Popular Articles