From a6d77470d171ee5f6650f649dbb3f3a04490b222 Mon Sep 17 00:00:00 2001 From: Alexey Avramov Date: Sun, 30 Jun 2019 02:28:24 +0900 Subject: [PATCH] fix thanatolog --- trash/thanatolog | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/trash/thanatolog b/trash/thanatolog index 6c3e46b..22d4aa7 100755 --- a/trash/thanatolog +++ b/trash/thanatolog @@ -3,7 +3,8 @@ import os from time import sleep, time from signal import (signal, - SIGKILL, SIGTERM, SIGINT, SIGQUIT, SIGCONT, SIGUSR1, SIGUSR2, + SIGKILL, SIGTERM, SIGINT, SIGQUIT, + SIGCONT, SIGUSR1, SIGUSR2, SIGHUP, SIGABRT, SIGSEGV, SIGBUS) from sys import argv, exit @@ -34,7 +35,6 @@ def mlockall(): print('All memory locked with MCL_CURRENT | MCL_FUTURE | MCL_ONFAULT') - def check_mem(): """find mem_available""" with open('/proc/meminfo') as f: @@ -44,8 +44,6 @@ def check_mem(): return mem_available - - def pid_to_name(pid): """ """ @@ -102,6 +100,12 @@ def rline1(path): ############################################################################### +if len(argv) != 2: + print("""Usage: +thanatolog PID""") + exit() + + mlockall() @@ -116,16 +120,14 @@ print('Name:', name) print('RSS at startup: {} (100.0 %)'.format(int(rss0))) print('MemAvail:', ma) -send_signal = SIGTERM - +send_signal = SIGKILL # os.kill(int(pid), SIGCONT) +os.kill(int(pid), send_signal) -# os.kill(int(pid), send_signal) t0 = time() - while True: rpe = os.path.exists('/proc/{}/exe'.format(pid)) rss = pid_to_rss(pid) @@ -135,12 +137,10 @@ while True: state = pid_to_state(pid) ma = check_mem() + print('RP: {} | RSS: {} ({} %) | State: {} | time: {} | MemAv' + 'ail: {}'.format(rpe, rss, round(float(rss) / ( + rss0 + 0.0001) * 100, 1), state, round(d, 3), ma)) + if pe is False: + print('Process {} ({}) died in {} sec'.format(pid, name, round(d, 3))) exit() - - print('RP: {} | RSS: {} ({} %) | State: {} | time: {} | MemAvail: {}'.format( - rpe, rss, round(float(rss) / (rss0 + 0.0001) * 100, 1), state, round(d, 4), ma - ) - ) - - # sleep(0.0001)