summaryrefslogtreecommitdiff
path: root/code/snippets/wait_for_each_process.rb
blob: ca1441800186a76eb7ab4b82bdfc525bc2fc00ec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
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