Questions tagged [filelock]

File locks are locks held by an application, preventing interference from other processes. Locks may be advisory (may be ignored by others), or mandatory, enforced by the operating system, depending on implementation.

File locks are locks held by an application, preventing interference from other processes. Locks may be advisory (may be ignored by others), or mandatory, enforced by the operating system, depending on implementation.

188 questions
256
votes
12 answers

How to check for file lock?

Is there any way to check whether a file is locked without using a try/catch block? Right now, the only way I know of is to just open the file and catch any System.IO.IOException.
ricree
  • 30,749
  • 13
  • 33
  • 27
74
votes
12 answers

How to unlock a file from someone else in Team Foundation Server

We have a project that is stored within our TFS server and some files were Checked-Out by me from another computer and another user (both of which are not used anymore). Is there a way to force the unlocking of the file (no changes were made to it…
David Brunelle
  • 6,190
  • 10
  • 57
  • 101
58
votes
9 answers

PowerShell script to check an application that's locking a file?

Using in PowerShell, how can I check if an application is locking a file? I like to check which process/application is using the file, so that I can close it.
Marc Vitalis
  • 1,779
  • 3
  • 20
  • 30
24
votes
1 answer

Linux flock, how to "just" lock a file?

In Bash, I'm trying to make a function getLock to be used with different lock names. function getLock { getLock_FILE="${1}" getLock_OP="${2}" case "${getLock_OP}" in "LOCK_UN") flock -u "${getLock_FILE}" …
JorgeeFG
  • 4,812
  • 8
  • 48
  • 78
23
votes
3 answers

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…
bobtheowl2
  • 631
  • 2
  • 10
  • 19
23
votes
2 answers

Can I prevent a StreamReader from locking a text file whilst it is in use?

The StreamReader locks a text file whilst it is reading it. Can I force the StreamReader to work in a "read-only" or "non locking" mode? My workaround would be to copy the file to a temp location and read it from there but I would prefer to use the…
G-.
  • 1,005
  • 3
  • 11
  • 29
20
votes
4 answers

How can I simulate a "locked" file (one which has a write lock)

I am trying to debug a problem where users occasionally have locked files which they try to open. The code appears to have correct exception handling but users are still reporting seeing error messages. How can I simulate a locked file so that I…
Daisetsu
  • 4,416
  • 9
  • 46
  • 68
17
votes
4 answers

FileStream with locked file

I am wondering if it's possible to get a readonly FileStream to a locked file? I now get an exception when I try to read the locked file. using (FileStream stream = new FileStream("path", FileMode.Open)) Thanks!
SaphuA
  • 2,924
  • 3
  • 36
  • 56
17
votes
10 answers

How to check in command-line if a given file or directory is locked (used by any process)?

I need to know that before any attempt to do anything with such file.
rsk82
  • 24,158
  • 43
  • 131
  • 223
13
votes
2 answers

Using FileChannel to write any InputStream?

Can I write any InputStream into a FileChannel? I'm using java.nio.channels.FileChannel to open a file and lock it, then writing a InputStream to the output file. The InputStream may be opened by another file, URL, socket, or anything. I've write…
KiKi
  • 485
  • 1
  • 4
  • 11
12
votes
2 answers

When using Java's FileLock, is it ok to let close() to automatically do a lock.release()?

As most should know close() also closes any streams uses. This allows the follow code: BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(...))); ... br.close(); This is nice, since we don't need a reference to…
Pyrolistical
  • 26,088
  • 21
  • 78
  • 104
11
votes
4 answers

Java: opening and reading from a file without locking it

I need to be able to mimic 'tail -f' with Java. I'm trying to read a log file as it's being written by another process, but when I open the file to read it, it locks the file and the other process can't write to it anymore. Any help would be greatly…
rogue780
  • 135
  • 1
  • 1
  • 8
10
votes
1 answer

Lock file when writing to it from parallel processes in R

I use parSapply() from parallel package in R. I need to perform calculations on huge amount of data. Even in parallel it takes hours to execute, so I decided to regularly write results to a file from clusters using write.table(), because the…
user1603038
  • 1,833
  • 2
  • 16
  • 27
10
votes
4 answers

How to find out what processes have folder or file locked?

How do you go about querying running processes to find out what folders or files they have locked? (i.e. you go to eject a drive and you're told that it can't be ejected because it's in use) I'd like to either get an "off the shelf" download, or…
CodeMonkey1313
  • 14,477
  • 17
  • 71
  • 109
9
votes
6 answers

how to best wait for a filelock to release

I have an application where i sometimes need to read from file being written to and as a result being locked. As I have understood from other questions i should catch the IOException and retry until i can read. But my question is how do i know for…
Tjelle
  • 956
  • 1
  • 9
  • 16
1
2 3
12 13