ProcessID in *nix

Fairlight fairlite at fairlite.com
Wed Jun 23 12:47:12 PDT 2004


With neither thought nor caution, Jay Ashworth blurted:
> 
> 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?

Fair enough.  Just curious.

> > 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...

Hmmm.  I hadn't thought about that entirely.  Well, it's relatively easy to
modify the perl to grab the PPid of the secondary parent, if you can rely
on linux's /proc.  No big deal:

#!/usr/local/bin/perl
#
# fpgetcrpid - Get *clerk or *report PID assuming USER uses system() and
# invokes a subshell between the actual script and this program.
#
# Use from USER command.
#
$ppid = getppid();
open(STATUS,"</proc/${ppid}/status") or print("Could not open status file.\n"),exit(1);
@lines = <STATUS>;
close(STATUS) or print("Could not close status file.\n"),exit(2);
@ppids = grep(/^PPid:/, at lines);
chomp($m_ppid = shift(@ppids));
$m_ppid =~ s/^PPid:\s*//;
print("${m_ppid}\n");
exit;

While you -can- make a one-liner out of that, I wouldn't necessarily
recommend it.  :)

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