From: Dave Thomas Date: 2003-05-28T07:08:57+09:00 Subject: Re: system calls Florian G. Pflug wrote: > On Wed, May 28, 2003 at 01:56:41AM +0900, J.Hawkesworth wrote: > >>Don't know if this helps but I recall that in perl you have to divide by >>256 to get the real return value. (Tried to test here but running under >>Windows and therefore have no 'fork' to eat really_cool_system with). > > > This is because the reason for the program termination (e.g. caught a > signal, called exit,....) is encoded in the least significant 8 bits. Ruby 1.8 encapsulates this in a Process::Status object: dave[ruby/rdoc 17:07:36] ri Process::Status This is a test 'ri'. Please report errors and omissions on http://www.rubygarden.org/ruby?RIOnePointEight ------------------------------------------------------------------------ class: Process::Status ------------------------------------------------------------------------ Process::Status encapsulates the information on the status of a running or terminated system process. The built-in variable $? is either nil or a Process::Status object. fork { exit 99 } #=> 26557 Process.wait #=> 26557 $?.class #=> Process::Status $?.to_i #=> 25344 $? >> 8 #=> 99 $?.stopped? #=> false $?.exited? #=> true $?.exitstatus #=> 99 Posix system record information on processes using a 16-bit integer. The lower bits recorded 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. ------------------------------------------------------------------------ &, ==, >>, coredump?, exited?, exitstatus, inspect, pid, signaled?, stopped?, stopsig, termsig, to_i, to_int, to_s ------------------------------------------------------------------------