Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: tostop && TTOU



On 12/12/99, Bart Schaefer said:
>On Dec 12, 11:22am, Danny Dulai wrote:
>} Subject: tostop && TTOU
>}
>} I'm trying to get TTOU generated in a script, without forcing the user to
>} stty tostop in the terminal controling shell.
>
>You're going to have to give a few more details about the script.
>
>In order to get a TTOU, the script itself must run in the background, or
>it starts a background job; which one is it?
>
>I played with this a bit, and if I run a script in the background which
>attempts to do anything with stty, it gets TTOU even when the original
>stty settings include -tostop.  I can only change the settings with a
>foreground job.

(~) % cat p
stty tostop

function o() {
    # so blank function doesnt complain
    foo=bar
}

trap o TTOU

helu=0
while :; do
        sleep 1
        echo $helu
        helu=$(($helu+1))
done

return 0


(~) % stty
speed 9600 baud; line = 0;
erase = ^H;
-brkint -imaxbel
tostop
(~) % /usr/local/src/zsh-3.1.5/Src/zsh p
0
1

zsh: 6096 suspended  /usr/local/src/zsh-3.1.5/Src/zsh p
(~) % bg
[1]  + continued  /usr/local/src/zsh-3.1.5/Src/zsh p
(~) % fg               <--- after waiting a few seconds
[1]  + running    /usr/local/src/zsh-3.1.5/Src/zsh p
6
7
8


Ok, thats the desired behavior.  The write() to stdout stops happening becuase
the SIGTTOU interrupts it i assume. But:


(~) % stty -tostop
(~) % /usr/local/src/zsh-3.1.5/Src/zsh p
0
1

zsh: 6112 suspended  /usr/local/src/zsh-3.1.5/Src/zsh p
(~) % bg
[1]  + continued  /usr/local/src/zsh-3.1.5/Src/zsh p
(~) % 2
3
4
5
6


The stty tostop in the begining of the script seems to have done nothing :(

This is all using zsh 3.1.6-pws-11.

What I'm trying to do is find out if the script is running in the background or
in the foreground. Another solution (other than TTOU) is to use TTIN, but I
can't figure out a way to do a nonblocking read from stdin from within a zsh
script. The TTIN solution is pretty easy if that read functionality exists,
because you dont have to mess with tty settings to get a TTIN.

-- 
___________________________________________________________________________
Danny Dulai                                           Feet. Pumice. Lotion.
http://www.ishiboo.com/~nirva/                            nirva@xxxxxxxxxxx



Messages sorted by: Reverse Date, Date, Thread, Author