LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 10-25-2009, 01:34 PM   #1
ksames
LQ Newbie
 
Registered: May 2005
Location: Athens,Greece
Posts: 5

Rep: Reputation: 0
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!

Thanks in advance!
 
Old 10-25-2009, 01:50 PM   #2
nadroj
Senior Member
 
Registered: Jan 2005
Location: Canada
Distribution: ubuntu
Posts: 2,538

Rep: Reputation: 58
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.
 
Old 10-25-2009, 01:57 PM   #3
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,523

Rep: Reputation: 92
See this thread: http://www.linuxquestions.org/questi...rocess-276839/

And this seems to be for OSX, but might work as well for linux:
http://www.objectpark.net/parentpid.html

Last edited by Hko; 10-25-2009 at 02:00 PM.
 
Old 10-25-2009, 02:04 PM   #4
ksames
LQ Newbie
 
Registered: May 2005
Location: Athens,Greece
Posts: 5

Original Poster
Rep: Reputation: 0
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!
 
Old 10-25-2009, 02:52 PM   #5
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: Slackware64 13.37, Kubuntu 10.04
Posts: 2,831

Rep: Reputation: Disabled
How exactly do programs like ksysguard give you a process tree? That might be worth looking into.
Kevin Barry
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
want to make Log of system calls per process running on the machine sudhansu Linux - Kernel 6 11-17-2011 05:04 PM
how the get the process state using System calls. rheosiva Linux - General 0 04-01-2009 11:44 AM
process ,threads and system calls raedbenz Linux - Newbie 16 07-15-2008 01:30 AM
run process in background using system calls indian Programming 2 08-10-2004 06:03 PM
getppid question for BSD users concoran *BSD 1 08-05-2002 02:59 AM


All times are GMT -5. The time now is 03:49 PM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration