简体   繁体   中英

How to get the Parent Process ID by giving a Process ID in Linux using C/C++?

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.

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM