[GLLUG] read -t 1 hangs on reading from an unconnected pipe.

Fred Youhanaie fly at anydata.co.uk
Thu Jan 7 10:15:46 UTC 2021

Hi Tim

Happy New Year to you too.

This is expected behaviour with pipes. The first process to open the pipe will block until the other end opens too.

You confirm with the following - the first echo does not happen until the shell itself has completed the open (</tmp/pipe)

	time { echo hello ; read -t 1 ;} </tmp/pipe

You can try something like this and drop it in the background before the read

	sleep 999 >/tmp/pipe &


On 07/01/2021 09:31, Tim Woodall via GLLUG wrote:
> Happy new year to all.
> I didn't expect this:
> tim at einstein(9):~$ mkfifo /tmp/pipe
> tim at einstein(9):~$ time read -t 1 </tmp/pipe
> real    0m13.514s
> user    0m0.000s
> sys     0m0.000s
> tim at einstein(9):~$
> in another terminal I did:
> tim at einstein(10):~$ echo >/tmp/pipe
> I had expected the read to time out after one second.
> Is there any way to make read always timeout, even if the other end of
> the pipe isn't connected?
> Tim.

More information about the GLLUG mailing list