summaryrefslogtreecommitdiff
path: root/code/snippets/wait_for_each_process.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/wait_for_each_process.rb
initial commitHEADmaster
Diffstat (limited to 'code/snippets/wait_for_each_process.rb')
-rw-r--r--code/snippets/wait_for_each_process.rb14
1 files changed, 14 insertions, 0 deletions
diff --git a/code/snippets/wait_for_each_process.rb b/code/snippets/wait_for_each_process.rb
new file mode 100644
index 0000000..ca14418
--- /dev/null
+++ b/code/snippets/wait_for_each_process.rb
@@ -0,0 +1,14 @@
+# We create 3 child processes.
+3.times do
+ fork do
+ # Each one sleeps for a random amount of number less than 5 seconds.
+ sleep rand(5)
+ end
+end
+
+3.times do
+ # We wait for each child process to exit and print the pid that
+ # gets returned.
+ puts Process.wait
+end
+