[Top][All Lists]

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

Re: Fwd: read -t 0 fails to detect input.

From: Chet Ramey
Subject: Re: Fwd: read -t 0 fails to detect input.
Date: Fri, 20 Dec 2019 10:24:56 -0500
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:60.0) Gecko/20100101 Thunderbird/60.9.1

On 12/19/19 3:07 PM, Bize Ma wrote:
> To: Chester Ramey <address@hidden>
> On thu., dec. 19 of 2019 at 12:40, Chet Ramey (<address@hidden>) wrote:
>> On 12/18/19 6:40 PM, Bize Ma wrote:
>>>>> The exit status is 0 if input is available on the specified file
>>>   descriptor, non-zero otherwise.
>> Bash-5.0 uses select/FIONREAD to determine whether or not there is input
>> available on the file descriptor. Those don't wait; they test whether or
>> not there is input on the specified file descriptor at the point they are
>> called.
> Thanks Chet.
> Could you please comment about this assertions:

>From an eight-year-old message?

>  1.-   bash will either do a select() or an ioctl(FIONREAD), or neither of
> them, but not both, as it should for it to work. read -t0 is broken. Do not
> use it – mosvy.

It doesn't matter. You can use both and not change the inherent race
condition at all. The only difference in their behavior is what happens
at EOF (select returns success, ioctl(FIONREAD) returns failure). If you
want to see whether or not there is input on stdin, read stdin.

If you want to test whether a write-only file descriptor that you opened is
ready for reading, it's programmer error.

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

reply via email to

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