Author |
Message |
Steve Madin #1 / 11
|
 Who's my grandparent?
Okay, there exists a getpid() in a variety of programming languages, and shells, and there exists a getppid() to get the parent process ID in a variety of languages and shells. But how can I get my grandparent pid, in some way that is portable? The only thing I can think of is to read the ouput of a 'ps' command, because there doesn't seem to be any standard calls or commands that give me that. Ideally, it would be nice if there was some sort of getppid command that instead of just returning YOUR parent, would return the parent of a pid you give it as an argument. Again, I don't care if this is something in a shell or a more low-level language like C, I just want to know if anyone out there has seen some sort of a way to do this, in any language or any shell. I want to avoid 'ps' because it's flags differ so much from one UNIX to another, as does its output format.
|
Mon, 02 Jun 2003 15:51:13 GMT |
|
 |
Dan Merc #2 / 11
|
 Who's my grandparent?
In article <919u5h$ho...@news.doit.wisc.edu>,
Actually, thanks to XPG4, ps has actually converged. For instance, the same works for both HP-UX 10.x &11.x and Linux Red Hat 6.1 (under ksh): UNIX95=1 ps -p $PPID -o ppid= (don't forget the trailing "="). On some systems, xpg4 compliant utilities will be in a separate bin directory, /usr/xpg4/bin for example. -- Dan Mercer damer...@uswest.net
|
Mon, 02 Jun 2003 21:09:36 GMT |
|
 |
The.Central.Scrutinizer.wakaw.. #3 / 11
|
 Who's my grandparent?
On 14 Dec 2000 07:51:13 GMT, Steve Mading <madi...@baladi.bmrb.wisc.edu> wrote:
How about looking in the /proc directory? (or is this linux-centric?) -- Remove 'wakawaka' and 'invalid' to e-mail me. You can thank spammers for this inconvenience. I didn't do it! Nobody saw anything! You can't prove anything! -- bart
|
Tue, 03 Jun 2003 05:58:46 GMT |
|
 |
Steve Madin #4 / 11
|
 Who's my grandparent?
: On 14 Dec 2000 07:51:13 GMT, Steve Mading <madi...@baladi.bmrb.wisc.edu> wrote: :> :>I want to avoid 'ps' because it's flags differ so much from :>one UNIX to another, as does its output format. : How about looking in the /proc directory? (or is this linux-centric?) All /proc directory layouts are vendor-specific.
|
Tue, 03 Jun 2003 07:31:18 GMT |
|
 |
Steve Madin #5 / 11
|
 Who's my grandparent?
: Actually, thanks to XPG4, ps has actually converged. For instance, : the same works for both HP-UX 10.x &11.x and Linux Red Hat 6.1 (under ksh): : UNIX95=1 ps -p $PPID -o ppid= : (don't forget the trailing "="). On some systems, xpg4 compliant : utilities will be in a separate bin directory, /usr/xpg4/bin for : example. I'm afraid I have no idea what this XPG4 is. (There is no /usr/xpg4 in any of the unix system I have access to.)
|
Tue, 03 Jun 2003 07:33:06 GMT |
|
 |
Richard Howlet #6 / 11
|
 Who's my grandparent?
There isn't on SCO OpenServer 5 either but I thought I'd try it anyway. It works. Just try it. What systems are you going to be using this on? -- Richard Howlett mailto:rich...@howie.org.uk
|
Tue, 03 Jun 2003 07:45:12 GMT |
|
 |
The.Central.Scrutinizer.wakaw.. #7 / 11
|
 Who's my grandparent?
On 14 Dec 2000 23:31:18 GMT, Steve Mading <madi...@baladi.bmrb.wisc.edu> wrote:
Thanks for the heads up. Should I worry about changes w/ a specific vendor? (elinux on the etrax100 board in this case) -- Remove 'wakawaka' and 'invalid' to e-mail me. You can thank spammers for this inconvenience. I didn't do it! Nobody saw anything! You can't prove anything! -- bart
|
Tue, 03 Jun 2003 10:44:50 GMT |
|
 |
Paul D. Smit #8 / 11
|
 Who's my grandparent?
>> All /proc directory layouts are vendor-specific. n> Thanks for the heads up. Should I worry about changes w/ a n> specific vendor? (elinux on the etrax100 board in this case) Generally, yes. The Linux kernel (which is what you care about) has, can, and will continue to change the format of the contents of /proc files. They don't like to do it, but they aren't nearly as concerned about keeping backward-compatibility here as they are about getting a correct, usable interface. -- ------------------------------------------------------------------------------- Paul D. Smith <psm...@baynetworks.com> HASMAT--HA Software Methods & Tools "Please remain calm...I may be mad, but I am a professional." --Mad Scientist ------------------------------------------------------------------------------- These are my opinions---Nortel Networks takes no responsibility for them.
|
Tue, 03 Jun 2003 15:28:28 GMT |
|
 |
Dan Merc #9 / 11
|
 Who's my grandparent?
In article <91blbi$kj...@news.doit.wisc.edu>,
XPG4 is a standard. Some vendors use a separate directory path to hold the compliant function. Most just build the compliance in (like Linux and HP-UX 10/11) but some of those (HP-UX) rely on the UNIX95 env var being set (to any value) to trigger the new functionality. Under any circumstances, setting UNIX95 for the ps command does no harm. Check your man pages for the ps command and pay particular attention to the "Standards Compliance" section: Name ps - report process status ... Standards Compliance ps: SVID2, XPG2, XPG3, XPG4 Did you try the command to see if it works? There is no portable API for reading the process table. -- Dan Mercer damer...@uswest.net
|
Wed, 04 Jun 2003 02:01:33 GMT |
|
 |
Chris Matter #10 / 11
|
 Who's my grandparent?
You either have to parse "ps" (or /proc, which is even less portable) or have the parent process stash *its* PPID somewhere that the child can find it. Uh, *why* do you need a grandparent PID anyways? "Grandparents" have no particular relation to their "grandchildren" and there is not generally a need for a process to need this information, which is why there's no easy way to get it. Chris Mattern
|
Sat, 07 Jun 2003 06:20:07 GMT |
|
 |
Chris Matter #11 / 11
|
 Who's my grandparent?
And many vendors don't provide a /proc at all. Chris Mattern
|
Sat, 07 Jun 2003 06:21:36 GMT |
|
 |
|