How to open a test file exclusively in Linux?

Just starting out? Need help? Post your questions and find answers here.
swhite
Enthusiast
Enthusiast
Posts: 726
Joined: Thu May 21, 2009 6:56 pm

How to open a test file exclusively in Linux?

Post by swhite »

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
Simon White
dCipher Computing
User avatar
Kukulkan
Addict
Addict
Posts: 1352
Joined: Mon Jun 06, 2005 2:35 pm
Location: germany
Contact:

Re: How to open a test file exclusively in Linux?

Post by Kukulkan »

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
Post Reply