Comment 4 for bug 1399916

Revision history for this message
Roman Odaisky (rdaysky) wrote :

In case there’s another right parenthesis from the process name. str.partition would get the first parenthesis while rpartition would get the last one, which is guaranteed to be the right one (no pun intended :−). Unlikely but why not play it safe when possible. ps does the same.

See for yourself:

ln -s /usr/bin/python xyzzy:-\)plugh
./xyzzy:-\)plugh <<E
statline = open("/proc/self/stat").read()
print(statline)
print("Parent PID is not " + statline.partition(")")[2].split()[1])
print("But rather " + statline.rpartition(")")[2].split()[1])
E