bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: bug in force_interactive handling


From: Chet Ramey
Subject: Re: bug in force_interactive handling
Date: Sun, 01 Jan 2012 22:15:43 -0500
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:8.0) Gecko/20111105 Thunderbird/8.0

On 12/30/11 5:36 AM, Stas Sergeev wrote:
> Hello Chet, thanks for your patch file.
> It is slightly broken, attached is the fixed version
> of your patch.
> BUT: it solves only half of the bug.

Thanks, I inadvertently left that part of the patch out of what I sent.

> Please check it yourself, here's the script:
> ---
> #!./bash -i
> set -m; cat
> echo Finished!
> while :; do jobs; sleep 2; done
> ---
> 
> Run this script, then do
> killall -STOP cat
> You'll start seeing the output of "jobs" every 2 seconds,
> and the cat is marked "Stopped".
> Then do
> killall -CONT cat
> Nothing changes, the cat is still listed as stopped.
> Then bash will run terminate_stopped_jobs() on it. :(
> Do you know how to fix also this?

I don't get this behavior; after the patch I get the `cat' listed as
running until it gets rescheduled, which depends on the kernel and
the scheduler.  (I have to wait much longer for it to be rescheduled
and run on Mac OS X than Linux, for instance.)  Let's talk through the
behavior you'd like to see happen.

If you send the `cat' a SIGCONT it will end up running in the background:
its process group id will never be the same as the terminal's.  Sending
SIGCONT from another process will not set the terminal's process group to
cat's pgid.  That's why things like `fg' and `bg' are shell builtins --
so the shell can multiplex the terminal's process group among its children.

Because cat is running as a background job, it will get SIGTTIN from the
kernel as soon as it runs and attempts to read from the terminal (and, in
fact, when you look at it with `ps', the status is `T').

Since the cat is stopped, and will be sent SIGTSTP every time it reads
from the terminal no matter how many times it gets SIGCONT, chances are
pretty good that bash will find it stopped, report it as such, and
terminate it before exiting.

What about this would you like to change?

Chet
-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    address@hidden    http://cnswww.cns.cwru.edu/~chet/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]