in reply to Avoid multiple process writing to a file at the same time
As well as ccn's excellent pointer, OP might also want to have a look at the code in :
I have found the discussions there very useful! HTH