Multiple processes atomic output in linux shell


Is it possible to write from multiple processes to some queue in atomic manner?
For example


rm ./queue
mkfifo ./queue
curl > ./queue &
curl > ./queue &
cat ./queue

Output order or does not matter. I would like to have consistence content regardless of size. Is it possible in linux shell? Named fifo is not obligatory.


Just with GNU parallel:

parallel --group curl :::

Without GNU parallel you would lock for the output:

func() {
   a=$(curl "$1")
   flock "$lockfile" cat <<<"$a"
func &

# with GNU xargs
export -f func
printf "%s\n" |
  xargs -P0 bash -c 'func "[email protected]"' _

Answered By – KamilCuk

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published