foreground/background (was Re: What "isatty"?)
Chris Torek
chris at mimsy.UUCP
Tue May 23 14:18:34 AEST 1989
In article <SCP.89May22172024 at raven.lanl.gov> scp at raven.lanl.gov
(Stephen Pope) writes:
>Well, as long as we're on the subject, I'm curious in general how
>a process can know whether it is in the foreground or background.
`foreground' and `background' mean different things in different
shells. In sh:
$ foo &
runs `foo' with input connected to /dev/null---read-select will say
`yes' (if you have select) and reading will find EOF. In csh, with
job control,
% foo &
[1] 1234
runs `foo' with its process group differing from that of its control
terminal. (If input has not been redirected, it comes from the
control terminal.) So: if the input is not a terminal, the process
is running in background or has had its input redirected. If the
input is a terminal, the process is in the foreground if and only if
its process group matches that of the control terminal.
A process never moves from foreground to background without warning:
it must first stop. But it is possible (and not uncommon) for a
process to move from background to foreground:
% %f
foo
A foreground process can tell when it loses control, but a background
process can only poll to see if it has gained it. (To make this more
efficient, it might do this only when select-for-read is true.)
--
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain: chris at mimsy.umd.edu Path: uunet!mimsy!chris
More information about the Comp.unix.wizards
mailing list