help-bash
[Top][All Lists]
Advanced

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

[Help-bash] Dealing with "Broken pipe: 13" error


From: Peng Yu
Subject: [Help-bash] Dealing with "Broken pipe: 13" error
Date: Thu, 22 Feb 2018 17:06:45 -0600

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"
> "$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 5
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 }'
> "$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



reply via email to

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