in reply to How to do atomic file locking?
"Please correct me if I'm wrong, but if I first open then flock, isn't there a non-zero probability that this would cause a race condition?" You're wrong.