Reopen voters: flock()
doesn't work on named pipes, this is not a dupe.
I was trying to do the following with named pipes:
mkfifo example.txt
( printf "456"; printf "abc"; printf "\n"; ) > example.txt &
( printf "456"; printf "abc"; printf "\n"; ) > example.txt &
( printf "456"; printf "abc"; printf "\n"; ) > example.txt &
If I cat the example.txt
sometimes I got:
456abc
456abc
456abc
Other times I got:
456456456abcabc
abc
I was hoping the writes would be atomic. Is there any way to achieve atomic writes?
printf "456abc\n"
and it will be atomic. The answer in the other question, is in your case unusable.flock()
doesn't work on named pipes"? I just tried it and it seemed to work fine.