It is currently Tue, 17 May 2022 19:24:08 GMT



 
Author Message
 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   
 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   
 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   
 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   
 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   
 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   
 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   
 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   
 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   
 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   
 Who's my grandparent?
And many vendors don't provide a /proc at all.

                       Chris Mattern



 Sat, 07 Jun 2003 06:21:36 GMT   
 
   [ 11 post ] 

Similar Threads

1. How to set up a computers with GNU/Linux for grandparents

2. Returning to grandparent function (ksh)

3. "rm: can't unlink 'files'",can't delete files

4. Error: 'Can't load module '/kernel': no such file or directory

5. 'can't load 'kernel'

6. mmap'd file ends with '!', copy doesn't

7. ''pure'' executables

8. Programming with 'nap', 'usleep'

9. alpha sort: 'sed'/'awk'?

10. Attempting to load object 'w2quad01.so', with entry 'W2QUAD01', error


 
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software