从 $? [英] Extracting information from $?
问题描述
您能否就以下 perl 代码片段提供很好的解释.我从谷歌那里得到了一些想法,但仍然有很多基本的困惑.如果你能提供一些小笔记,很有帮助
Can you please provide good explanation about the following perl code snippet. I got some idea from google but still lots of basic confusion is there. great help if you can provide small notes on it
$exit_value = $? >> 8;
$signal_num = $? & 127;
$dumped_core = $? & 128;
推荐答案
引用 The Doc:
$?
最后一个管道关闭返回的状态,反引号(``)命令,成功调用 wait() 或 waitpid(),或从 system() 运算符调用.这只是传统Unix返回的16位状态字wait() 系统调用(或者看起来像它).就这样子进程的退出值真的是 ($?>> 8 ),而 $?&第127话哪个信号,如果有,该进程是从哪个信号中死亡的,以及 $?&128份报告是否有核心转储.
The status returned by the last pipe close, backtick (`` ) command, successful call to wait() or waitpid(), or from the system() operator. This is just the 16-bit status word returned by the traditional Unix wait() system call (or else is made up to look like it). Thus, the exit value of the subprocess is really ($?>> 8 ), and $? & 127 gives which signal, if any, the process died from, and $? & 128 reports whether there was a core dump.
<代码>>>8 给我们一个 16 位字的高字节.
>> 8
gives us the higher byte of a 16-bit word.
<代码>&127 本质上与 & 相同.0b01111111
,给出该字的低 7 位部分.
& 127
is essentially the same as & 0b01111111
, giving out the lower 7-bit part of that word.
<代码>&128 与 & 相同0b10000000
,基本上就是检查结果的第8位.
& 128
is the same as & 0b10000000
, which is basically checking for the 8th bit of the result.
这篇关于从 $?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!