以编程方式获取另一个进程的父 pid? [英] Programmatically get parent pid of another process?

查看:23
本文介绍了以编程方式获取另一个进程的父 pid?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了 google,但发现 getppid() 获取了 当前 进程的父进程 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 的第 4 个参数

You'll find the ppid as the 4th parameter of /proc/pid/stat

这篇关于以编程方式获取另一个进程的父 pid?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆