Search code examples
rubyprocessstandard-library

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


I have code:

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

and I wait and check its status by:

Process.wait
$?.success?

Most of the time, it works well. But sometimes, $?.success? is false and $?.to_i is 0x0100. It seems the failed process didn't get a chance to run any code before 0x0100 was returned (I didn't send any signal to the process). I wonder the meaning of 0x0100. I further want to know if Ruby's spawn may fail when the command is all right. Could anyone help?


Solution

  • OK, finally I got the answer: when a ruby process throws an uncaught exception, the process' exit code will be 0x0100. This is from my observation on Ubuntu 14.04 and Ruby 2.2. For example: there's ruby file a.rb, and in another file, say src.rb, there's a code snippet:

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

    If a.rb throws an uncaught exception, then $?.to_i will be 0x0100. What's more, I also observed that a.rb sometimes didn't get executed before its process failed with 0x0100. So I guess it may have something to do with the Ruby interpreter since I'm sure a.rb is OK.

    Anyway, there' no official document mentioning the exact behavior. So my experience is for your reference.