get process id
Brian K. White
brian at aljex.com
Mon Oct 11 16:02:02 PDT 2004
Bob Stockler wrote:
> I don't know whether I misunderstood all of the responses or
> perhaps the originating post in this thread, but . . .
>
> I thought the original question was, to the effect, "How do I
> get the PPID of a filePro process?".
>
> And, it seems to me that all of the responses concerned ways
> to return the PPID of a program called by the USER command,
> which would be the PID of the filePro process and not its PPID.
>
> With that in mind I wrote a filePro processing table that writes
> a KornShell or Bash script (Bourne won't cut it), then uses the
> USER command to get the PPID of the current process.
>
> The shell script uses AWK to scan the output of "ps" to find a
> line where the PID is the PPID of the script. It confirms it
> by also matching the filePro program name and File name (which
> is probably overkill). Here's the script it writes:
>
> #!/bin/ksh
> read fPprog fPfile ; ps -ef |
> awk -v PID="$PPID" -v fPprog="$fPprog" -v fPfile="$fPfile" '
> { if ($2==PID && $8==fPprog && $9==fPfile){print $3;exit} }'
>
> Here's the table that writes it and executes with USER:
>
> 1 Then: end
> 2 Then: declare PPID, fPprog, fPfile, UserPgm, Handle(8,.0),
> Misc, Cnt(3,.0)
> @MENU If:
> 3 Then: ' Get the PPID of the current filePro process
> 4 Then: fPprog = @CMDLINE["1"] ; fPfile = @CMDLINE["2"]
> 5 Then: UserPgm = "/tmp/get_ppid" ; gosub RiteIt
> 6 Then: USER get_ppid = /tmp/get_ppid
> 7 Then: get_ppid = fPprog < fPfile ; PPID = get_ppid ; close
> get_ppid ; Cnt = remove(UserPgm)
> 8 Then: show PPID ; wk = waitkey ; exit
> RiteIt If: exists("/bin/ksh") eq "1"
> 9 Then: Misc = "#!/bin/ksh"
> If: NOT RiteIt
> 10 Then: Misc = "#!/bin/bash" ' assume "ksh" or "bash" exists
> 11 Then: Handle = open(UserPgm,"c0tw") ; gosub RiteIt1
> 12 Then: Misc = "read fPprog fPfile ; ps -ef |" ; gosub RiteIt1
> 13 Then: Misc = "awk -v PID=\"$PPID\" -v fPprog=\"$fPprog\" -v
> fPfile= \"$fPfile\" '" ; gosub RiteIt1
> 14 Then: Misc = "{ if ($2==PID && $8==fPprog &&
> $9==fPfile){print $3; exit} }'" ; gosub RiteIt1
> 15 Then: Cnt = close(Handle) ; system "chmod ug=rwx" < UserPgm ;
> return RiteIt1 If:
> 16 Then: Cnt = writeline(Handle,Misc) ; return
>
> And here it is to cut and paste (if you want to play with it):
>
>>> end:
>>> declare PPID, fPprog, fPfile, UserPgm, Handle(8,.0), Misc,
>>> Cnt(3,.0):
> @MENU::' Get the PPID of the current filePro process:
>>> fPprog = @CMDLINE["1"] ; fPfile = @CMDLINE["2"]:
>>> UserPgm = "/tmp/get_ppid" ; gosub RiteIt:
>>> USER get_ppid = /tmp/get_ppid:
>>> get_ppid = fPprog < fPfile ; PPID = get_ppid ; close get_ppid ; Cnt
>>> = remove(UserPgm):
>>> show PPID ; wk = waitkey ; exit: RiteIt:exists("/bin/ksh") eq
>>> "1":Misc = "#!/bin/ksh": NOT RiteIt:Misc = "#!/bin/bash" ' assume
>>> "ksh" or "bash" exists: Handle = open(UserPgm,"c0tw") ; gosub
>>> RiteIt1:
>>> Misc = "read fPprog fPfile ; ps -ef |" ; gosub RiteIt1:
>>> Misc = "awk -v PID=\"$PPID\" -v fPprog=\"$fPprog\" -v
>>> fPfile=\"$fPfile\" '" ; gosub RiteIt1: Misc = "{ if ($2==PID &&
>>> $8==fPprog && $9==fPfile){print $3;exit} }'" ; gosub RiteIt1:
>>> Cnt = close(Handle) ; system "chmod ug=rwx" < UserPgm ; return:
> RiteIt1::Cnt = writeline(Handle,Misc) ; return:
>
> Bob
I tried that a few years ago as part of a showlock scheme. (Well, I hit a
snag and abandoned the approach long before it got quite as sophisticated as
above)
Under Linux, ps refused to run in a shell spawned by a suid program.
The site where I needed this ran linux for another year after that and no
one else really needed it and by the time that site switched to sco we had
long since abandoned the approach and didn't need it anymore and so I just
never got around to even trying out the idea under sco.
There was a discussion of the whole thing here and various ideas were kicked
around, mostly things that were too linux-specific for my taste, from
hacking the ps source to perusing the /proc tree. Although we were trying to
solve a linux-only problem, I didn't want to bother writing stuff that would
only work on linux (which, linux being linux, would probably end up not even
working on other versions or distributions of linux), which was proved out
by the fact that a year later they migrated to sco, and then even further to
sun.
The OP in this discussion really waned the PID of the filepro process, which
the PPID of a user command gives.
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