Code: Alles auswählen
def print_processpath(pid):
while pid:
print os.popen('ps -p %d -opid=,command=' % pid).read().strip(), os.getsid(pid) == pid
pid = int(os.popen('ps -p %d -oppid=' % pid).read().strip())
Ruft man das in einem xterm mit Shell in ipython auf, sieht es so aus:
Code: Alles auswählen
In [5]: print_processpath(os.getpid())
13689 /usr/bin/python /usr/bin/ipython False
13441 bash True
13439 /usr/bin/xterm False
4187 init --user True
4161 lightdm --session-child 12 25 False
1188 lightdm True
1 /sbin/init True
Code: Alles auswählen
In [3]: print_processpath(os.getpid())
13769 /usr/bin/python /usr/bin/ipython True
13767 xterm ipython False
13441 bash True
13439 /usr/bin/xterm False
4187 init --user True
4161 lightdm --session-child 12 25 False
1188 lightdm True
1 /sbin/init True