本文簡要介紹ruby語言中 Process::Status類
的用法。
Process::Status
封裝了正在運行或已終止的係統進程的狀態信息。內置變量$?
是nil
或 Process::Status
對象。
fork { exit 99 } #=> 26557
Process.wait #=> 26557
$?.class #=> Process::Status
$?.to_i #=> 25344
$? >> 8 #=> 99
$?.stopped? #=> false
$?.exited? #=> true
$?.exitstatus #=> 99
Posix 係統使用 16 位整數記錄有關進程的信息。低位記錄進程狀態(已停止、已退出、已發出信號),高位可能包含附加信息(例如,在已退出進程的情況下程序的返回碼)。在 Ruby 1.8 之前,這些位直接暴露給 Ruby 程序。 Ruby 現在將這些封裝在 Process::Status
對象中。然而,為了最大限度地提高兼容性,這些對象保留了bit-oriented 接口。在下麵的說明中,當我們談論 stat
的整數值時,我們指的是這個 16 位值。
相關用法
- Ruby Status.to_s用法及代碼示例
- Ruby Status.exitstatus用法及代碼示例
- Ruby Status.to_i用法及代碼示例
- Ruby Status.inspect用法及代碼示例
- Ruby Status.stat >>用法及代碼示例
- Ruby Status.wait用法及代碼示例
- Ruby Status.stat & num用法及代碼示例
- Ruby Status.pid用法及代碼示例
- Ruby Stat.stat <=>用法及代碼示例
- Ruby Stat.world_writable?用法及代碼示例
- Ruby Stat.birthtime用法及代碼示例
- Ruby Stat.ino用法及代碼示例
- Ruby Stat.readable_real?用法及代碼示例
- Ruby Stat.blockdev?用法及代碼示例
- Ruby Stat.grpowned?用法及代碼示例
- Ruby Stat.mode用法及代碼示例
- Ruby Stat.setuid?用法及代碼示例
- Ruby Stat.ftype用法及代碼示例
- Ruby Stat.blocks用法及代碼示例
- Ruby Stat.ctime用法及代碼示例
- Ruby Stat.rdev_major用法及代碼示例
- Ruby Stat.gid用法及代碼示例
- Ruby Stat.world_readable?用法及代碼示例
- Ruby Stat.size用法及代碼示例
- Ruby Stat.atime用法及代碼示例
注:本文由純淨天空篩選整理自ruby-lang.org大神的英文原創作品 Status類。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。