[Top][All Lists]

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

Re: 100% cpu with: while true ;do read < /dev/null ;done

From: Jan Schampera
Subject: Re: 100% cpu with: while true ;do read < /dev/null ;done
Date: Thu, 22 Oct 2009 07:10:33 +0200
User-agent: Mozilla-Thunderbird (X11/20090707)

Jo King schrieb:

> Fix:
>       [ bash/the read code could
>  detect there's no stdin and sleep for 1-2 seconds]

If you consider this as a bug, the bug is not in Bash (but in the

In short you request that read should wait a second, once it got a
end-of-file signalled, I don't think this is the way to 'fix' this
'bug'. It has far too many side effects or impacts to other uses of
read. Fix your application instead, query the exit code of read
(non-zero on EOF, timeout or error) and insert a conditional sleep yourself.

By the way (not really serious, but it fits): A CPU constantly below
100% is wasted money ;-)


reply via email to

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