file-locking

Mac OS X equivalent of Linux flock(1) command

放肆的年华 提交于 2019-12-09 04:39:01
问题 Is there a flock command on Mac OS X that manages file lock? http://linux.die.net/man/1/flock 回答1: 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. 回答2: Perl one-liner: perl -MFcntl=:flock -e '$|=1; $f=shift; print("starting\n"); open(FH,$f) || die($!); flock(FH,LOCK_EX); print("got lock\n"); system(join(" ",@ARGV)); print("unlocking\n"); flock(FH,LOCK_UN); ' /tmp

FileSystemWatcher.WaitForChanged returns, but there is still a lock on the file

主宰稳场 提交于 2019-12-08 10:06:55
问题 I have a program that send a document to a pdf printer driver and that driver prints to a particular directory. After the print I want to attach the pdf to an e-mail (MailMessage) and send it off. Right now, I send the document to the printer (wich spawns a new process) and then call a FileSystemWatcher.WaitForChanged(WaitForChangedResult.Created) but when the object is created, it's still not done "printing" and the pdf printer still has a lock on it, throwing an error when I try to attach

PHP lock text file for editing?

£可爱£侵袭症+ 提交于 2019-12-06 02:03:50
问题 I've got a form that writes its input to a textfile. Would it be possible to lock a text file for editing, and perhaps give a friendly message "the file is edited by another user, please try again later." I'd like to avoid conflicts if the file has multiple editors at the same time. Here's how the entry is currently added. $content = file_get_contents("./file.csv"); $fh = fopen("./file.csv", "w"); fwrite($fh, $date_yy . '-' . $date_mm . '-' . $date_dd . '|' . $address . '|' . $person . '|' .

Visual Studio 2010 Build Fails to File Copy Error

半城伤御伤魂 提交于 2019-12-06 00:42:21
问题 I'm building a project in Visual Studio 2010 and the build fails because it cannot copy the assemblyname.dll file from obj to bin folder. The exact error message is: Error 7 Unable to copy file "obj\Debug\AssemblyName.dll" to "bin\AssemblyName.dll". The requested operation cannot be performed on a file with a user-mapped section open. I think this is because the previous file in bin-folder is not accessible. When I try to delete the file manually, I get an error "The action can't be completed

Log File Monitor

孤人 提交于 2019-12-05 18:14:09
Is is possible to open a text file and read the contents while another application is updating the file, in such a way that it does not cause a lock conflict? I need to monitor a log file from one application which is updated by another application each time an event occurs. I do check if the file is in use before I try to read it, but that does not seem to work in all cases. Thanks, Pieter it depends on how the first app open that file. i.e when calling CreateFile API to open a file, there is dwShareMode param which tells the api how to open it (if this was given 0, it can't be accessed from

Get username of user who has file open on network drive - Microsoft Office Style

那年仲夏 提交于 2019-12-05 13:52:54
I would like to add user friendly file locking to a software running under Windows (Windows 7 mostly), written in C# . I already achieved the file locking part, by keeping the files in use "open" in the corresponding process. What I now still would like to add is recognition of the user who has a file currently open/locked. The files being accessed lie on a mapped network drive , used by different users on different computers. When a file is locked and a second person tries to open the file, he should be confronted with a dialog, similar to the "File in use"-dialog from the Microsoft Office

File locked by which process?

纵饮孤独 提交于 2019-12-05 01:20:54
Is there a way in .Net to find out exactly which process has locked a file? EDIT : I'm doing this because I want to let my user know that they can't modify/open the file, because at the moment, another program they're using (such as Excel) has it open. Hopefully, this helps. The short answer to this is no. However, the long answer is that there are various API calls and WMI methods that you can use to find this information out, but don't expect it to be quick and simple. If you want to use API calls, take a look at the NtQuerySystemInformation function with the SYSTEM_PROCESS_INFORMATION

PHP lock text file for editing?

末鹿安然 提交于 2019-12-04 07:17:51
I've got a form that writes its input to a textfile. Would it be possible to lock a text file for editing, and perhaps give a friendly message "the file is edited by another user, please try again later." I'd like to avoid conflicts if the file has multiple editors at the same time. Here's how the entry is currently added. $content = file_get_contents("./file.csv"); $fh = fopen("./file.csv", "w"); fwrite($fh, $date_yy . '-' . $date_mm . '-' . $date_dd . '|' . $address . '|' . $person . '|' . $time_hh . ':' . $time_mm); fwrite($fh, "\n" . $content); fclose($fh); Any thoughts? You can use flock(

Log File Locking Issue in C#

谁说胖子不能爱 提交于 2019-12-03 20:31:29
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 being used by another process. I had read another post on this and was under the impression this was

Persistent memoization in Python

做~自己de王妃 提交于 2019-12-03 17:15:38
问题 I have an expensive function that takes and returns a small amount of data (a few integers and floats). I have already memoized this function, but I would like to make the memo persistent. There are already a couple of threads relating to this, but I'm unsure about potential issues with some of the suggested approaches, and I have some fairly specific requirements: I will definitely use the function from multiple threads and processes simultaneously (both using multiprocessing and from