ProcessID in *nix
Fairlight
fairlite at fairlite.com
Wed Jun 23 09:35:27 PDT 2004
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?
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}'`
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.
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.
mark->
--
Bring the web-enabling power of OneGate to -your- filePro applications today!
Try the live filePro-based, OneGate-enabled demo at the following URL:
http://www2.onnik.com/~fairlite/flfssindex.html
More information about the Filepro-list
mailing list