Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
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.


Report this thread to moderator Post Follow-up to this message
Old Post
$
06-06-05 08:58 AM


Re: 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.

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

Report this thread to moderator Post Follow-up to this message
Old Post
Gordon Burditt
06-06-05 08:58 AM


Re: how to know the change to a file during run time
"$" <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 sym'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

Report this thread to moderator Post Follow-up to this message
Old Post
Maurizio Loreti
06-06-05 01:57 PM


Re: how to know the change to a file during run time
"$" <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.

Report this thread to moderator Post Follow-up to this message
Old Post
SM Ryan
06-06-05 01:57 PM


Re: how to know the change to a file during run time
$ 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.

Report this thread to moderator Post Follow-up to this message
Old Post
Phil Endecott
06-06-05 01:57 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Unix Programming archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 06:44 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.