file-locking

How to manually Lock a file for other applications

荒凉一梦 提交于 2021-01-27 05:23:27
问题 I have spent quite some time figuring out how to do this but did not find any usefull solution. Here is what I want to do. I am generating a huge binary file in my application. The tricky thing is that, the process requires me to occasionally close the FileStream. The problem now is, that occasionally other applications (i.e. my virus scanner) are using this brief moment where the file is not locked anymore, to lock the file itself. or other applications like dropbox etc... The result is,

How to manually Lock a file for other applications

假装没事ソ 提交于 2021-01-27 05:23:25
问题 I have spent quite some time figuring out how to do this but did not find any usefull solution. Here is what I want to do. I am generating a huge binary file in my application. The tricky thing is that, the process requires me to occasionally close the FileStream. The problem now is, that occasionally other applications (i.e. my virus scanner) are using this brief moment where the file is not locked anymore, to lock the file itself. or other applications like dropbox etc... The result is,

How safe is it to use Java FileLock?

跟風遠走 提交于 2021-01-24 07:53:05
问题 How safe is it to use java.nio.channels.FileLock for locking files among processes? It is stated that other processes can not access the file if we have an exclusive lock. However, the below answer on another SO question states other processes have to check for the filelock too in order for our process to be safe. (a) Are you aware that locking the file won't keep other processes from touching it unless they also use locks? So I tested my code and tried to change, a file which I have the lock

NetBeans IDE: Is there a way to make files read-only or lock the contents?

╄→гoц情女王★ 提交于 2020-01-15 05:29:06
问题 In the Netbeans IDE, is there a way to make a file read-only or prevent the file's contents from being edited, even though the file is part of a project as source code, a test package, or a data file? PLEASE NOTE: I know a version control system should be used for any kind of project, and I diff any file with the version control copy before committing the changes to the repository; I'm just wondering if there's a way to "lock" a file in this editor/IDE. 回答1: After further research, this

How to make Emacs lock-buffer fail when it cannot lock a file?

会有一股神秘感。 提交于 2020-01-14 13:06:28
问题 I want to some Emacs lisp to manipulate same file from different Emacs processes. So I wrote the following script to check how lock-buffer works. However, it stops when trying to lock the file by the second Emacs process ( find-and-lock-file $es2 /tmp/dummy ). I need to go to another terminal and send emacsclient --socket-name server-2 --eval '(kill-emacs)' to stop the Emacs process. Emacs prompts what to do for the file if I open an UI by emacsclient -t --socket-name server-2 , but I want to

How to start concurrent threads that acquire a file lock and wait on each other

你离开我真会死。 提交于 2020-01-06 04:31:12
问题 I'm studying the FileLock class. What I want to do is start three Threads that will run at the same time and access a single file. While the file is locked by one thread, I want the other two threads to wait for their turn when the lock is released. However, when I run my code below, the threads don't even start all at the same time--they are started one after the other, as soon as each of their run() methods is finished. I don't understand. public class Main { public static void main(String[

Log File Locking Issue in C#

安稳与你 提交于 2020-01-01 07:01:23
问题 I have a windows service that writes out log file entries to an XML log file. I maintain a handle to the log file while the service is operational, and close, flush and dispose of it when the service is stopped. The file write operations are by the service only, and I have the filestream open in FileAccess.ReadWrite while sharing is set to FileShare.Read. I would like to be able to open and view this file with an XmlRead() call by another application, but I get an error stating the file is

db.mdf is being used by another process

≡放荡痞女 提交于 2019-12-25 01:54:24
问题 Right now by code looks like the following: private void DatabaseIntegrityCheck() { try { string m_checksum; using (FileStream stream = File.OpenRead(@"C:\~\db.mdf")) { SHA256Managed sha = new SHA256Managed(); byte[] checksum = sha.ComputeHash(stream); m_checksum = BitConverter.ToString(checksum).Replace("-", String.Empty); } Console.WriteLine(m_checksum); } catch (Exception ex) { Console.WriteLine("unable to retrieve checksum"); } } When I set a breakpoint in my code to see what the

File r/w locking and unlink

不羁的心 提交于 2019-12-25 00:36:20
问题 I have following problem. I want to create a file system based session storage where each session data is stored in simple file named with session ids. I want following API: write(sid,data,timeout) , read(sid,data,timeout) , remove(sid) where sid==file name, Also I want to have some kind of GC that may remove all timed-out sessions. Quite simple task if you work with single process but absolutly not trivial when working with multiple processes or even over NFS. The simplest solution I thought

Understanding / removing a file lock on Azure File Service

天涯浪子 提交于 2019-12-24 07:04:33
问题 I'm working on an application that used to share common files to blob storage (i.e. Worker Role A would update those files and Worker Role B would read those). As this application is non critical we recently transitioned to Azure File Service share, even though it's still a preview. It was working just fine until recently when a file lock wouldn't be released on the share, even after trying to delete all the instances that could possibly have a handle on those files. Always the same message