summaryrefslogtreecommitdiff
path: root/code/snippets/process_wait_queue.rb
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2013-08-28 07:20:13 -0600
committermo khan <mo@mokhan.ca>2013-08-28 07:20:13 -0600
commitdb1191ec0e7305d684383f8974e2fa437f77ad5a (patch)
tree5e27b197dff849d22d8e1f50eb75aa499b16bd06 /code/snippets/process_wait_queue.rb
initial commitHEADmaster
Diffstat (limited to 'code/snippets/process_wait_queue.rb')
-rw-r--r--code/snippets/process_wait_queue.rb18
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
+