fix fattest()
This commit is contained in:
parent
83c1fd1018
commit
4f5f4c7d44
76
nohang
76
nohang
@ -577,45 +577,77 @@ def fattest():
|
||||
"""Find the 'fattest' process"""
|
||||
pid_badness_list = []
|
||||
|
||||
if regex_matching:
|
||||
for pid in os.listdir('/proc'):
|
||||
# only directories whose names consist only of numbers, except /proc/1/
|
||||
if pid[0].isdecimal() is False or pid == '1':
|
||||
continue
|
||||
|
||||
for pid in os.listdir('/proc'):
|
||||
if pid[0].isdecimal() is False:
|
||||
continue
|
||||
# find and modify badness (if it needs)
|
||||
try:
|
||||
badness = int(rline1('/proc/' + pid + '/oom_score'))
|
||||
|
||||
if decrease_oom_score_adj:
|
||||
oom_score_adj = int(rline1('/proc/' + pid + '/oom_score_adj'))
|
||||
if badness > oom_score_adj_max:
|
||||
badness = badness - oom_score_adj + oom_score_adj_max
|
||||
|
||||
if regex_matching:
|
||||
|
||||
try:
|
||||
badness = int(rline1('/proc/' + pid + '/oom_score'))
|
||||
name = pid_to_name(pid)
|
||||
cmdline = pid_to_cmdline(pid)
|
||||
uid = pid_to_uid(pid)
|
||||
|
||||
# skip kthreads
|
||||
if cmdline == '':
|
||||
continue
|
||||
|
||||
#print([uid], [name], [cmdline])
|
||||
|
||||
if search(avoid_regex, name) is not None:
|
||||
badness = int(badness / avoid_factor)
|
||||
print(' Name matches with avoid_regex \033[33m{}\033[0m: \033[33m{}\033[0m, CmdLine: {}'.format(
|
||||
avoid_regex, name, cmdline))
|
||||
|
||||
if search(prefer_regex, name) is not None:
|
||||
badness = int((badness + 1) * prefer_factor)
|
||||
print(' Name matches with prefer_regex \033[33m{}\033[0m: \033[33m{}\033[0m, CmdLine: {}'.format(
|
||||
prefer_regex, name, cmdline))
|
||||
|
||||
except FileNotFoundError:
|
||||
badness = 0
|
||||
except ProcessLookupError:
|
||||
badness = 0
|
||||
pid_badness_list.append((pid, badness))
|
||||
|
||||
else:
|
||||
if search(avoid_re_cmdline, cmdline) is not None:
|
||||
badness = int(badness / avoid_cmd_factor)
|
||||
print(' Cmdline matches with avoid_re_cmdline \033[33m{}\033[0m: \033[33m{}\033[0m, Name: {}'.format(
|
||||
avoid_re_cmdline, cmdline, name))
|
||||
|
||||
for pid in os.listdir('/proc'):
|
||||
if pid[0].isdecimal() is False:
|
||||
continue
|
||||
try:
|
||||
badness = int(rline1('/proc/' + pid + '/oom_score'))
|
||||
except FileNotFoundError:
|
||||
badness = 0
|
||||
except ProcessLookupError:
|
||||
badness = 0
|
||||
pid_badness_list.append((pid, badness))
|
||||
if search(prefer_re_cmdline, cmdline) is not None:
|
||||
badness = int((badness + 1) * prefer_cmd_factor)
|
||||
print(' Cmdline matches with prefer_re_cmdline \033[33m{}\033[0m: \033[33m{}\033[0m, Name: {}'.format(
|
||||
prefer_re_cmdline, cmdline, name))
|
||||
|
||||
|
||||
if search(avoid_re_uid, uid) is not None:
|
||||
badness = int(badness / avoid_uid_factor)
|
||||
print(' UID matches with avoid_re_uid \033[33m{}\033[0m: \033[33m{}\033[0m, Name: {}'.format(
|
||||
avoid_re_uid, uid, name))
|
||||
|
||||
if search(prefer_re_uid, uid) is not None:
|
||||
badness = int((badness + 1) * prefer_uid_factor)
|
||||
print(' UID matches with prefer_re_uid \033[33m{}\033[0m: \033[33m{}\033[0m, Name: {}'.format(
|
||||
prefer_re_uid, uid, name))
|
||||
|
||||
except FileNotFoundError:
|
||||
badness = 0
|
||||
except ProcessLookupError:
|
||||
badness = 0
|
||||
pid_badness_list.append((pid, badness))
|
||||
|
||||
# Make list of (pid, badness) tuples, sorted by 'badness' values
|
||||
pid_tuple_list = sorted(
|
||||
pid_badness_list, key=itemgetter(1), reverse=True)[0]
|
||||
|
||||
# Get maximum 'badness' value
|
||||
victim_badness = pid_tuple_list[1]
|
||||
|
||||
pid = pid_tuple_list[0]
|
||||
|
||||
name = pid_to_name(pid)
|
||||
|
Loading…
Reference in New Issue
Block a user