Deleting a possibly locked file in c

Deleting a possibly locked file in c

I am using fcntl locks in C on linux and have a dilemma of trying to delete a file that may possibly be locked from other processes that also check for the fcntl locking mechanism. What would be the preferred way of handling this file which must be deleted, (Should I simply delete the file without regard of other processes that may have reader locks or is there a better way)? Any help would be much appreciated.

CreateTimerQueue for linux


Terminate threads Gracefully in ACE
On UNIX systems, it is possible to unlink a file while it is still open; doing so decrements the reference count on the file, although the actual file and its inode remains around until the reference count goes to zero.. building Mozilla Spider Monkey on Ubuntu
Determine the contents of Linux CacheScaling a ruby script by launching multiple processes instead of using threads


What is linux equivalent of running a .bat file on windows from PHP using system()
As others have noted, you are free to delete the file even while you hold the lock.. Newbie: Render RGB to GTK widget — howto? Now, a cautionary note: you didn't mention why processes are locking this file, although you should be aware this if you are using this file for interprocess synchronization, deleting it is a good way to introduce subtle race conditions into your system, basically for the reason this there's no way to atomically create AND lock the file in a single operation.. Is there any way to get the combine two xml into one xml in Linux For example, process AA might create the file, with the intention of locking it immediately to did whatever updates it needs to do. However, there's nothing to prevent process BB from grabbing the lock on the file first, then deleting the file, leaving process AA with a handle to the now deleted file. Process AA will still be able to lock and update this file, although those updates will effectively be "lost" for the reason this the file's already been deleted..


Moreover, locks on UNIX system are advisory by default, not mandatory, so this locking a file does not prevent it from being open or unlinked, just from being locked again..

58 out of 100 based on 43 user ratings 318 reviews