in reply to
Safe to open+close for every write, without locking?
If I understand the OP code correctly, it seems like the lines being written to the one output file are all quite short - just two numerics that yield a maximum of 10 characters per line (counting the final line-feed - 11 characters if you're on a CRLF system).
The problem I would want to check for is whether multiple competing processes, writing to the same output file, might interrupt each other if one or more of them were trying to write relatively long lines. I've seen this happen, and it makes the resulting file incomprehensible and unparsable.
I'd be inclined to go with something like BrowserUK's suggestion, but if you want to pursue the OP strategy, you should test again by writing, say, 130 characters or more per line; follow the same tactic of starting each line with a token that is different for each process, and see whether you get the expected number of lines starting with those tokens, as opposed to things like this:
PROC.1 This line is being written by process #1.
PROC.2 This line is being writtPROC.1 This line is being written by pr
en by process #2.
PROC.3 This line is beinPROC.4 This line is being written by process #
g written by pPROC.1 This line is being written by process #1.
(... and so on) I'm using fewer than 130 characters per line there, but I hope you get what I'm talking about.