Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

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.

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


Comment on Re: How to detect if file is in use?
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.

    /J\

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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://440351]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (6)
As of 2014-07-23 00:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (130 votes), past polls