Using signals to debug long-running processes
Sometimes a long-running process will start to perform it's tasks much slower than it should, or in a strange order. It'd be lovely to know what the process is doing but strace
produces a deluge of information that is several levels below what you want to know. What can you do?
Well, we could ask the process to turn on debugging output while it's still running. How does that sound?
trap("USR1") do
$DEBUG = !$DEBUG
@logger.level = $DEBUG ? Logger::DEBUG : Logger::INFO
@logger.info "USR1 received. Turning #{$DEBUG ? 'on' : 'off'} debugging."
end
Now whenever you need more debugging information simple send a USR1 signal to your process.
kill -USR1 [pid]
You can verify that I've written this post by following the verification instructions:
curl -LO http://barkingiguana.com/2008/08/31/using-signals-to-debug-long-running-processes.html.orig
curl -LO http://barkingiguana.com/2008/08/31/using-signals-to-debug-long-running-processes.html.orig.asc
gpg --verify using-signals-to-debug-long-running-processes.html.orig{.asc,}
If you'd like to have a conversation about this post, email craig@barkingiguana.com. I don't bite.