[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: 100% cpu with: while true ;do read < /dev/null ;done
From: |
Pierre Gaston |
Subject: |
Re: 100% cpu with: while true ;do read < /dev/null ;done |
Date: |
Thu, 22 Oct 2009 09:08:15 +0300 |
On Thu, Oct 22, 2009 at 12:15 AM, Jo King <jokiiii@yahoo.co.uk> wrote:
> Configuration Information [Automatically generated, do not change]:
> Machine: i686
> OS: linux-gnu
> Compiler: gcc
> Compilation CFLAGS: -DPROGRAM='bash' -DCONF_HOSTTYPE='i686'
> -DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i686-pc-linux-gnu'
> -DCONF_VENDOR='pc' -DLOCALEDIR='/usr/local/share/locale' -DPACKAGE='bash'
> -DSHELL -DHAVE_CONFIG_H -I. -I. -I./include -I./lib -g -O2
> uname output: Linux puppypc 2.6.30.5 #1 SMP Tue Sep 1 15:48:26 GMT-8 2009
> i686 GNU/Linux
> Machine Type: i686-pc-linux-gnu
>
> Bash Version: 3.2
> Patch Level: 48
> Release Status: release
>
> Description:
> [See subject for test case.
> Many scripts sit in a loop asking for user input - if script is
> run in bg/without tty (by mistake) then high cpu usage results]
>
> Repeat-By:
> [while true ;do read </dev/null ;done]
>
> Fix:
> [ bash/the read code could
> detect there's no stdin and sleep for 1-2 seconds]
>
Script waiting for user input in the background will be stopped on read, and
it will not result in a busy loop.
A script that expects a tty should test it with something like:
if ! [ -t 0 ]; then echo "this script must be run in a terminal"; exit 1;fi
I too believe that the scripts must be fixed, not bash