home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.unix.shell:3515 comp.sys.hp:9407
- Path: sparky!uunet!munnari.oz.au!mtiame!marvin!tony
- From: tony@marvin.jpl.oz (Tony Sanderson)
- Newsgroups: comp.unix.shell,comp.sys.hp
- Subject: ksh bk-gnd behaviour
- Message-ID: <891@marvin.jpl.oz>
- Date: 19 Aug 92 07:21:13 GMT
- Reply-To: tony@marvin.jpl.oz (Tony Sanderson)
- Distribution: world
- Organization: Boral Elevators, Melbourne
- Lines: 64
-
-
- With ksh (HP-UX on a new '720), I find that scripts which successfully
- used either the "[ -t 0 ]" or "tty" commands on our old system to detect
- that the script has been backgrounded no longer work. I'm told (by HP)
- that this is a result of the job control feature (which is absent in the
- ksh on our older machines), causing stdin to remain attached to the user
- terminal when a script is backgrounded. Suggestion was to insert a !sh
- command at the top of every script to ensure processing by the bourne
- shell. I suppose I could do that, but it seems like a pretty pathetic
- "solution" to me (esp as we don't use job control around here anyway!).
-
- They suggested I read "The Korn Shell" by Dave Korn - I've just flicked
- thru that for an hour or so, but I'm none the wiser! Have I just found
- a major deficiency or limitation of ksh, or is this an HP implementation
- quirk? I find it difficult to believe that there's no simple way for a
- script to tell that it's running in the background! (Incidentally, both
- tests work fine where the script gets installed in a pipe.)
-
- A test script (for anyone who may be interested) using the aforementioned
- commands is as follows:
-
- ----------------------------- snip 'ere ---------------------------------
- # Test for foreground v/s background execution of this script, and its
- # ability to detect same.
- # To simplify things (with stdout blocking or whatever), writes result
- # to file "yy":
-
- echo 'Result via "test -t 0", method (a): \c' > yy
-
- if [ -t 0 ]
- then
- echo "Terminal attached" >> yy
- else
- echo "Terminal not attached" >> yy
- fi
-
- echo 'Result via output of tty command, method (b): \c' >> yy
-
- if [ "`tty`" = "not a tty" ]
- then
- echo "Terminal not attached" >> yy
- else
- echo "Terminal attached" >> yy
- fi
-
- # End
- ----------------------------- and 'ere too ------------------------------
-
- Any suggestions?
-
- PS: had a look thru the FAQ's for ...unix.shell about a month ago and saw
- no reference to it there, hence the post.
-
- PS 2: Just in case anyone reading this did answer another recent post re
- methods for an efficient 16 bit integer divide-by-5 method (which I'm
- looking for), we just lost the last 2 weeks news around here as a result
- a disc crash - so could u re-post!
-
- -----------------------------------------------------------------------------
-
- Tony Sanderson Boral Elevators, Melbourne, Australia
- e-mail tony@marvin.jpl.oz.au
-
- -----------------------------------------------------------------------------
-