[net.bugs.4bsd] csh/jobs funniness

tiberio@seismo.UUCP (Mike Tiberio) (02/21/85)

<>
Under csh if you have a job running in the background, jobs says running
and ps will give a stat of R indicating runnable. If you send the process
a signal 17 or 18 (STOP,TSTP) using kill, jobs will indicate the process
has stopped and ps will indicate T for stopped. So far everything is fine,
however if you restart the job using using kill -19 pid (or -CONT) the 
process does restart, ps will give a STAT of R, but jobs will indicate 
still stopped. This happens on both our VAX and SUN running 4.2bsd.
Any comments or solutions?

					seismo!tiberio

chris@umcp-cs.UUCP (Chris Torek) (02/22/85)

> ...if you have a job running in the background, jobs says running
> and ps will give a stat of R indicating runnable. If you send ...  a
> signal 17 or 18 (STOP,TSTP) using kill, jobs will indicate the process
> has stopped and ps will indicate T for stopped. ...  however if you
> restart the job using using kill -19 pid (or -CONT) the process does
> restart, ps will give a STAT of R, but jobs will indicate still
> stopped.

It's a ``feature''.  Ps reaches into the kernel and pulls out the per-
process data, thus gets the right answer.  Jobs relies on the C shell's
knowledge of what's going on.  Since ``kill'' is a built-in command,
the C shell *could* notice kill -CONT's and update its own information,
but you could still defeat it by running /bin/kill (or sending the signal
from another terminal).

When a process stops, its parent can find out by using the ``wait3''
system call.  However, there is no information given about restarted
processes.  Csh's ``bg'' and ``fg'' commands update the job status
when asked to continue a stopped job, but its ``kill'' command doesn't.
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 4251)
UUCP:	{seismo,allegra,brl-bmd}!umcp-cs!chris
CSNet:	chris@umcp-cs		ARPA:	chris@maryland

ed@mtxinu.UUCP (Ed Gould) (02/28/85)

> Under csh if you have a job running in the background, jobs says running
> and ps will give a stat of R indicating runnable. If you send the process
> a signal 17 or 18 (STOP,TSTP) using kill, jobs will indicate the process
> has stopped and ps will indicate T for stopped. So far everything is fine,
> however if you restart the job using using kill -19 pid (or -CONT) the 
> process does restart, ps will give a STAT of R, but jobs will indicate 
> still stopped. This happens on both our VAX and SUN running 4.2bsd.
> Any comments or solutions?
> 
> 					seismo!tiberio

There's no way for the shell to know that the job has been restarted,
unless it did the restart itself.  It knows that it was stopped,
because parents get notified of such events via a wait() call
(or variant).  Usually, it's safer to stop and start processes using
csh's builtins, since they will correctly deal with multiple
processes in a job.

(In case it's not clear how to restart a job in csh, use the "fg"
or "bg" builtins, e.g. "fg %5" to bring job #5 to the foreground.
"Fg" or "bg" without arguments will operate on the "current"
job, noted with a "+" in the output from "jobs".  There are also
synonyms:  "%n" == "fg %n",  "%n&" == "bg %n", etc.)

-- 
Ed Gould		    mt Xinu, 739 Allston Way, Berkeley, CA  94710  USA
{ucbvax,decvax}!mtxinu!ed   +1 415 644 0146