Alex
Alex

Reputation: 1031

How to force all read workers consume fifo data?

Producer:

#!/bin/bash                                                                                                                   

/bin/rm ./queue
/usr/bin/mkfifo ./queue

./work.sh &
./work.sh &
./work.sh &
./work.sh &

for i in {1..100};do
    echo "1" > ./queue
done


wait
echo "FINISHED"

Consumer work.sh:

#!/bin/bash                                                                                                                   

while read line
do
    echo "$line $BASHPID"
done < ./queue
echo "FINISHED"

Usually only 3 workers consume data. 4th is blocked in reading fifo(open syscall), it gets no data at all. If I change

for i in {1..100};do

to

for i in {1..1000};do

all read workers consume data. How to force all read workers to consume data?

Upvotes: 2

Views: 35

Answers (0)

Related Questions