But in my case I have some processes running in parallel and accessing the same file. Suppose Process1 is writing to a file, it should lock the file. and when procees2 has to write into the same file, it should check if the file is locked, if so wait till it is released and then write into it. How to implement this?