I'm working on a project where I have a number of PIDs and I have to find out which of these are zombie processes and then kill their parent processes in order to kill the initial zombie process. I am not sure if there is any way to find out what the PPID of a given PID is. Any help would be appreciated.
At the source for the ps command, there is a function called get_proc_stats
defined in proc/readproc.h
that (among other things) returns the parent pid
of a given pid
. You need to do install libproc-dev
to get this function. You can then do:
#include <proc/readproc.h>
void printppid(pid_t pid) {
proc_t process_info;
get_proc_stats(pid, &process_info);
printf("Parent of pid=%d is pid=%d\n", pid, process_info.ppid);
}
This is taken from here. I never used this but according to author this may be helpful.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With