in reply to Forking and writing to files

You'll need to close that file as well as lock it. If you can change your program so that it writes larger chunks less often, then this will become less of an issue.