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 References: Process names can contain spaces. Handle these cases correctly. Signed-off-by: Libor Pechacek Signed-off-by: Mike Galbraith --- cpuset/commands/proc.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) --- a/cpuset/commands/proc.py +++ b/cpuset/commands/proc.py @@ -711,7 +711,12 @@ options = [make_option('-l', '--list', 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', ' ')