Last active
May 25, 2020 11:40
-
-
Save lmarburger/ede778f8d6907b7c41d7fcfcd554d2a9 to your computer and use it in GitHub Desktop.
Quit and suspend a ruby process for debugging
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
require 'bundler/setup' | |
require 'rbtrace' | |
require 'English' | |
$run = true | |
Signal.trap('HUP') { $run = false } | |
while $run do | |
puts "pid=#{$PID} time=#{Time.now}" | |
sleep 10 | |
end | |
puts 'done' |
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
$ ruby work.rb | |
pid=24203 time=2017-03-08 15:10:00 -0500 | |
pid=24203 time=2017-03-08 15:10:10 -0500 | |
done | |
waiting... | |
I can debug this process all day |
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
$ rbtrace --pid=24203 --eval='at_exit { $do_not_exit = true; puts "waiting..."; while $do_not_exit do sleep 1 end }' | |
*** attached to process 24203 | |
>> at_exit { $do_not_exit = true; puts "waiting..."; while $do_not_exit do sleep 1 end } | |
=> #<Proc:0x007ffe0899cb78@(eval):1> | |
*** detached from process 24203 | |
$ kill -HUP 24203 | |
$ rbtrace --pid=24203 --eval='puts "I can debug this process all day"' | |
*** attached to process 24203 | |
>> puts "I can debug this process all day" | |
=> nil | |
*** detached from process 24203 | |
$ rbtrace --pid=24203 --eval='$do_not_exit = false' | |
*** attached to process 24203 | |
*** timed out waiting for eval response | |
*** process 24203 is gone |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment