Re: Which process is locking a file ?




"Paddy" <padmanabha.kamath@xxxxxxxxx> wrote in message
news:1151333034.318399.137430@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
| We have a recurring problem where a (long-running) service throws an
| exception while trying to access a file. The problem is that this is
| very rare (happens once every week and without warning) but does happen
| time to time. We are trying ways to find which other process is holding
| on to the file or even if any other thread from our process is holding
| on to the file at the specific time that the problem occurs.
|
| So, I am trying to invesitigate whether there are any ways that when we
| throw an exception that "The file is in use ...", specifically WHICH
| process is holding on to it. i.e. which process is locking the file or
| using it. As I was saying, this is a rarely occuring phenomenon and
| Process Explorer is not of much use to us as it (as far as I know) does
| not have a monitoring mode.
|
| Can anyone please let me know how this can be accomplished in code (C#,
| C, C++ .... doesn't matter) ?
|
| - K
|

It's nearly impossible in real-time, to know which other process/thread has
the file open in Windows. The only way to find the process who has a file
open is by inspecting each process handle table (by taking a snapshot like
Process Explorer does), this is an expensive (time consuming) operation
which requires elevated privileges (not something you want your service to
run with), by the time you have taken a snapshot of THE process, it's
possible that the handle has been released.

If the file is shareable across processes, there is very little you can do,
other than retrying to open the file. If the file can only be shared across
your process threads, you have a design flaw.
If the file must be shared across threads you should have set the correct
sharing mode (ReadWrite), on the other hand, if the file should not be
shared across threads, then you should synchronize the file accesses, or
better, have only one thread accessing the file.

Willy.




.



Relevant Pages

  • Versioned pointers: a new method of representing snapshots
    ... A snapshot of a disk volume may be represented as a list of exceptions ... exception is present, the data resides on the origin volume. ... size chunk sharing bitmap, as is the existing practice in ddsnap. ... the geometry of the version tree changes and exception lists are ...
    (Linux-Kernel)
  • Re: Which process is locking a file ?
    ... exception while trying to access a file. ... very rare (happens once every week and without warning) but does happen ... We are trying ways to find which other process is holding ... The first one has the source code included. ...
    (microsoft.public.dotnet.languages.csharp)
  • Which process is locking a file ?
    ... We have a recurring problem where a (long-running) service throws an ... exception while trying to access a file. ... very rare but does happen ... We are trying ways to find which other process is holding ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Which process is locking a file ?
    ... |> exception while trying to access a file. ... We are trying ways to find which other process is holding ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Geode LX HW RNG Support
    ... >>>I thought that a early version did that and somebody took exception to ... >>>the defines are only useful when you have a Geode CPU (and thus a ... > prevented immediate merge. ... Looking at the thread from my 2nd attempt, the main thing holding it back ...
    (Linux-Kernel)

Loading