file-locking

How do I check the exit code of a command executed by flock?

Greetings all. I'm setting up a cron job to execute a bash script, and I'm worried that the next one may start before the previous one ends. A little googling reveals that a popular way to address this is the flock command, used in the following manner: flock -n lockfile myscript.sh if [ $? -eq 1 ]; then echo "Previous script is s...

Determine which process (b)locks a file, programmatically (under Windows >= XP)

How to programmatically determine from a process P, which other process P' has a lock on a file, that prevents P from recreating that file ? I know there are tools to do that, but how do they achieve that ? (Context: a batch program that runs overnight fails because of a locked file. Running an admin tool the next day may be too late t...

How to find out which thread is locking a file in java?

I'm trying to delete a file that another thread within my program has previously worked with. I'm unable to delete the file but I'm not sure how to figure out which thread may be using the file. So how do I find out which thread is locking the file in java? ...

One service appends to and another one truncates a file.

I have a service that controls an RS-232 device and logs actions to a file. I am to write another service which will read the log file line by line and run some queries on a database then delete all the logs. My concern is about read and write conflicts on the file. For example, the logger service open the file to append a new line at t...

Java FileLock for Reading and Writing

I have a process that will be called rather frequently from cron to read a file that has certain move related commands in it. My process needs to read and write to this data file - and keep it locked to prevent other processes from touching it during this time. A completely separate process can be executed by a user to (potential) writ...

How can my Linux daemon know when a Windows program has stopped writing a file that I access through SAMBA?

I'm developing a system that interfaces with a USPS shipping package called Dazzle. Part of this system includes a monitoring daemon whose purpose is to take tab-separated value files, turn them into XML that Dazzle recognizes, and pass them to Dazzle for label generation. And this part works just fine. What I also want to do, however...

Deleting an Image that has been used by a WPF control

I would like to bind an Image to some kind of control an delete it later on. path = @"c:\somePath\somePic.jpg" FileInfo fi = new FileInfo(path); Uri uri = new Uri(fi.FullName, UriKind.Absolute); var img = new System.Windows.Controls.Image(); img.Source = new BitmapImage(uri); Now after this code I would like to delete the file : fi....

File locked by which process?

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. ...

Removing file locks in Windows and Java

I have a Java program that opens a file using the RandomAccessFile class. I'd like to be able to rename that file while it is opened by Java. In Unix, this isn't a problem. Does anyone know how I can do this in Windows? Should I set Java to open it a certain way? Thanks in advance. Edit, clarification: I'd like to be able to set this...

Locking behaviour is different via network shares

I have been trying to lock a file so that other cloned services cannot access the file. I then read the file, and then move the file when finished. The Move is allowed by using FileShare.Delete. However in later testing, we found that this approach does not work if we are looking at a network share. I appreciate my approach may not have...

Is std::ifstream thread-safe & lock-free?

I intend to perform opening for reading a single file from many threads using std::ifstream. My concern is if std::ifstream is thread-safe & lock-free? More details: I use g++ 4.4 on Ubuntu & Windows XP, 4.0 on Leopard. Each thread creates its own instance of std::ifstream Thanks in advance! ...

Easy way to lock a file on a remote machine (windows)?

I've tracked down an error in my logs, and am trying to reproduce it. My theory is that a file sometimes gets locked in a specific folder, and when the application (ASP.NET) tries to delete that folder it hangs. I don't have the application running on my own machine so I'm debugging this on a remote server. But for the life of me, I ca...

PHP check if file locked with flock()?

Will fopen() fail if a file exists, but is currently locked with LOCK_EX? Or do I have to open it, and then try and set a lock, in order to determine if one already exists? I've also read that flock() will; pause [the script] untill you get the lock for indefinite amount of time or till your script times out http://www.php.net...

ASP.NET How do I wait for file upload/release?

Hi, I've got ASP.NET intranet application written in VB. It gets a file from the user, and then depending on a few different cases it may create a few copies of the file as well as move the original. Unfortunately I've come across a case where I get this error: Exception Details: System.IO.IOException: The process cannot access the f...

Log File Locking Issue in C#

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 ...

Collaborative Code Editing

Hi all. I work for a small web development company (6 people) and we've been in the market for a new code editor/development environment for quite some time. Currently, we're using Dreamweaver's (CS3) coding side for our site development. Each site's files is hosted on a Dreamhost ftp server. All 6 of us work on the same set of liv...

VB6 IDE Is Locking The Loaded Project's DLL

I'm responsible for maintaining legacy VB6 code, and have encountered an annoying problem with regard to the locking of a project's COM DLL. (We'll call it MyProject and MyProject.dll) When I load MyProject into the VB6 IDE, I am able to compile the resulting binary-compatible DLL MyProject.dll. I can then run my (Classic ASP) web appli...

How to ensure that when my process is operating on a file, no other process tries to write to it or delete it?

If my process is trying to read from a file, then how do I ensure from my code (C Language) that no other process either writes to it or deletes it (include system commands for deleting the file)? Also, can this be achieved on all OS (Windows, Linux, Solaris, HP-UX, VxWorks etc)? ...