`Process::Status` 值的 `0x0100` 是什么意思?

What's the meaning of `0x0100` for a `Process::Status` value?

我有代码:

Process.spawn(RbConfig.ruby, "a ruby file", "arg")

然后我等待并通过以下方式检查其状态:

Process.wait
$?.success?

大多数时候,它运行良好。但有时,$?.success?false$?.to_i0x0100。在返回 0x0100 之前,失败的进程似乎没有机会 运行 任何代码(我没有向进程发送任何信号)。我想知道 0x0100 的含义。我还想知道 Ruby 的 spawn 是否会在命令正常时失败。有人可以帮忙吗?

这里引用 Process::Status class 文档:

Posix systems record information on processes using a 16-bit integer. The lower bits record the process status (stopped, exited, signaled) and the upper bits possibly contain additional information (for example the program's return code in the case of exited processes). Pre Ruby 1.8, these bits were exposed directly to the Ruby program. Ruby now encapsulates these in a Process::Status object. To maximize compatibility, however, these objects retain a bit-oriented interface. In the descriptions that follow, when we talk about the integer value of stat, we're referring to this 16 bit value.

方法 Process::Status#to_i returns 此统计作为 Fixnum。

好吧,我终于得到了答案:当一个ruby进程抛出一个未捕获的异常时,进程的退出代码将是0x0100。这是我对 Ubuntu 14.04 和 Ruby 2.2 的观察。例如:有 ruby 文件 a.rb,在另一个文件中,比如 src.rb,有一个代码片段:

Process.spawn(RbConfig.ruby, "a.rb", "arg")
Process.wait

如果a.rb抛出一个未捕获的异常,那么$?.to_i将是0x0100。更重要的是,我还观察到 a.rb 有时在其进程失败并返回 0x0100 之前没有被执行。所以我想这可能与 Ruby 解释器有关,因为我确定 a.rb 没问题。

无论如何,没有官方文件提到确切的行为。所以我的经验供大家参考。