I do not recommend using flock(2). First, I use it in the library functions for UTMP on Tru64 UNIX. The semantics of flock(2) changed between the 4.0 and 5.0 stream where I had to implement a 4.0 version of flock(2) on the 5.0 stream for the UTMP library functions.