remove unnecessary read
This commit is contained in:
parent
44e7b0b2cf
commit
e61bed7fd6
|
@ -2,8 +2,6 @@ from glob import glob
|
||||||
import re
|
import re
|
||||||
|
|
||||||
KTHREADD_PID = 2
|
KTHREADD_PID = 2
|
||||||
PAT_UID = re.compile(r'Uid:\s+(?P<uid>[0-9]+)\s')
|
|
||||||
PAT_GID = re.compile(r'Gid:\s+(?P<gid>[0-9]+)\s')
|
|
||||||
PAT_REMOVE_PROC_SPACES = re.compile(r'(\([^\)]+\))')
|
PAT_REMOVE_PROC_SPACES = re.compile(r'(\([^\)]+\))')
|
||||||
|
|
||||||
def procs():
|
def procs():
|
||||||
|
@ -35,27 +33,20 @@ def procs():
|
||||||
for f in glob('/proc/[0-9]*/stat'):
|
for f in glob('/proc/[0-9]*/stat'):
|
||||||
try:
|
try:
|
||||||
with open(f, "r") as statfile:
|
with open(f, "r") as statfile:
|
||||||
with open(f+"us", "r") as statusfile:
|
# Read stat info
|
||||||
# Read stat info
|
stat = statfile.read().strip()
|
||||||
stat = statfile.read().strip()
|
# Fix spaces in process names
|
||||||
# Fix spaces in process names
|
stat = PAT_REMOVE_PROC_SPACES.sub("PROCNAME", stat)
|
||||||
stat = PAT_REMOVE_PROC_SPACES.sub("PROCNAME", stat)
|
stat = stat.split(" ")
|
||||||
stat = stat.split(" ")
|
|
||||||
|
proc_id = int(stat[0])
|
||||||
# Read uid/gid from status
|
proc_parent = int(stat[3])
|
||||||
status = statusfile.read()
|
|
||||||
|
if proc_parent == KTHREADD_PID:
|
||||||
proc_uid = PAT_UID.findall(status)
|
num_kthreads+=1
|
||||||
proc_gid = PAT_GID.findall(status)
|
else:
|
||||||
|
num_procs+=1
|
||||||
proc_id = int(stat[0])
|
num_threads += int(stat[19])
|
||||||
proc_parent = int(stat[3])
|
|
||||||
|
|
||||||
if proc_parent == KTHREADD_PID:
|
|
||||||
num_kthreads+=1
|
|
||||||
else:
|
|
||||||
num_procs+=1
|
|
||||||
num_threads += int(stat[19])
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
|
|
Loading…
Reference in New Issue