Created
April 9, 2012 21:49
-
-
Save wuputah/2346764 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
puts "I am #{$$}" | |
trap('TERM') { puts "[#{Time.now}] #{$$}: Got TERM!" } | |
pid1 = fork | |
# child | |
if !pid1 | |
puts "Child is #{$$}" | |
# create a sub-child | |
pid2 = fork | |
if !pid2 | |
puts "Sub-child is #{$$}" | |
sleep 5 | |
end | |
# child send a signal to the grandchild | |
if pid2 | |
sleep 3 | |
Process.kill("TERM", pid2) | |
end | |
# parent | |
else | |
sleep 1 | |
# send a signal to ourselves | |
Process.kill("TERM", $$) | |
# send a signal to the child | |
sleep 1 | |
Process.kill("TERM", pid1) | |
# wait for everyone else to finish | |
sleep 10 | |
end |
Author
wuputah
commented
Apr 9, 2012
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment