-
-
Save ahoward/83b98ac750bb8249c38acf0e32157c45 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
# when you really, really, really want to make sure your children get cleaned up you can generate a script | |
# that detaches and monitors *you*. if you disappear the assassin can ensure cleanup happens. even if | |
# you are 'kill -9d' or call 'exit!' | |
assassin = <<-__ | |
pid = #{ Process.pid } | |
4242.times do | |
begin | |
Process.kill(0, pid) | |
rescue Object => e | |
if e.is_a?(Errno::ESRCH) | |
`#{ stop_server } >/dev/null 2>&1` | |
Process.kill(-15, pid) rescue nil | |
sleep(rand + rand) | |
Process.kill(-9, pid) rescue nil | |
end | |
exit | |
end | |
sleep(1 + rand) | |
end | |
__ | |
IO.binwrite('/tmp/assassin.rb', assassin) | |
cmd = "nohup ruby /tmp/assassin.rb >/dev/null 2>&1 &" # need pure ruby / windoze compat | |
system cmd |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment