diff options
Diffstat (limited to 'code/snippets/process_wait_queue.rb')
| -rw-r--r-- | code/snippets/process_wait_queue.rb | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/code/snippets/process_wait_queue.rb b/code/snippets/process_wait_queue.rb new file mode 100644 index 0000000..872f8d8 --- /dev/null +++ b/code/snippets/process_wait_queue.rb @@ -0,0 +1,18 @@ +# We create two child processes. +2.times do + fork do + # Both processes exit immediately. + abort "Finished!" + end +end + +# The parent process waits for the first process, then sleeps for 5 seconds. +# In the meantime the second child process has exited and is no +# longer running. +puts Process.wait +sleep 5 + +# The parent process asks to wait once again, and amazingly enough, the second +# process' exit information has been queued up and is returned here. +puts Process.wait + |
