2018-01-10 21:51:52 -05:00
|
|
|
#!/usr/bin/env ruby
|
2019-05-02 18:17:27 -04:00
|
|
|
# frozen_string_literal: true
|
2018-01-10 21:51:52 -05:00
|
|
|
|
|
|
|
$parent_pid = ARGV[0].to_i
|
|
|
|
|
|
|
|
puts "Hello from #{Process.pid} my parent is #{$parent_pid}"
|
|
|
|
|
|
|
|
Thread.new do
|
|
|
|
|
|
|
|
def alive?(pid)
|
|
|
|
Process.kill(0, pid)
|
|
|
|
true
|
|
|
|
rescue
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
|
|
|
while true
|
|
|
|
begin
|
|
|
|
unless alive?($parent_pid)
|
|
|
|
STDERR.puts "Parent was terminated!"
|
|
|
|
Process.kill "TERM", Process.pid
|
|
|
|
sleep 10
|
|
|
|
Process.kill "KILL", Process.pid
|
|
|
|
end
|
|
|
|
rescue => e
|
|
|
|
STDERR.puts "URGENT monitoring thread had an exception #{e}"
|
|
|
|
end
|
|
|
|
sleep 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
sleep
|