flock can be used to prevent other people from using the file, but it's an elective system. That means that if a program doesn't try to lock the file before using it, it'll be able to read and modify file even if your application has it locked. I think that's the best you can do.