using comm to find proc name
This commit is contained in:
parent
f3d3fd09fa
commit
bf1d4bfb35
24
nohang
24
nohang
@ -480,6 +480,7 @@ def zram_stat(zram_id):
|
|||||||
return disksize, mem_used_total # BYTES, str
|
return disksize, mem_used_total # BYTES, str
|
||||||
|
|
||||||
|
|
||||||
|
'''
|
||||||
def pid_to_name(pid):
|
def pid_to_name(pid):
|
||||||
"""
|
"""
|
||||||
Get process name by pid.
|
Get process name by pid.
|
||||||
@ -501,6 +502,22 @@ def pid_to_name(pid):
|
|||||||
f.seek(6)
|
f.seek(6)
|
||||||
return f.read(15).decode(
|
return f.read(15).decode(
|
||||||
'utf-8', 'ignore').partition('\n')[0]
|
'utf-8', 'ignore').partition('\n')[0]
|
||||||
|
'''
|
||||||
|
|
||||||
|
|
||||||
|
def pid_to_name(pid):
|
||||||
|
"""
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
with open('/proc/' + pid + '/comm', 'rb') as f:
|
||||||
|
return f.read().decode('utf-8', 'ignore')[:-1]
|
||||||
|
except FileNotFoundError:
|
||||||
|
return ''
|
||||||
|
except ProcessLookupError:
|
||||||
|
return ''
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def pid_to_ppid(pid):
|
def pid_to_ppid(pid):
|
||||||
@ -798,18 +815,12 @@ def pid_to_badness(pid):
|
|||||||
if search(re_tup[1], cgroup) is not None:
|
if search(re_tup[1], cgroup) is not None:
|
||||||
badness += int(re_tup[0])
|
badness += int(re_tup[0])
|
||||||
|
|
||||||
|
|
||||||
if re_match_realpath:
|
if re_match_realpath:
|
||||||
realpath = pid_to_realpath(pid)
|
realpath = pid_to_realpath(pid)
|
||||||
for re_tup in realpath_re_list:
|
for re_tup in realpath_re_list:
|
||||||
if search(re_tup[1], realpath) is not None:
|
if search(re_tup[1], realpath) is not None:
|
||||||
badness += int(re_tup[0])
|
badness += int(re_tup[0])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if re_match_cmdline:
|
if re_match_cmdline:
|
||||||
cmdline = pid_to_cmdline(pid)
|
cmdline = pid_to_cmdline(pid)
|
||||||
for re_tup in cmdline_re_list:
|
for re_tup in cmdline_re_list:
|
||||||
@ -878,6 +889,7 @@ def find_victim(_print_proc_table):
|
|||||||
# pid_to_cmdline(pid)
|
# pid_to_cmdline(pid)
|
||||||
# pid_to_realpath(pid)
|
# pid_to_realpath(pid)
|
||||||
pid_to_cgroup(pid)
|
pid_to_cgroup(pid)
|
||||||
|
# pid_to_name(pid)
|
||||||
# ''
|
# ''
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -387,7 +387,7 @@ print_total_stat = True
|
|||||||
|
|
||||||
Печатать таблицу процессов перед каждым корректирующим действием.
|
Печатать таблицу процессов перед каждым корректирующим действием.
|
||||||
|
|
||||||
print_proc_table = False
|
print_proc_table = True
|
||||||
|
|
||||||
print_victim_info = True
|
print_victim_info = True
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user