Created
September 9, 2019 13:33
-
-
Save miry/c963483b74152cfce3b346d82d3ef7fe to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# frozen_string_literal: true | |
def print_threads | |
puts '>> print_threads' | |
Thread.list.each do |thread| | |
p thread | |
puts "Thread TID-#{(thread.object_id ^ ::Process.pid).to_s(36)} #{thread['label']}" | |
if thread.backtrace | |
puts thread.backtrace.join("\n") | |
else | |
puts "<no backtrace available>" | |
end | |
end | |
end | |
def handle_signal(sig) | |
case sig | |
when 'TTIN' | |
print_threads | |
end | |
end | |
%w(TTIN).each do |sig| | |
begin | |
trap sig do | |
puts "Signal #{sig}" | |
handle_signal(sig) | |
end | |
rescue ArgumentError | |
puts "Signal #{sig} not supported" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment