Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

win32-files in use by other processes ?

by tos (Deacon)
on Sep 02, 2003 at 07:22 UTC ( #288257=perlquestion: print w/replies, xml ) Need Help??

tos has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,

is there are reliable way to determine whether especially win32-files are opened bei other processes or threads ? (what would be an equivalent way for unix-files?)

greetings, tos

  • Comment on win32-files in use by other processes ?

Replies are listed 'Best First'.
Re: win32-files in use by other processes ?
by BrowserUk (Pope) on Sep 02, 2003 at 07:55 UTC

    If the file has been opened by a non-perl process using the native OpenFile or CreateFile APIs, then the easiest (only?) way is to attempt to open the file using the native API OpenFile() with a uStyle parameter of OF_SHARE_EXCLUSIVE. If the file is already open, you will get an error.

    If the file has been opened using Perl, then you will always be able to open it as perl use OF_SHARED_DENY_NONE which is fits with the unix standard. See flock for how Perl and unix prevent multiple accesses to files.

    You can gain access to the native APIs via Win32::API (and Win32::API::Prototype) or via tyes Win32API::File


    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller
    If I understand your problem, I can solve it! Of course, the same can be said for you.

      thanks a lot for your comprehensive answer. Beyond that i'am glad to see that you aren't resentful regarding my person. Thanks for that too.

      greetings, tos

Re: win32-files in use by other processes ?
by wirrwarr (Monk) on Sep 02, 2003 at 07:45 UTC
    for unix-systems, there's a command-line tool called lsof (list open files) that provides this sort of information.

    daniel.
Re: win32-files in use by other processes ?
by wufnik (Friar) on Sep 02, 2003 at 09:04 UTC
    not perl, but then neither is lsof -

    not as instructive as BrowserUKs answer -

    but for raw functionality, ie process, time, file, request &c &c you can not do much better than filemon, from sysinternals sysinternals. on win32. other useful tools abound at the site. it is free.

    regards, best wishes,

    wufnik

    -- in the world of the mules there are no rules --
Re: win32-files in use by other processes ?
by bm (Hermit) on Sep 02, 2003 at 08:51 UTC
    (what would be an equivalent way for unix-files?)

    On at least Linux and Solaris platforms, use fuser. See Linux::Fuser
    --
    bm

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (1)
As of 2021-03-09 01:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favorite kind of desktop background is:











    Results (129 votes). Check out past polls.

    Notices?