Lee writes:
> Mark Castoe <[log in to unmask]> wrote:
> > I am working on an application which will run under both the MPE CI and
> > the POSIX shell. I need to be able to determine whether or not the app
> > has been launched under the shell. Is there an easy way to do this? I
> > have considered using HPFOPEN to open a file with an HFS filename and
> > checking to see if it fails.
>
> Look at either AIFPROCGET or PROCINFO which will return the PIN of the
> processes father and then the program file name which you can then compare
> to CI.PUB.SYS or SH.HPBIN.SYS.
Unfortunately, that doesn't help much if you're running under something
else! (E.g., CI -> QEDIT -> FOO (your program))
or (sh -> ??? -> FOO)
For a trivial check, which only says "you're under the CI" if you are
indeed the top-level process in the session, try:
Pascal:
const
ccG = 0;
ccL = 1;
ccE = 2;
var
i_am_under_ci : boolean;
parent_pin : shortint;
...
Function father : shortint; intrinsic;
...
parent_pin := father;
if ccode = ccG then
i_am_under_ci := true
else
i_am_under_ci := false; {well, we aren't the top-level child}
This works because, according to CSEQ, father() returns a condition
code as follows:
CSEQ [2.1] - LPS Toolbox [A.01q] (c) 1995 Lund Performance Solutions
Function FATHER := pin : UInt16 {R28}
{ CCE: parent is user process }
{ CCG: parent is job/session main (CI) process }
{ CCL: parent is system process }
Otherwise, to do it "right", you'd need pseudo-code like:
i_am_under_ci := true; {initial assumption}
pin := father;
loops := 0;
while not done do
loops := loops + 1;
get program name (pin) <--- via PROCINFO, probably
if name = "CI.PUB.SYS" then
done := true;
i_am_under_ci := true;
else if name = "SH.HPBIN.SYS" then
done :+ true;
i_am_under_ci := false;
else
begin
pin := parent of pin; <--- via PROCINFO, probably
if pin <= 1 then <--- run off end? (shouldn't happen)
done := true;
if loops > 9999 then <--- prevent bug from causing inf loop
done := true;
end;
Also, what answer do you *want* if the process tree is:
CI
sh
CI
???
foo (your program)
You may want to specify *why* you want to determine your environment!
If it's because you're writing a C program, and want to be able to
handle open-old-file requests in a friendly manner (e.g., user
enters "fum" ... if under CI, you want to open ./FUM, if under
the shell, you want to open ./fum) ... that's relatively easy.
If the file name doesn't start with "/" or "./", and you're
using FOPEN/HPFOPEN do:
1) try opening as given
2) if that fails, put "./" in front, and try opening it again
3) if that fails, complain to user: no such file
if you're using fopen() (from POSIX C library), do:
1) try opening as given
2) if filename has any periods in it (e.g., "fum.fie.foe"),
extract and convert to MPE style: /FOE/FIE/FUM
and try again.
If you're opening a NEW disk file based on user input, then it's
a harder task :)
--
Stan Sieler [log in to unmask]
http://www.allegro.com/sieler.html
|