Peng Yu
2018-02-22 23:06:45 UTC
Hi,
When I run the following code, it will generate the "Broken pipe: 13"
error. And the for-loop hangs there at the iteration 1859. How to make
the awk process persistent so that `read` still can get new data
beyond iteration 1859?
$ cat ./main.sh
#!/usr/bin/env bash
# vim: set noexpandtab tabstop=2:
set -v
myfifo=$(mktemp -u)
guard=$(mktemp -u)
mkfifo "$myfifo" "$guard"
jobs
sleep 5
for i in {1..10000}
do
read -r x < "$myfifo"
echo "$x"
jobs
done
$ ./main.sh
myfifo=$(mktemp -u)
guard=$(mktemp -u)
mkfifo "$myfifo" "$guard"
jobs
[1]- Running > "$myfifo" < "$guard" &
[2]+ Running awk -e 'BEGIN { for(i=1;;++i) print i }'
for i in {1..10000}
do
read -r x < "$myfifo"
echo "$x"
jobs
done
1
[1]- Running > "$myfifo" < "$guard" &
[2]+ Running awk -e 'BEGIN { for(i=1;;++i) print i }'
[1]- Running > "$myfifo" < "$guard" &
[2]+ Running awk -e 'BEGIN { for(i=1;;++i) print i }'
[1]- Running > "$myfifo" < "$guard" &
[2]+ Running awk -e 'BEGIN { for(i=1;;++i) print i }'
[1]- Running > "$myfifo" < "$guard" &
[2]+ Broken pipe: 13 awk -e 'BEGIN { for(i=1;;++i) print i }'
[1]+ Running > "$myfifo" < "$guard" &
6
[1]+ Running > "$myfifo" < "$guard" &
...
1858
[1]+ Running > "$myfifo" < "$guard" &
1859
[1]+ Running > "$myfifo" < "$guard" &
When I run the following code, it will generate the "Broken pipe: 13"
error. And the for-loop hangs there at the iteration 1859. How to make
the awk process persistent so that `read` still can get new data
beyond iteration 1859?
$ cat ./main.sh
#!/usr/bin/env bash
# vim: set noexpandtab tabstop=2:
set -v
myfifo=$(mktemp -u)
guard=$(mktemp -u)
mkfifo "$myfifo" "$guard"
"$myfifo" < "$guard" &
awk -e 'BEGIN { for(i=1;;++i) print i }' > "$myfifo" &jobs
sleep 5
for i in {1..10000}
do
read -r x < "$myfifo"
echo "$x"
jobs
done
$ ./main.sh
myfifo=$(mktemp -u)
guard=$(mktemp -u)
mkfifo "$myfifo" "$guard"
"$myfifo" < "$guard" &
awk -e 'BEGIN { for(i=1;;++i) print i }' > "$myfifo" &jobs
[1]- Running > "$myfifo" < "$guard" &
[2]+ Running awk -e 'BEGIN { for(i=1;;++i) print i }'
"$myfifo" &
sleep 5for i in {1..10000}
do
read -r x < "$myfifo"
echo "$x"
jobs
done
1
[1]- Running > "$myfifo" < "$guard" &
[2]+ Running awk -e 'BEGIN { for(i=1;;++i) print i }'
"$myfifo" &
2[1]- Running > "$myfifo" < "$guard" &
[2]+ Running awk -e 'BEGIN { for(i=1;;++i) print i }'
"$myfifo" &
3[1]- Running > "$myfifo" < "$guard" &
[2]+ Running awk -e 'BEGIN { for(i=1;;++i) print i }'
"$myfifo" &
4[1]- Running > "$myfifo" < "$guard" &
[2]+ Broken pipe: 13 awk -e 'BEGIN { for(i=1;;++i) print i }'
"$myfifo"
5[1]+ Running > "$myfifo" < "$guard" &
6
[1]+ Running > "$myfifo" < "$guard" &
...
1858
[1]+ Running > "$myfifo" < "$guard" &
1859
[1]+ Running > "$myfifo" < "$guard" &
--
Regards,
Peng
Regards,
Peng