问题描述
在Perl 5中,system()
呼叫能否在die
中使用?
Can a system()
call can ever die
in Perl 5?
(换句话说,为了使执行system()
调用的程序100%防崩溃,是否需要将其包装到eval
块中,或者完全完全没有必要吗?)
(in other words, in order to 100% crash-proof a program that does a system()
call, does it need to be wrapped into an eval
block, or is that wholly totally unnecessary?)
在 perldoc system
中,我没有提到任何这种可能性,但也没有找到确切的此呼叫永不消亡".
I haven't found a single mention to that possibility in perldoc system
, but didn't quite find the precise "this call never dies" either.
注意:这里的问题是关于基本CORE Perl的,没有autodie
或任何其他具有类似效果的自定义模块.另外,假定未设置ALRM
信号,或对此设置任何其他自定义信号处理程序.
NOTE: the question is about basic CORE Perl here, no autodie
or any other custom module that would have similar effect. Also, assume no ALRM
signal was set, or any other custom signal handler for that matter.
推荐答案
除非我对源的解释不正确,否则这似乎是一种可能性:
Unless my interpretation of the source is incorrect, this looks like a possibility:
源:Perl 5.16.2(也已选中5.8.8),文件:pp_sys.c,行:PP(pp_system)
代码块中的4224:
Source: Perl 5.16.2 (checked 5.8.8 too), file: pp_sys.c, line: 4224 within the PP(pp_system)
code block:
if (n != sizeof(int))
DIE(aTHX_ "panic: kid popen errno read, n=%u", n);
DIE
是在util.c
根据文档,恐慌:孩子popen errno读"表示分叉的孩子返回了有关其errno的令人费解的消息".
According to the documentation, "panic: kid popen errno read" means "forked child returned an incomprehensible message about its errno".
Explanation of panic
messages in Perl:
这篇关于Perl system()调用会死吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!