type=class
superclass=Object
included=
extended=
dynamically_included=
dynamically_extended=
library=_builtin
aliases=
aliasof=

プロセスの終了ステータスを表すクラスです。
メソッド [[m:Process.#wait2]] などの返り値として使われます。

=== 使用例

wait を使用した例

  fork { exit }
  Process.wait
  case
  when $?.signaled?
    p "child #{$?.pid} was killed by signal #{$?.termsig}"
    if $?.coredump?   # システムがこのステータスをサポートしてなければ常にfalse
      p "child #{$?.pid} dumped core."
    end
  when $?.stopped?
    # 実際には Process.wait を使用しているので、ここに来ることはない
    p "child #{$?.pid} was stopped by signal #{$?.stopsig}"
  when $?.exited?
    p "child #{$?.pid} exited normally. status=#{$?.exitstatus}"
  else
    p "unknown status %#x" % $?.to_i
  end

SIGCHLD を trap する例

  trap(:SIGCHLD) {|sig|

    puts "interrupted by signal #{sig} at #{caller[1]}"
    # 複数の子プロセスの終了に対して1つの SIGCHLD しか届かない
    # 場合があるのでループさせる必要があります

    while Process.waitpid(-1, Process::WNOHANG|Process::WUNTRACED)
      case
      when $?.signaled?
        puts "   child #{$?.pid} was killed by signal #{$?.termsig}"
        if $?.coredump?
          puts "   child #{$?.pid} dumped core."
        end
      when $?.stopped?
        puts "   child #{$?.pid} was stopped by signal #{$?.stopsig}"
      when $?.exited?
        puts "   child #{$?.pid} exited normally. status=#{$?.exitstatus}"
      else
        p "unknown status %#x" % $?.to_i
      end
    end
  }

  p pid1 = fork { sleep 1; exit }
  p pid2 = fork { loop { sleep } } # signal を待つための sleep
  begin
     Process.kill :STOP, pid2
     sleep                      # SIGCHLD を待つための sleep
     Process.kill :CONT, pid2
     Process.kill :TERM, pid2
     loop { sleep }             # SIGCHLD を待つための sleep
  rescue Errno::ECHILD
    puts "done"
  end

  => 12964
     12965
     interrupted by signal 17 at -:27:in `sleep'
        child 12965 was stopped by signal 19
     interrupted by signal 17 at -:30:in `sleep'
        child 12965 was killed by signal 15
     interrupted by signal 17 at -:30:in `sleep'
        child 12964 exited normally. status=0
     done
