Last active
October 10, 2015 07:07
-
-
Save r4um/3652764 to your computer and use it in GitHub Desktop.
Decode signal masks Sig* in /proc/PID/status
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
#!/usr/bin/env ruby | |
# | |
# Decode signal masks Sig* in /proc/PID/status | |
# See function render_sigset_t in kernel source fs/proc/array.c | |
# | |
class SIGMask | |
def self.signame(signo) | |
sig = Signal::list.invert[signo] | |
if sig | |
"SIG" + sig | |
else | |
signo | |
end | |
end | |
def self.decode(mask) | |
# echo "#include <signal.h>" | gcc -dM -E - | grep define._NSIG | |
_NSIG = 65 | |
signals = [] | |
pos = 1 | |
mask.split('').each do |m| | |
i = _NSIG - (pos * 4) | |
bm = { 1=> 1, 2 => 2, 4 => 3, 8 => 4 } | |
bm.each do |k,v| | |
if (m.to_i(base=16) & k) == k | |
signals.push signame(i + bm[k]) | |
end | |
end | |
pos += 1 | |
end | |
signals | |
end | |
end | |
puts SIGMask.decode ARGV[0] if ARGV[0] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@bdlow, how ?
Complete app https://github.com/r4um/sigmask