get process id

Bob Stockler bob at trebor.iglou.com
Mon Oct 11 11:04:02 PDT 2004


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

-- 
Bob Stockler - bob at trebor.iglou.com
Author: MENU EDIT II - The BEST Creator/Editor/Manager for filePro User Menus.
Fully functional (time-limited) demos available by email request (specify OS).


More information about the Filepro-list mailing list