From 226c8185d4f59cdbcc2116b7bf5df1f44fc59aa4 Mon Sep 17 00:00:00 2001 From: Libor Pechacek Date: Tue, 22 Dec 2015 15:10:55 +0100 Subject: [PATCH] Parse /proc//stat properly Process names can contain spaces. Handle these cases correctly. Signed-off-by: Libor Pechacek --- cpuset/commands/proc.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cpuset/commands/proc.py b/cpuset/commands/proc.py index a2a929c..e4f30e2 100644 --- a/cpuset/commands/proc.py +++ b/cpuset/commands/proc.py @@ -711,7 +711,12 @@ def task_detail(pid, width=70): except: pass # sometimes, we get an extra \n out of this file... stat = file('/proc/'+pid+'/stat', 'r').readline() - stat = stat.split() + # we assume parentheses appear only around the name + stat_right_paren = stat.rfind(')') + stat_left_paren = stat.find('(') + stat = [stat[:stat_left_paren-1]] + \ + [stat[stat_left_paren:stat_right_paren+1]] + \ + stat[stat_right_paren+2:].split() cmdline = file('/proc/'+pid+'/cmdline').readline() # assume that a zero delimits the cmdline (it does now...) cmdline = cmdline.replace('\0', ' ')