php pclose popen,PHP: pclose - Manual

博客讨论了`pclose()`函数返回值的文档误导问题,指出其无法区分正常退出和信号终止,且建议使用`pcntl_wexitstatus()`的说明不准确。实际上,`pclose()`的返回值取决于`waitpid()`的`status`参数。文章揭示了底层实现细节,并提醒开发者正确理解进程退出状态的获取方式。
摘要由CSDN通过智能技术生成

Regarding the return value:

"Returns the termination status of the process that was run. In case of an error then -1 is returned. "

and the note about the exit status: "pclose() is internally implemented using the waitpid(3) system call. To obtain the real exit status code the pcntl_wexitstatus() function should be used."

The documentation of the return value is, at best, misleading. The function returns, as does proc_close():

* -1 on error,

* WEXITSTATUS(status) if WIFEXITED(status) is true, or

* status if WIFEXITED(status) is false,

where status is the status parameter of waitpid().

This makes it impossible to differentiate between a relatively normal exit or a termination by signal, and reduces the value of the proc_close return code to a binary one (ok / something broke).

This can be seen in proc_open_rsrc_dtor() in ext/standard/proc_open.c (PHP 5.4.44, 5.6.12).

The note advising the use of pcntl_wexitstatus is plain wrong. One cannot use pcntl_wexitstatus because it already has been used.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值