summaryrefslogtreecommitdiff
path: root/code/snippets/process_wait_queue.rb
blob: 872f8d83e6ded4f74ad95260979f8798b04773c2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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