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
def exec | |
pids = [] | |
pid = Process.fork do | |
Exec.execve_override_procname(ENV.to_hash, "sleep", "/bin/sleep", "10") | |
end | |
pids << pid | |
puts "sleep(pid: #{pid})" | |
th = SignalThread.trap(:INT, {detailed:true}) do |info| | |
puts "SIGINT pid: #{pid} siginfo.uid:#{info.uid} siginfo.pid:#{info.pid}" | |
if info.pid.zero? | |
begin | |
puts Process.kill(:INT, *pids) | |
rescue => e | |
puts e | |
end | |
end | |
end | |
Process.wait2(pid) | |
th.kill(:INT) | |
th.cancel | |
end | |
SignalThread.trap(:KILL) do | |
puts "SIGKILL" | |
end | |
exec | |
exec | |
#Thread.usleep(5000000) | |
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
❯ mruby signal_test.rb | |
sleep(pid: 239527) | |
^CSIGINT pid: 239527 siginfo.uid:0 siginfo.pid:0 🌟 一回目のSIGINTは飛ぶ | |
No such process - no such process | |
SIGINT pid: 239527 siginfo.uid:899402263 siginfo.pid:239525 🌟 スレッドの終了 | |
sleep(pid: 239532) | |
^CSIGINT pid: 239532 siginfo.uid:0 siginfo.pid:0 🌟 二回目以降はなぜかSIGINTが飛ばない? | |
1 | |
^CSIGINT pid: 239532 siginfo.uid:0 siginfo.pid:0 | |
1 | |
^CSIGINT pid: 239532 siginfo.uid:0 siginfo.pid:0 | |
1 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment