如何从进程的父pid中分辨出进程呢?

时间:2021-08-03 15:51:13

I know getppid retrieves the parent pid of the underlying program, but how can you tell this out of that program? I can't find anything useful in /proc/[pid], or is there any useful API that i can use?

我知道getppid检索底层程序的父pid,但是如何从这个程序中分辨出来呢?我在/proc/[pid]中找不到任何有用的东西,或者有什么有用的API可以使用吗?

UPDATE

更新

I mean , i'm inspecting these procress with another process , so getppid won't work here

我是说,我正在用另一个进程检查这些procress,所以getppid在这里不能工作

2 个解决方案

#1


2  

It is the fourth field in /proc/[pid]/stat. It is documented in the man page proc(5).

它是/proc/[pid]/stat中的第四个字段。在手册页proc(5)中有记载。

#2


1  

That information is present in /proc/<pid>/stat, and more readably in /proc/<pid>/status:

该信息存在于/proc/ /stat中,并且在/proc/ /status中更易于阅读。

$ grep PPid /proc/$$/status
PPid:   10615
$ awk '{print $4}' /proc/$$/stat
10615
$ ps -ef
...
me 10616 10615  0 11:04 pts/2    00:00:00 bash

#1


2  

It is the fourth field in /proc/[pid]/stat. It is documented in the man page proc(5).

它是/proc/[pid]/stat中的第四个字段。在手册页proc(5)中有记载。

#2


1  

That information is present in /proc/<pid>/stat, and more readably in /proc/<pid>/status:

该信息存在于/proc/ /stat中,并且在/proc/ /status中更易于阅读。

$ grep PPid /proc/$$/status
PPid:   10615
$ awk '{print $4}' /proc/$$/stat
10615
$ ps -ef
...
me 10616 10615  0 11:04 pts/2    00:00:00 bash