1

I have a C++ program where I'm trying to follow the parent process ID chain backward (parent of a parent, parent of a parent of a parent, etc...). The first step is easy - getppid() returns the process id of the immediate parent. After that, I'm stumped.

I'm currently developing in linux, and a workaround is to screen-scrape the output of the proc command. That works, but it's not portable (Macs either don't have proc or it's not universal).

Any ideas?

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
user3195869
  • 75
  • 1
  • 6
  • 1
    Does this help? https://stackoverflow.com/a/1525673/2357085 – w08r Oct 31 '20 at 20:26
  • What kind of communication are you allowed/willing to have between the processes? Pipes? FIFO's? File? – kyriakosSt Oct 31 '20 at 20:28
  • @kyriakosSt seems to be thinking the processes are of the OP's making. Are they, user3195869? – erik258 Oct 31 '20 at 20:37
  • considering the OP is able to make use of the `getppid()` call, it certainly seems that the intent is on user-coded processes. The output of the `proc` command is mentioned as a workaround – kyriakosSt Oct 31 '20 at 20:53
  • 1
    Why do you need to search for the pid? Such a solution is clunky to begin with, and as you've discovered, non-portable. For best portability, use IPC mechanisms to communicate between processes. – rustyx Oct 31 '20 at 21:00

0 Answers0