am I in background?
Guy Harris
guy at sun.uucp
Fri Nov 29 07:25:27 AEST 1985
> One common test is to check the status of SIGINT, because most
> shells set it SIG_IGN for background jobs. I think that this
> also holds for the 4.2 csh IFF the job was started in the background;
> STOPping the sending the job into the background isn't the same.
No, it doesn't hold for the C shell. The only reason that background jobs
1) have their input redirected to /dev/null and 2) ignore SIGINT is that,
without job control, any attempt by them to read from the terminal will
conflict with the foreground job and any signals sent by hitting your
interrupt key will go to them as well as to the foreground job. Since job
control permits you to prevent background jobs from reading from their
control terminal (they stop if they try) and causes signals from the
keyboard to be sent *only* to the foreground job, and since you may want to
move a job from the background to the foreground and permit it to read from
the terminal and get signals from the terminal, the C shell can't redirect
the input or ignore interrupts (and Ron Natalie's Bourne shell and probably
the Korn shell can't do this either).
There's no way to tell if you were run in the background that works with all
shells on all systems. Besides, if you have job control you may have been
in the background 10 minutes ago but may be in the foreground now. If you
need to know this, think harder about *why* you need to know this; you may
find that you don't really need to know it, or that it isn't really want you
need to know.
Guy Harris
More information about the Comp.unix.wizards
mailing list