0

I know it's possible to get ppid information from /proc/PID/status but I just want to use it as the backup plan.

So, is it possible to get the PPID by giving a PID number? getppid(2) can only get the PPID of current process so it's not helpful in this situation.

Any idea? Thank you.

yegle
  • 5,795
  • 6
  • 39
  • 61
  • 1
    Failing access to a lib, you can always read `/proc/$pid/status` where `$pid` is, of course, the PID you're interested in. Look for the line prefixed by "PPid:" – Nathan Ernst Jul 25 '13 at 20:15

1 Answers1

1

I think you can use get_proc_stats function to do this. But you need to install the libproc-dev library.

Here is an example :

proc_t p_info;
get_proc_stats(pid_num, &p_info);
int parent_pid = p_info.ppid;
Junior Dussouillez
  • 2,327
  • 3
  • 30
  • 39