diff options
Diffstat (limited to 'contrib/gnunet_janitor.py.in')
-rw-r--r-- | contrib/gnunet_janitor.py.in | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/contrib/gnunet_janitor.py.in b/contrib/gnunet_janitor.py.in index c11ff4f..056ab9b 100644 --- a/contrib/gnunet_janitor.py.in +++ b/contrib/gnunet_janitor.py.in @@ -34,6 +34,9 @@ import signal if os.name == 'nt': from win32com.client import GetObject WMI = GetObject('winmgmts:') + killsignal = signal.SIGTERM # any valid value will result in TerminateProcess() +else: + killsignal = signal.SIGKILL def get_process_list (): result = [] @@ -44,7 +47,10 @@ def get_process_list (): else: pids = [pid for pid in os.listdir('/proc') if pid.isdigit ()] for pid in pids: - result.append ((pid, open (os.path.join ('/proc', pid, 'comm'), 'rb').read ())) + with open (os.path.join ('/proc', pid, 'cmdline'), 'rb') as p: + cmdline = p.read ().split ('\x00') + if len (cmdline) > 0: + result.append ((pid, cmdline[0])) return result def main (): @@ -57,7 +63,7 @@ def main (): if re.match (r'gnunet-service-arm', p[1]): print ("killing arm process {0:5} {1}".format (p[0], p[1])) try: - os.kill (p[0], signal.SIGTERM) + os.kill (int (p[0]), killsignal) except OSError as e: print ("failed: {0}".format (e)) pass @@ -65,7 +71,7 @@ def main (): if not re.match (r'gnunet-service-arm', p[1]): print ("killing non-arm process {0:5} {1}".format (p[0], p[1])) try: - os.kill (p[0], signal.SIGTERM) + os.kill (int (p[0]), killsignal) except OSError as e: print ("failed: {0}".format (e)) pass |