Hi
On Windows I am use to opening a file and leaving it open while my app is running. If another instance of my application tries to delete this file it generates an error and the file is not deleted. This is an easy way for me to prevent multiple instances of my app from running. On Linux I have found that PurePasic can delete the file even if it is open in another process so I am wondering how to change this behaviour.
Thanks,
Simon
How to open a test file exclusively in Linux?
How to open a test file exclusively in Linux?
Simon White
dCipher Computing
dCipher Computing
Re: How to open a test file exclusively in Linux?
Hi,
Linux file system locking is completely different from Windows. In Linux, such file locking does not really exist. If a file is opened, the filesystem is working somehow with a copy and it is written back only in the moment you close the handle (very simplified explanation). Because of this, other processes can work with the original file as long as it is opened by another process. Including deletion. The last one who saves won the race. It is not better or worse than on Windows. I sometimes like it, sometimes I miss the locks (like you now). I suggest to use another technique to find out if the program is already running. I believe you will find some ideas here in the forum.
Like this thread: http://www.purebasic.fr/english/viewtop ... 13&t=65046
Linux file system locking is completely different from Windows. In Linux, such file locking does not really exist. If a file is opened, the filesystem is working somehow with a copy and it is written back only in the moment you close the handle (very simplified explanation). Because of this, other processes can work with the original file as long as it is opened by another process. Including deletion. The last one who saves won the race. It is not better or worse than on Windows. I sometimes like it, sometimes I miss the locks (like you now). I suggest to use another technique to find out if the program is already running. I believe you will find some ideas here in the forum.
Like this thread: http://www.purebasic.fr/english/viewtop ... 13&t=65046