ProcessID in *nix

Jay R. Ashworth jra at baylink.com
Wed Jun 23 09:59:01 PDT 2004


On Wed, Jun 23, 2004 at 12:35:27PM -0400, Fairlight wrote:
> On Wed, Jun 23, 2004 at 12:19:47PM -0400, after drawing runes in goat's blood,
> Jay Ashworth cast forth these immortal, mystical words:
> > > #!/usr/local/bin/perl
> > > # fpgetppid - to be used with USER
> > > print(getppid(),"\n");
> > > exit;
> > 
> > Isn't there a way to do that as a one-liner on the command line?  perl
> > -e or something?
> 
> Further, now that I've answered that with the solution, might I ask what
> advantage it has over having a tiny program sitting there, besides taking
> one less inode?

Well, my generic answer to this class of question is that any program
which can be self-contained, should be self-contained, because that's
one less item to break.  If you depend on the perl program being there,
and someone accidentally deletes it, then you're screwed. 

While I realize that that's a) a slippery slope, and b) an unlikely
occurrence, why tempt fate when you don't have to?

> And further still, for those that eschew perl, you can do this in linux
> with the following snippet of Bourne/bash/ksh:
> 
> echo `egrep ^PPid: /proc/$$/status |awk '{print $2}'`

Assuming you have /proc, yeah.

> I daresay it -may- be adapted to other /proc-based systems, but it depends
> on how /proc is locked down, and what format the output takes.  This
> -won't- work on Solaris 8, even though it has a /proc, simply because the
> [PID] directories aren't readable by users--even the user who owns the
> process, which seems rather silly on the face of it.

Hmmm...

> Of course, this spawns four children to do the same thing as the two
> children needed in perl (the counts are inflated by one each because fP
> uses system() rather than fork/exec), but some people just -don't- like
> perl for some reason, where they understand and adopt Bourne easily.
> Thought I'd offer the option, at least for linux.  Implementation on other
> platforms is left as an exercise to the developer. 

Hmmm...  Doesn't filePro's use of system guarantee that none of these
are going to work, since the PPID you'll get is the *shell* spawned by
system, rather than the dclerk...

Cheers,
--- jra
-- 
Jay R. Ashworth                                                jra at baylink.com
Designer                          Baylink                             RFC 2100
Ashworth & Associates        The Things I Think                        '87 e24
St Petersburg FL USA      http://baylink.pitas.com             +1 727 647 1274

                2004 Stanley Cup Champion Tampa Bay Lightning


More information about the Filepro-list mailing list