Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically get parent pid of another process?

I tried google, but found getppid() which gets the parent pid of the current process.

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.

like image 483
hasen Avatar asked Oct 06 '09 13:10

hasen


1 Answers

I think the simplest thing would be to open "/proc" and parse the contents.

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

like image 77
Arkaitz Jimenez Avatar answered Oct 12 '22 22:10

Arkaitz Jimenez