Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
There is (update: currently (that I am aware of)) no perl module which can tell if a file is open in another program.

There is a utility called lsof which may let you fiquire out if the file is opened by another application on UNIX-like systems, but this is likely to be slow, and probably will suffer from race conditions (you check if the file is open elsewhere, someone edits the file, you do something with the file, someone stops editing the file. Oops.)

If you really want to prevent people from doing things with these files you could probably use mandatory file locking, if your system supports it. This is likely to be very much unportable. (On Solaris one can do this by setting the setgid bit without setting the executable-by-group bit and using lockf or fcntl with F_GETLK, etc. (update: So much for trusting manpages... ("discretionary file locks", indeed). Much thanks to traveler) On Linux, it appears this cannot be done.)

On Windows, you can actually get this information and/or obtain exclusive write access to a file... A Super Search of this site should tell you how.

A better solution would probably be to either trust the user to not do that or, if possible, give the file permissions that prevent normal users from doing things with it (and presumably the "privallaged" users will be able to tell when they shouldn't do something. Or they'll modify your package to remove the restriction. (; ) If these are temporary files, you may even be able to remove the need for the file to actually have a name on disk. (Hint: on some UNIX systems, /dev/fd/X corresponds to fileno X. Or you can use open to turn a specific filehandle into stdin and stdout... And IO::File provides new_tmpfile.)


In reply to Re: file information by wog
in thread file information by hotshot

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2024-04-25 21:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found