It looks like very classic problem, but I'm not sure if I handle it correctly.
There is some short-lived program, launched by the external event, possibly several times in rapid succession. This program has to log its work into the fixed file (possibly rotating over time, but not changing for every invocation). How to make sure that every write to log will be "atomic", i.e. that two instances of program won't try to add their logs concurrently?
The solution I can think of is to use lock-files, i.e. create the lock file (waiting and retrying if it already exists), write to the log, the delete the lock to allow others to work. Is there any better way?