bug-bash
[Top][All Lists]
Advanced

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

read with very small timeout sometime hand on stdin


From: felix
Subject: read with very small timeout sometime hand on stdin
Date: Wed, 28 Oct 2020 12:06:01 +0100
User-agent: Mutt/1.10.1 (2018-07-13)

Configuration Information:
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -g -O2 -Wno-parentheses -Wno-format-security
uname output: Linux medium 4.19.0-9-amd64 #1 SMP Debian 4.19.118-2 (2020-04-29) 
x86_64 GNU/Linux
Machine Type: x86_64-pc-linux-gnu

Bash Version: 5.1
Patch Level: 0
Release Status: rc1

Description:
    Trying to see limits of timeout with `read -t`, I encounter strange
    and unconstant result: sometime `read -t .000001` don't consider
    timeout, when running fastly multiple time.

    From help:
      -t timeout time out and return failure... may be a fractional...
         ... exit status is greater than 128 if the timeout is exceeded.

Repeat-By:

    $ read -t .0000001 foo ; echo $?
    1

    $ read -t .000001 foo ;echo $?
    142

    Ok, then microsecond seem to by smallest value.

    $ tot=0; for i in {1..100} ;do
        rt=${EPOCHREALTIME//.}
        read -t .000001 foo
        ((tot+=${EPOCHREALTIME//.}-rt))
        sleep .002
      done; echo ${tot:: -2}.${tot: -2}

If this not end after 1 second, hit <return>, wait 1 second
and repeat (and count); You won't hit 100x <return>!
Maybe this return correctly after ~0.2 seconds. If yes, try
again. Mostly I have to hit 3 - 8x for this 100 loop test.

    $ tot=0; for i in {1..100} ;do
        rt=${EPOCHREALTIME//.}
        read -t .000001 foo
        ((tot+=${EPOCHREALTIME//.}-rt))
        done < <(
            while :;do sleep 1;echo;done
        );echo ${tot:: -2}.${tot: -2}

Correct output must be < 1000


-- 
 FĂ©lix Hauri  -  <felix@f-hauri.ch>  -  http://www.f-hauri.ch



reply via email to

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