Mac OS X equivalent of Linux flock(1) command
There is a cross-platform flock command here: https://github.com/discoteq/flock I have tested it and it works well on OSX as a drop-in replacement for the util-linux flock.
There is a cross-platform flock command here: https://github.com/discoteq/flock I have tested it and it works well on OSX as a drop-in replacement for the util-linux flock.
This is what worked for me (using Windows). It is basically the same procedure as commented by ali haider, but with more details… Using Windows command prompt: tasklist | findstr java (“findstr” is a command line utility for Windows similar to “grep” in Linux) Search for any lines with ‘java’ and note the PID of …
Killing other processes is not a healthy thing to do. If your scenario involves something like uninstallation, you could use the MoveFileEx API function to mark the file for deletion upon next reboot. If it appears that you really need to delete a file in use by another process, I’d recommend re-considering the actual problem …
Long ago it was impossible to reliably get the list of processes locking a file because Windows simply did not track that information. To support the Restart Manager API, that information is now tracked. I put together code that takes the path of a file and returns a List<Process> of all processes that are locking …
If notepad can read the file then so can you, clearly the program didn’t put a read lock on the file. The problem you’re running into is that StreamReader will open the file with FileShare.Read. Which denies write access. That can’t work, the other program already gained write access. You’ll need to create the StreamReader …
This is very common in Windows environment but there is a solution via the antiResourceLocking context property: Open context.xml from /tomcat/conf folder and modify the context to match this : <Context antiResourceLocking=”true”> Edit: Updated properties following @JanM comment. Previously it also contained ‘antiJARLocking’
Notepad reads files by first mapping them into memory, rather than using the “usual” file reading mechanisms presumably used by the other editors you tried. This method allows reading of files even if they have an exclusive range-based locks. You can achieve the same in C# with something along the lines of: using (var f …
Long ago it was impossible to reliably get the list of processes locking a file because Windows simply did not track that information. To support the Restart Manager API, that information is now tracked. I put together code that takes the path of a file and returns a List<Process> of all processes that are locking …
Alright, so I ended up going with the code I wrote here, on my website link is dead, view on archive.org (also available on GitHub). I can use it in the following fashion: from filelock import FileLock with FileLock(“myfile.txt”): # work with the file as it is now locked print(“Lock acquired.”)
Updated NOTE on this solution: Checking with FileAccess.ReadWrite will fail for Read-Only files so the solution has been modified to check with FileAccess.Read. ORIGINAL: I’ve used this code for the past several years, and I haven’t had any issues with it. Understand your hesitation about using exceptions, but you can’t avoid them all of the …