I have 2 programs, both writing to the same file (/tmp/outfile
). Started by cron at the same time.
Basically this is what is happening:
echo -n "1111111111" >> /tmp/outfile
And at the same time:
echo -n "2222222222" >> /tmp/outfile
The output file says "11111222222222211111
". This is an example, I am talking about hundreds of lines, where one line is "cut" mid-sentence, but simply put, above thing is happening.
How to prevent this behavior?
flock
-- it provides the necessary mechanisms to do so. – Malte Skoruppa Mar 15 '18 at 10:30