Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re: How to detect if file is in use?

by Ben Win Lue (Friar)
on Mar 17, 2005 at 12:23 UTC ( #440351=note: print w/replies, xml ) Need Help??

in reply to How to detect if file is in use?

What I did in the past was renaming the file. If you can rename it, it is not in use.

Particularly, when a process might reopen the file and append something, you have the advantage of having your file to work with and the process starts to write a new file.

Gellyfish is right, I did it only with MS/IBM/DEC-(nonUNIX) Systems.

Replies are listed 'Best First'.
Re^2: How to detect if file is in use?
by gellyfish (Monsignor) on Mar 17, 2005 at 12:32 UTC

    Nope that is not true in the general sense, which can be demonstrated simply by running:

    open FOO, ">x"; $foo = <>;
    in one window and then in another:
    [jonathan@orpheus test]$ /sbin/fuser -u x x: 5665(jonathan) [jonathan@orpheus test]$ mv x x1 [jonathan@orpheus test]$ /sbin/fuser -u x1 x1: 5665(jonathan)
    However it is true for most Windows applications.


Re^2: How to detect if file is in use?
by bart (Canon) on Mar 17, 2005 at 13:57 UTC
    You can rename, or even delete a file while it is open, on Linux, *BSD, and similar OSes. That's one way to create a temporary anonymous file, which will disappear as soon as your open handle to it closes. It is caused by the strong dissociation between file name and file contents. Hard links are another example, where you can have two independent and completely fully qualified (no limits) paths to the same file contents.

    Also, if on those platforms, you attempted to rename a log file for for example Apache while it is running, you'll see it doesn't stop it from still growing.

    Windows won't allow you to rename or delete the file while its open, that's true.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://440351]
and John Coltrane plays...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2017-05-25 05:36 GMT
Find Nodes?
    Voting Booth?