Flowdock
wait(...) public

Waits for a child process to exit, returns its process id, and sets $? to a Process::Status object containing information on that process. Which child it waits on depends on the value of pid:

> 0:Waits for the child whose process ID equals pid.
0:Waits for any child whose process group ID equals that of the calling process.
-1:Waits for any child process (the default if no pid is given).
< -1:Waits for any child whose process group ID equals the absolute value of pid.

The flags argument may be a logical or of the flag values Process::WNOHANG (do not block if no child available) or Process::WUNTRACED (return stopped children that haven’t been reported). Not all flags are available on all platforms, but a flag value of zero will work on all platforms.

Calling this method raises a SystemError if there are no child processes. Not available on all platforms.

   include Process
   fork { exit 99 }                 #=> 27429
   wait                             #=> 27429
   $?.exitstatus                    #=> 99

   pid = fork { sleep 3 }           #=> 27440
   Time.now                         #=> Wed Apr 09 08:57:09 CDT 2003
   waitpid(pid, Process::WNOHANG)   #=> nil
   Time.now                         #=> Wed Apr 09 08:57:09 CDT 2003
   waitpid(pid, 0)                  #=> 27440
   Time.now                         #=> Wed Apr 09 08:57:12 CDT 2003
Show source
Register or log in to add new notes.