Skip to content

Instantly share code, notes, and snippets.

@wuputah
Created April 9, 2012 21:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wuputah/2346764 to your computer and use it in GitHub Desktop.
Save wuputah/2346764 to your computer and use it in GitHub Desktop.
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
@wuputah
Copy link
Author

wuputah commented Apr 9, 2012

I am 16371
Child is 16372
Sub-child is 16373
[2012-04-09 14:50:50 -0700] 16371: Got TERM!
[2012-04-09 14:50:51 -0700] 16372: Got TERM!
[2012-04-09 14:50:52 -0700] 16373: Got TERM!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment