Discussion:
[Help-bash] Is there an efficient way to let a process communicate with a group of other processes?
Peng Yu
2018-02-23 21:53:47 UTC
Permalink
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
--
Regards,
Peng
Eduardo Bustamante
2018-02-23 22:53:21 UTC
Permalink
On Fri, Feb 23, 2018 at 3:53 PM, Peng Yu <***@gmail.com> wrote:
[...]
Post by Peng Yu
Is there an efficient way to let a process communicate with a group of
other processes? Thanks.
Communicate *what* (type of information, volume, throughput, ..)?
Google "UNIX IPC", depending on what you're trying to communicate, you
might want to use shared memory or signals.

I definitely recommend you to use something other than bash for this though.
Loading...