本文簡要介紹ruby語言中 Process.wait 的用法。
用法
wait() → integer
wait(pid=-1, flags=0) → integer
waitpid(pid=-1, flags=0) → integer
等待子進程退出,返回其進程 ID,並將 $? 設置為包含該進程信息的 Process::Status 對象。它等待哪個孩子取決於 pid 的值:
- > 0
-
等待進程 ID 等於
pid的子進程。 - 0
-
等待其進程組 ID 等於調用進程的任何子進程。
- -1
-
等待任何子進程(如果沒有給出
pid,則為默認值)。 - < -1
-
等待進程組 ID 等於
pid絕對值的任何子進程。
flags 參數可能是標誌值 Process::WNOHANG (如果沒有可用的子節點,則不阻塞)或 Process::WUNTRACED (返回尚未報告的已停止子節點)的邏輯或標誌值。並非所有標誌都適用於所有平台,但標誌值為零將適用於所有平台。
如果沒有子進程,調用此方法會引發 SystemCallError 。並非在所有平台上都可用。
include Process
fork { exit 99 } #=> 27429
wait #=> 27429
$?.exitstatus #=> 99
pid = fork { sleep 3 } #=> 27440
Time.now #=> 2008-03-08 19:56:16 +0900
waitpid(pid, Process::WNOHANG) #=> nil
Time.now #=> 2008-03-08 19:56:16 +0900
waitpid(pid, 0) #=> 27440
Time.now #=> 2008-03-08 19:56:19 +0900
相關用法
- Ruby Process.wait2用法及代碼示例
- Ruby Process.waitall用法及代碼示例
- Ruby Process.groups用法及代碼示例
- Ruby Process.getpgrp用法及代碼示例
- Ruby Process.setproctitle用法及代碼示例
- Ruby Process.setrlimit用法及代碼示例
- Ruby Process.uid用法及代碼示例
- Ruby Process.pid用法及代碼示例
- Ruby Process.detach用法及代碼示例
- Ruby Process.maxgroups用法及代碼示例
- Ruby Process.clock_gettime用法及代碼示例
- Ruby Process.exec用法及代碼示例
- Ruby Process.groups=用法及代碼示例
- Ruby Process.clock_getres用法及代碼示例
- Ruby Process.getsid用法及代碼示例
- Ruby Process.getpriority用法及代碼示例
- Ruby Process.times用法及代碼示例
- Ruby Process.getpgid用法及代碼示例
- Ruby Process.euid用法及代碼示例
- Ruby Process.exit用法及代碼示例
- Ruby Process.setpriority用法及代碼示例
- Ruby Process.kill用法及代碼示例
- Ruby Process.initgroups用法及代碼示例
- Ruby Process.spawn用法及代碼示例
- Ruby Process.egid用法及代碼示例
注:本文由純淨天空篩選整理自ruby-lang.org大神的英文原創作品 Process.wait。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
