Home > Archive > Unix Programming > June 2005 > how to know the change to a file during run time
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
how to know the change to a file during run time
|
|
|
| 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.
| |
| Gordon Burditt 2005-06-06, 3:58 am |
| >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
| |
| Maurizio Loreti 2005-06-06, 8:57 am |
| "$" <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 http://www.pd.infn.it/~loreti/mlo.html
Dept. of Physics, Univ. of Padova, Italy ROT13: ybergv@cq.vasa.vg
| |
| SM Ryan 2005-06-06, 8:57 am |
| "$" <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.
| |
| Phil Endecott 2005-06-06, 8:57 am |
| $ 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.
|
|
|
|
|