watching a file

Discussion in 'C Programming' started by Benjamin D. LeMasurier, Oct 1, 2004.

  1. Hey everyone,

    Is there a way to "watch" a file for changes? I know I could poll the
    file every few seconds and check to see if the buffer has changed but
    is there a cleaner way?

    thanks!

    Ben
     
    Benjamin D. LeMasurier, Oct 1, 2004
    #1
    1. Advertising

  2. Benjamin D. LeMasurier

    Mike Wahler Guest

    "Benjamin D. LeMasurier" <> wrote in message
    news:...
    > Hey everyone,
    >
    > Is there a way to "watch" a file for changes?


    I assume you mean changes made by some other process.
    Otherwise your program already 'knows' when it changes
    things.

    >I know I could poll the
    > file every few seconds and check to see if the buffer has changed but
    > is there a cleaner way?


    Depending upon your operating system, probably yes. But
    standard C doesn't recognize the notion of multiple processes,
    shared files, etc. Those issues are the domain of the operating
    system. Ask in a forum which discuss your host platform.

    -Mike
     
    Mike Wahler, Oct 1, 2004
    #2
    1. Advertising

  3. Benjamin D. LeMasurier

    dandelion Guest

    "Benjamin D. LeMasurier" <> wrote in message
    news:...
    > Hey everyone,
    >
    > Is there a way to "watch" a file for changes? I know I could poll the
    > file every few seconds and check to see if the buffer has changed but
    > is there a cleaner way?


    Depends on your OS. AFAIK, there is no standard 'C' way to do it. On a POSIX
    system, stat() and check atime.

    > thanks!
    >
    > Ben
     
    dandelion, Oct 1, 2004
    #3
  4. "dandelion" <> writes:
    > "Benjamin D. LeMasurier" <> wrote in message
    > news:...
    >> Hey everyone,
    >>
    >> Is there a way to "watch" a file for changes? I know I could poll the
    >> file every few seconds and check to see if the buffer has changed but
    >> is there a cleaner way?

    >
    > Depends on your OS. AFAIK, there is no standard 'C' way to do it. On a POSIX
    > system, stat() and check atime.


    <OT>
    mtime, not atime. For details, consult the documentation or an
    appropriate newsgroup.
    </OT>

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
     
    Keith Thompson, Oct 1, 2004
    #4
  5. "dandelion" <> wrote in message news:<415d286d$0$147
    > Depends on your OS. AFAIK, there is no standard 'C' way to do it. On a POSIX
    > system, stat() and check atime.



    I am in a linux/unix environment. I will give stat() a try

    thanks!

    Ben
     
    Benjamin D. LeMasurier, Oct 1, 2004
    #5
  6. Benjamin D. LeMasurier

    dandelion Guest

    "Keith Thompson" <> wrote in message
    news:...
    > "dandelion" <> writes:
    > > "Benjamin D. LeMasurier" <> wrote in message
    > > news:...
    > >> Hey everyone,
    > >>
    > >> Is there a way to "watch" a file for changes? I know I could poll the
    > >> file every few seconds and check to see if the buffer has changed but
    > >> is there a cleaner way?

    > >
    > > Depends on your OS. AFAIK, there is no standard 'C' way to do it. On a

    POSIX
    > > system, stat() and check atime.

    >
    > <OT>
    > mtime, not atime. For details, consult the documentation or an
    > appropriate newsgroup.
    > </OT>


    <ot>
    Right of course. Errare humanum est.
    </ot>
     
    dandelion, Oct 4, 2004
    #6
    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. Luis Esteban Valencia Muñoz
    Replies:
    3
    Views:
    1,421
    Scott Allen
    Jun 4, 2005
  2. Bomb Diggy
    Replies:
    11
    Views:
    6,184
    Ivan S Kirkpatrick
    Jul 3, 2003
  3. aljosa

    file parsing/watching + qt

    aljosa, May 4, 2005, in forum: Python
    Replies:
    2
    Views:
    334
    Swaroop C H
    May 4, 2005
  4. Christopher Harrison

    Watching a File for Changes

    Christopher Harrison, Oct 18, 2005, in forum: C Programming
    Replies:
    8
    Views:
    332
    Netocrat
    Oct 19, 2005
  5. Gordon Airporte

    Watching a file another app is writing

    Gordon Airporte, Mar 11, 2007, in forum: Python
    Replies:
    8
    Views:
    313
    Gordon Airporte
    Mar 12, 2007
Loading...

Share This Page