Skip to content

Instantly share code, notes, and snippets.

@r4um
Last active October 10, 2015 07:07
Show Gist options
  • Save r4um/3652764 to your computer and use it in GitHub Desktop.
Save r4um/3652764 to your computer and use it in GitHub Desktop.
Decode signal masks Sig* in /proc/PID/status
#!/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]
@r4um
Copy link
Author

r4um commented Jun 25, 2014

@bdlow, how ?

Complete app https://github.com/r4um/sigmask

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment