Check whether file is being written to

Discussion in 'Python' started by loial, Sep 23, 2010.

  1. loial

    loial Guest

    How can I check whether a file is being written to by another process
    before I access it?

    Platform is unix.
    loial, Sep 23, 2010
    #1
    1. Advertising

  2. loial

    Seebs Guest

    On 2010-09-23, loial <> wrote:
    > How can I check whether a file is being written to by another process
    > before I access it?


    You mean "written to" or "open for possible writing"?

    It may be possible (with sufficient privileges) to determine that a
    file has been opened for writing. I don't think you can detect
    being-written-to.

    More importantly, though, the question is irrelevant, because even if
    you absolutely, conclusively, prove that a file is not open nor being
    written to, before your next machine instruction loads, the file could
    be opened and rewritten multiple times by whole new processes that weren't
    even running when you checked.

    I suggest you look into advisory locks.

    -s
    --
    Copyright 2010, all wrongs reversed. Peter Seebach /
    http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
    http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
    I am not speaking for my employer, although they do rent some of my opinions.
    Seebs, Sep 23, 2010
    #2
    1. Advertising

  3. On Thursday 23 September 2010, it occurred to loial to exclaim:
    > How can I check whether a file is being written to by another process
    > before I access it?
    >
    > Platform is unix.


    As such, you can't. But you can lock the file using the functions in the fcntl
    module.
    Thomas Jollans, Sep 23, 2010
    #3
  4. Thomas Jollans <> writes:

    > On Thursday 23 September 2010, it occurred to loial to exclaim:
    >> How can I check whether a file is being written to by another process
    >> before I access it?
    >>
    >> Platform is unix.

    >
    > As such, you can't. But you can lock the file using the functions in the fcntl
    > module.


    Last time I checked, file-locking in unix was co-operative.

    Diez
    Diez B. Roggisch, Sep 23, 2010
    #4
  5. loial

    Nobody Guest

    On Thu, 23 Sep 2010 17:55:52 +0200, Diez B. Roggisch wrote:

    > Last time I checked, file-locking in unix was co-operative.


    Linux supports mandatory locking, but it's seldom enabled.
    Nobody, Sep 23, 2010
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steve C. Orr, MCSD
    Replies:
    1
    Views:
    547
    reaway lee
    Aug 24, 2003
  2. darrel
    Replies:
    3
    Views:
    554
    Darrel
    Apr 6, 2006
  3. JB
    Replies:
    1
    Views:
    542
  4. KaiWen
    Replies:
    102
    Views:
    2,640
    Jorgen Grahn
    Sep 15, 2011
  5. Kuhl
    Replies:
    6
    Views:
    95
    Tim Greer
    Nov 13, 2008
Loading...

Share This Page