[Top][All Lists]

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

Re: Bash Builtin Read Function Hang

From: Chet Ramey
Subject: Re: Bash Builtin Read Function Hang
Date: Mon, 19 Apr 2021 18:38:45 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.9.1

On 4/19/21 3:48 PM, Mike Whitton wrote:

Bash Version: 5.0
Patch Level: 18
Release Status: release

         I have a script that I wrote in bash and have been using for
years.  It worked fine up until I updated bash to the latest version from
IBM, 5.0 Patch 18.  Previously I ran it without issue on 5.0 with no
patches.  What is happening is when I run a command (such as 'ls -al /etc')
with a while loop and read the line it works fine sometimes but sometimes
it does not.  When it does not work fine it hangs once it reaches the end
of the input that is being fed into the loop, it should see the EOF and
automatically terminate but it does not.  This previously worked fine 100%
of the time.

I trussed the output and this is what we are getting when we reach the end
of the line:

      kfcntl(2, F_GETFL, 0x0FFFFFFFFFFFFFE8)          = 67110914
      kioctl(0, 22528, 0x0000000000000000, 0x0000000000000000) Err#25 ENOTTY
      lseek(0, 0, 1)                                  Err#29 ESPIPE
      kread(0, "\t", 1)               (sleeping...)

When it is working the kread function does not sleep, it just moves onto
the next iteration in the while loop.


        Here is a sample piece of code to recreate the issue:

       SGLIST=("testfile1" "testfile1" "testfile1" "testfile1")       # List
of storage groups

       for sg in ${SGLIST[@]}
               while read line
                       echo $line
               done < <(ls -al /etc 2>&1)

This particular sample code reliably fails every time.  The piece of code I
have written fails with the same basic setup one out of every four times or

I suspect this has something to do with reaping FIFOs when the writing
process exits, but I can't reproduce it on macOS or a couple different
Linux versions.


``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    chet@case.edu    http://tiswww.cwru.edu/~chet/

reply via email to

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