getppid() of a process (not necessarily the one who calls getppid)
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
getppid() of a process (not necessarily the one who calls getppid)
Hello people!
I have a program in C that fork()'s a child, which in turn fork()'s another one. Is there some function to use in the last child to find the parent's ppid?
I am looking for a way to implement getppid(getppid()) which is not available through the C library since getppid() doesn't accept arguments..
I know can find the parents ppid in other ways, like store it in some variable etc, but I was wondering whether there exists such a function!
I dont think there is a function to get a parent's parent's PID, like a "getpppid()". I dont think it exists because there isnt really anything "special" about a parent's parent's PID. In other words, if there were a "getpppid()", why wouldnt there be a "getppppid", or a "getpppppid", etc. (of course theres other ways this could have been implemented). I think you would have to go with your other method, such as passing the parent's PID to its first child, which passes that same value to its new child.
Nadroj, you missed the point.. I was not looking for a getpppppppppppid() etc, I was looking for a getppid(foo) where foo is ANY current process' PID.. and I would simply use the PID of getppid(). Anyways!
Thank you both, 'specially Hko, this is what I was looking for.
Best regards!
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.