home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.sys.hp:9297 comp.unix.questions:10081 comp.unix.misc:3232
- Newsgroups: comp.sys.hp,comp.unix.questions,comp.unix.misc
- Path: sparky!uunet!utcsri!helios.physics.utoronto.ca!alchemy.chem.utoronto.ca!system
- From: system@alchemy.chem.utoronto.ca (System Admin (Mike Peterson))
- Subject: Re: Pls help: Misc questions
- Message-ID: <1992Aug14.180857.3791@alchemy.chem.utoronto.ca>
- Organization: University of Toronto Chemistry Department
- References: <1992Aug14.100417.23395@hp9000.csc.cuhk.hk>
- Date: Fri, 14 Aug 1992 18:08:57 GMT
- Lines: 38
-
- In article <1992Aug14.100417.23395@hp9000.csc.cuhk.hk> a866700@hp9000.csc.cuhk.hk (Wong Siu To) writes:
- >
- >I also want to know how can I determine whether a process (say, "sh") is
- >a background job or an interactive one. I submit jobs to a batch queue
- >(managed by NQS, a batch job managing system) which acts as if the user
- >logs in the system before executing the job. I don't want several
- >commands in the .profile to be executed in this situation. I hope that
- >the determination can be made somewhere in the process (probably a shell
- >script) itself, without the help of any external program.
-
- You can try the 'tty -s' command, but that doesn't always work (it will
- always be true for every shell run under a login shell, even if you
- put it into the background and logout), but this method is probably OK
- for use in the .profile itself.
-
- The method we are using in the .kshrc (which is run for every ksh)
- at the moment is:
-
- if [ "$LEVEL" = "" ]; then
- let "LEVEL = 0"
- fi
- if [ "$PS1" != "" -a "$LEVEL" = "0" ]; then
- interactive=yes
- else
- interactive=no
- fi
- let "LEVEL = $LEVEL + 1"
- export LEVEL
-
- (do this before you set the prompt to something other than the null
- string). This method works by empirical observation, and could be
- broken at any time by HP. A reliable method to do this is ABSOLUTELY
- REQUIRED, though a better solution would be for HP to fix their
- brain-damaged 'stty' command to not cause the shell to abort/hang
- when not run in an interactive shell.
- --
- What are the chances that any computer system will ever "work" properly?
- ... and Slim just left town. -*- Mike Peterson, SysAdmin, U/Toronto Chemistry
-