bug-bash
[Top][All Lists]
Advanced

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

Re: Strange behaviour on 'read' from a pipe


From: Lluís Batlle i Rossell
Subject: Re: Strange behaviour on 'read' from a pipe
Date: Mon, 2 Apr 2012 20:46:12 +0200
User-agent: Mutt/1.5.20 (2009-06-14)

On Mon, Apr 02, 2012 at 04:39:19PM +0200, Lluís Batlle i Rossell wrote:
> Trying to reproduce the race, I got rid of 'sleep', and expected this to never
> hang. But it hangs where I try. Should I submit this to LKML maybe?
> 
> I think it should not hang ever, but maybe I forecast something bad.
> -------------
> #!/var/run/current-system/sw/bin/bash
> 
> PIPE=/tmp/pipe
> 
> rm -f $PIPE
> mkfifo $PIPE
> 
> function spawn {
>     echo DONE > $PIPE
> }
> 
> spawn sleep 1 &
> 
> while true; do
>     echo reading
>     while read LINE < $PIPE; do
>         echo $LINE
>         spawn &
>     done
> done
> ---------------

Adding a 'sleep 0.1' before 'echo DONE' makes it hang very early in three linux
machines I tried. Let me know if you can reproduce it. Let me know if this helps
you reproduce the problem. Here again:

----------
#!/bin/sh

PIPE=/tmp/pipe

rm -f $PIPE
mkfifo $PIPE
set -x

spawn() {
    sleep 0.1
    echo DONE > $PIPE
}

spawn &

while true; do
    while read LINE < $PIPE; do
        echo $LINE
        spawn &
    done
done
-----------



reply via email to

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