ProcessID in *nix
Brian K. White
brian at aljex.com
Wed Jun 23 08:41:14 PDT 2004
Walter Vaughan wrote:
> I found a thread in 1999 that addressed this issue, but it related to
> getting the process ID of the parent.
>
> I *think* what I want is the process id number of the currently
> executing *clerk.
>
> Anyone got a snippet of how they got it? Not the shell, but the
> current running *clerk.
Probably by running a system() or user() and getting the parent from within
that.
The only time I tried to do that, the site happenned to be running linux and
linux refused to run "ps" from within a child of a suid program. doh! So I
just bagged the idea as not a viable approach and have dealt with uniqueness
in other ways since then.
Possibly it would work fine on sco. Almost certainly something somewhere
could be hacked in linux to allow it since everything in linux is
customizeable thanks to the source.
This command spits ack the parent process.
run it in a system command and it should provide the pid of the clerk that
ran it.
ps -eopid,ppid |awk -v P=$$ '{if($1 == P) print $2}'
Although it means using a temp file, I recommend using system rather than
user for this.
so it would look like:
@once if:
then: x=rand("-1") ; end
...
if:
then: et="/tmp/"{@qu{@fi{@rn{@id{rand()
if:
then: system "umask 0; ps -eopid,ppid |awk -v P=$$ '{if($1 == P) print $2}'
>"{et
if:
then: h=open(et,"rt") ; x=readline(h,p) ; x=remove(et)
if:
then: msgbox "Process ID is:" < pp {""
that would be the core of it but i'd add a little sanity checking to that in
production
Brian K. White -- brian at aljex.com -- http://www.aljex.com/bkw/
+++++[>+++[>+++++>+++++++<<-]<-]>>+.>.+++++.+++++++.-.[>+<---]>++.
filePro BBx Linux SCO Prosper/FACTS AutoCAD #callahans Satriani
More information about the Filepro-list
mailing list