Improve signals handling
This commit is contained in:
parent
92af73d499
commit
488592d9ad
44
nohang
44
nohang
@ -6,11 +6,10 @@ from ctypes import CDLL
|
|||||||
from time import sleep, time
|
from time import sleep, time
|
||||||
from operator import itemgetter
|
from operator import itemgetter
|
||||||
from sys import stdout, stderr, argv, exit, version
|
from sys import stdout, stderr, argv, exit, version
|
||||||
from signal import (signal,
|
|
||||||
SIGKILL, SIGTERM, SIGINT, SIGQUIT,
|
|
||||||
SIGHUP, SIGABRT, SIGSEGV, SIGBUS)
|
|
||||||
from re import search
|
from re import search
|
||||||
from sre_constants import error as invalid_re
|
from sre_constants import error as invalid_re
|
||||||
|
from signal import signal, SIGKILL, SIGTERM, SIGINT, SIGQUIT, SIGHUP
|
||||||
|
|
||||||
|
|
||||||
start_time = time()
|
start_time = time()
|
||||||
|
|
||||||
@ -32,8 +31,16 @@ SC_CLK_TCK = os.sysconf(os.sysconf_names['SC_CLK_TCK'])
|
|||||||
|
|
||||||
conf_err_mess = 'Invalid config. Exit.'
|
conf_err_mess = 'Invalid config. Exit.'
|
||||||
|
|
||||||
sig_dict = {SIGKILL: 'SIGKILL',
|
sig_list = [SIGTERM, SIGINT, SIGQUIT, SIGHUP]
|
||||||
SIGTERM: 'SIGTERM'}
|
|
||||||
|
sig_dict = {
|
||||||
|
SIGKILL: 'SIGKILL',
|
||||||
|
SIGINT: 'SIGINT',
|
||||||
|
SIGQUIT: 'SIGQUIT',
|
||||||
|
SIGHUP: 'SIGHUP',
|
||||||
|
SIGTERM: 'SIGTERM'
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
self_pid = str(os.getpid())
|
self_pid = str(os.getpid())
|
||||||
|
|
||||||
@ -114,12 +121,22 @@ def print_self_rss():
|
|||||||
|
|
||||||
|
|
||||||
def signal_handler(signum, frame):
|
def signal_handler(signum, frame):
|
||||||
log('Got signal {}'.format(signum))
|
"""
|
||||||
|
"""
|
||||||
|
for sig_num in sig_list:
|
||||||
|
signal(sig_num, signal_handler_inner)
|
||||||
|
log('Got the {} signal '.format(sig_dict[signum]))
|
||||||
update_stat_dict_and_print(None)
|
update_stat_dict_and_print(None)
|
||||||
log('Exit')
|
log('Exit')
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
|
|
||||||
|
def signal_handler_inner(signum, frame):
|
||||||
|
"""
|
||||||
|
"""
|
||||||
|
log('Got the {} signal (ignored) '.format(sig_dict[signum]))
|
||||||
|
|
||||||
|
|
||||||
def write(path, string):
|
def write(path, string):
|
||||||
"""
|
"""
|
||||||
"""
|
"""
|
||||||
@ -601,9 +618,11 @@ def mlockall():
|
|||||||
if result != 0:
|
if result != 0:
|
||||||
log('WARNING: cannot lock all memory')
|
log('WARNING: cannot lock all memory')
|
||||||
else:
|
else:
|
||||||
log('All memory locked with MCL_CURRENT | MCL_FUTURE')
|
pass
|
||||||
|
# log('All memory locked with MCL_CURRENT | MCL_FUTURE')
|
||||||
else:
|
else:
|
||||||
log('All memory locked with MCL_CURRENT | MCL_FUTURE | MCL_ONFAULT')
|
pass
|
||||||
|
# log('All memory locked with MCL_CURRENT | MCL_FUTURE | MCL_ONFAULT')
|
||||||
|
|
||||||
|
|
||||||
def update_stat_dict_and_print(key):
|
def update_stat_dict_and_print(key):
|
||||||
@ -2563,7 +2582,7 @@ mlockall()
|
|||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
||||||
|
|
||||||
print_self_rss()
|
# print_self_rss()
|
||||||
|
|
||||||
|
|
||||||
log('Monitoring has started!')
|
log('Monitoring has started!')
|
||||||
@ -2590,9 +2609,8 @@ if print_mem_check_results:
|
|||||||
|
|
||||||
|
|
||||||
# handle signals
|
# handle signals
|
||||||
sig_list = [SIGTERM, SIGINT, SIGQUIT, SIGHUP, SIGABRT, SIGSEGV, SIGBUS]
|
for sig_num in sig_list:
|
||||||
for signum in sig_list:
|
signal(sig_num, signal_handler)
|
||||||
signal(signum, signal_handler)
|
|
||||||
|
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
@ -2837,7 +2855,5 @@ while True:
|
|||||||
send_notify_warn()
|
send_notify_warn()
|
||||||
warn_timer = 0
|
warn_timer = 0
|
||||||
|
|
||||||
# print(victim_dict)
|
|
||||||
|
|
||||||
# SLEEP BETWEEN MEM CHECKS
|
# SLEEP BETWEEN MEM CHECKS
|
||||||
sleep_after_check_mem()
|
sleep_after_check_mem()
|
||||||
|
@ -132,6 +132,8 @@ max_sleep_time = 3
|
|||||||
|
|
||||||
min_sleep_time = 0.1
|
min_sleep_time = 0.1
|
||||||
|
|
||||||
|
# sleep_time_if_threshold_is_exceeded = 0.02 # (todo)
|
||||||
|
|
||||||
#####################################################################
|
#####################################################################
|
||||||
|
|
||||||
4. The prevention of killing innocent victims
|
4. The prevention of killing innocent victims
|
||||||
|
Loading…
Reference in New Issue
Block a user