如何获取进程的祖父母ID [英] How to get process's grandparent id
本文介绍了如何获取进程的祖父母ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何获取当前进程的父进程的进程ID?
通常给定一个进程ID,我如何获得其父进程ID?
例如os.getpid()可以用来获取进程ID,而os.getppid()可以用来获取父进程,我该如何获取祖父母,
How can i get process id of the current process's parent?
In general given a process id how can I get its parent process id?
e.g. os.getpid() can be used to get the proccess id, and os.getppid() for the parent, how do I get grandparent,
我的目标是linux(ubuntu),所以平台特定的答案是可以的.
My target is linux(ubuntu) so platform specific answers are ok.
推荐答案
特定于Linux:
os.popen("ps -p %d -oppid=" % os.getppid()).read().strip()
这篇关于如何获取进程的祖父母ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文