http://qs1969.pair.com?node_id=35175


in reply to (Guildenstern) RE: RE (tilly) 1: Creating a file with Open
in thread Creating a file with Open

Opening the file "+>" will wipe it out, so flocking it is then pretty pointless - you destroy the file before you've gained the lock on it.

You need to open the file "+<", if that failed then open it "+>" then flock it then truncate it if you want to be safe with your flocking in the presence of other readers.

Note that if you want to read the file back in with flocking you need to use "+<" so that you open the file with write intent otherwise the flocking may not work properly (I don't understand the reasons for this but that is what it says in the man pages!)