Code Comments
Programming Forum and web based access to our favorite programming groups.Hi, I want to write a program which keeps on checking a file.If the file is modified it should fork a child to do some job.This should be continuous..... Please let me know if there is any function which notifies the program if there is any change to a file during runtime. Thanks, Sai.
Post Follow-up to this message>Hi, >I want to write a program which keeps on checking a file.If the file is >modified it should fork a child to do some job.This should be >continuous..... > >Please let me know if there is any function which notifies the program >if there is any change to a file during runtime. Not in standard C, unless you count repeatedly reading the file and comparing it against its original contents until it is different. Some implementations keep file modification times, and you could check these in a system-dependent manner (e.g. stat()). Gordon L. Burditt
Post Follow-up to this message"$" <r.saipra@gmail.com> writes: > Hi, > I want to write a program which keeps on checking a file.If the file is > modified it should fork a child to do some job.This should be > continuous..... On some computers I am sy
m'ing we were forced to define a "common" username with a well-known password, intended to be used from 1st year physics students (don't ask why, please - I was _forced_ from the management to do that) --- and, of course, after the login the "common" user was allowed to change its well-known password --- and, obviously, the password _was_ changed almost immediately :-( Restricting the access to the 'passwd' executable didn't work (I discovered that e.g. KDE has its own command to manage passwords). So, I wrote (in C++) a daemon watching, at regular time intervals, for changes in /etc/passwd and/or /etc/shadow, and restoring the original files. It worked correctly for almost two years. You can find the source (GPL) under http://wwwcdf.pd.infn.it/MLO/ ; get fwd.tar.gz . -- Maurizio Loreti [url]http://www.pd.infn.it/~loreti/mlo.html[/ur l] Dept. of Physics, Univ. of Padova, Italy ROT13: ybergv@cq.vasa. vg
Post Follow-up to this message"$" <r.saipra@gmail.com> wrote: # Hi, # I want to write a program which keeps on checking a file.If the file is # modified it should fork a child to do some job.This should be # continuous..... # # Please let me know if there is any function which notifies the program # if there is any change to a file during runtime. Depends on the flavour of unix. BSDs have something called kqueue that can tell you when an i-node changes or file descriptor becomes readable; others have FAM (file access monitor) originally from SGI Irix. Possibly other things on other unices. -- SM Ryan http://www.rawbw.com/~wyrmwif/ Mention something out of a Charleton Heston movie, and suddenly everybody's a theology scholar.
Post Follow-up to this message$ wrote: > Hi, > I want to write a program which keeps on checking a file.If the file is > modified it should fork a child to do some job.This should be > continuous..... Some systems have something called the "File Alteration Monitor", which does exactly this. But it is not available everywhere. However, I have seen libraries that provide a common API and use FAM when it is available and poll when it is not. I'm sure google or Freshmeat will find one for you. --Phil.
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.