I am writing 2 separate programs that need to access the same directory. The first application will save the files in the directory. The second application will have to copy all the files in the same directory to the remote machine and delete it. The problem is there is a chance that the first application is still trying to write a file and the second application have reading the partial of it to the remote machine. What is the best method to accomplish this?
My current idat is to have a status file. I think maybe I can have a dummy file with 0 byte to indicate which application is using the directory. If the first application lock this file then the second app will wait until this file is unlock. When the second app gain control by locking the dummy file, the first application will wait. However I don't know how to lock the file or how to check if the file is currently locked or not. Please suggest me on this and also if you have any better idea.