watching a file

  • Thread starter Benjamin D. LeMasurier
  • Start date
B

Benjamin D. LeMasurier

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
 
M

Mike Wahler

Benjamin D. LeMasurier said:
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
 
D

dandelion

Benjamin D. LeMasurier said:
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.
 
K

Keith Thompson

dandelion said:
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>
 
B

Benjamin D. LeMasurier

dandelion said:
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
 
D

dandelion

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

<ot>
Right of course. Errare humanum est.
</ot>
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top