Peng Yu
2018-02-23 21:53:47 UTC
Hi,
The following test case shows that `read` is not atomic. But this
limitation makes it impossible to communicate from one process to a
group of other processes.
Is there an efficient way to let a process communicate with a group of
other processes? Thanks.
$ cat main.sh
#!/usr/bin/env bash
# vim: set noexpandtab tabstop=2:
tmpdir=$(mktemp -d)
cd "$tmpdir"
mkfifo myfifo guard
<myfifo <guard &
awk 'BEGIN { for(i=1;;++i) print i }' >myfifo &
(
while :
do
read -r x < myfifo
echo "1: $x"
sleep 1
done
) &
(
while :
do
read -r x < myfifo
echo "2: $x"
sleep 1
done
) &
wait
$ head 1.txt
12
3
5
78
9
12
14
516
17
19
The following test case shows that `read` is not atomic. But this
limitation makes it impossible to communicate from one process to a
group of other processes.
Is there an efficient way to let a process communicate with a group of
other processes? Thanks.
$ cat main.sh
#!/usr/bin/env bash
# vim: set noexpandtab tabstop=2:
tmpdir=$(mktemp -d)
cd "$tmpdir"
mkfifo myfifo guard
<myfifo <guard &
awk 'BEGIN { for(i=1;;++i) print i }' >myfifo &
(
while :
do
read -r x < myfifo
echo "1: $x"
sleep 1
done
) &
(
while :
do
read -r x < myfifo
echo "2: $x"
sleep 1
done
) &
wait
$ head 1.txt
12
3
5
78
9
12
14
516
17
19
--
Regards,
Peng
Regards,
Peng