以编程方式获取另一个进程的父pid? [英] Programmatically get parent pid of another process?
本文介绍了以编程方式获取另一个进程的父pid?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试了google,但是发现getppid()
可以获取 current 进程的父pid.
I tried google, but found getppid()
which gets the parent pid of the current process.
我需要类似getppid(some_other_pid)
的东西,有这样的东西吗?基本上获取某个进程的pid,然后返回父进程的pid.
I need something like getppid(some_other_pid)
, is there such a thing? Basically takes the pid of some process and returns the parent process' pid.
推荐答案
我认为最简单的方法是打开"/proc"并解析内容.
I think the simplest thing would be to open "/proc" and parse the contents.
您会发现ppid是/proc/pid/stat的第四个参数
You'll find the ppid as the 4th parameter of /proc/pid/stat
这篇关于以编程方式获取另一个进程的父pid?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文