fix process names with spaces breaking column count

This commit is contained in:
Dave Pedu 2015-12-05 18:09:34 -08:00
parent 08f2101623
commit 44e7b0b2cf
1 changed files with 5 additions and 1 deletions

View File

@ -4,6 +4,7 @@ import re
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'(\([^\)]+\))')
def procs():
@ -36,7 +37,10 @@ def procs():
with open(f, "r") as statfile:
with open(f+"us", "r") as statusfile:
# Read stat info
stat = statfile.read().strip().split(" ")
stat = statfile.read().strip()
# Fix spaces in process names
stat = PAT_REMOVE_PROC_SPACES.sub("PROCNAME", stat)
stat = stat.split(" ")
# Read uid/gid from status
status = statusfile.read()