Reputation: 23489
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?
UPDATE
I mean , i'm inspecting these procress with another process , so getppid won't work here
Upvotes: 2
Views: 161
Reputation: 206659
That information is present in /proc/<pid>/stat
, and more readably in /proc/<pid>/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
Upvotes: 1
Reputation: 50024
It is the fourth field in /proc/[pid]/stat. It is documented in the man page proc(5)
.
Upvotes: 2