Created
June 4, 2019 10:49
-
-
Save yogeshlonkar/934da1cef5d0e60b699fe08e3b87f1a4 to your computer and use it in GitHub Desktop.
get all signals being listen by process - credit to https://unix.stackexchange.com/a/85365/48479
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
import subprocess | |
ALL_SIGNALS = {} | |
for sig in range(64): | |
sig += 1 | |
sig_cmd = "kill -l " + str(sig) + " 2>/dev/null" | |
ALL_SIGNALS[sig] = subprocess.Popen(sig_cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True).communicate()[0].strip() | |
def getSignals(pid, sigCat): | |
signal_cmd = "grep \"^" + sigCat + ":\" \"/proc/" + str(pid) + "/status\" | cut -c 9-" | |
hex_string = subprocess.Popen(signal_cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True).communicate()[0].strip() | |
bin_string = bin(int(hex_string, 16))[2:].zfill(8) | |
bin_string = bin_string[::-1] | |
signals = [] | |
sigposition = 1 | |
for sigchar in bin_string: | |
if sigchar == "1": | |
if sigposition in ALL_SIGNALS: | |
signal = {} | |
signal['sig'] = sigposition | |
signal['name'] = ALL_SIGNALS[sigposition] | |
signals_li.append(signal) | |
sigposition += 1 | |
return signals_li | |
pid = 123 | |
signalsCaught = getSignals(pid, "SigBlk") | |
signalsIgnore = getSignals(pid, "SigIgn") | |
signalsBlock = getSignals(pid, "SigCgt") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment