help-bash
[Top][All Lists]
Advanced

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

[Help-bash] Is there an efficient way to let a process communicate with


From: Peng Yu
Subject: [Help-bash] Is there an efficient way to let a process communicate with a group of other processes?
Date: Fri, 23 Feb 2018 15:53:47 -0600

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



reply via email to

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