Answered step by step
Verified Expert Solution
Question
1 Approved Answer
#include #include #include #define MFILE 1 0 void cmp ( const char * , time _ t ) ; struct stat sb; int main (
#include
#include
#include
#define MFILE
void cmpconst char timet;
struct stat sb;
int mainint argc, char argv
int j;
timet lasttimeMFILE;
if argc
fprintfstderr "usage: lookout filename
;
exit;
if argc MFILE
fprintfstderr "lookout: too many filenames
;
exit;
Initialization
forj j argc; j;
ifstatargvj &sb
fprintfstderr "lookout: couldn't stat s
argvj;
exit;
lasttimej sbstmtime;
loop until file changes
for;;
forj ; j argc; j
cmpargvj lasttimej;
rest for SECONDS "sleep" is a standard UNIX library routine
sleep;
void cmpconst char name timet last
as long as statics about the file can be read check the modification time
ifstatname &sb sbstmtime last
fprintfstderr "lookout: s changed
name;
exit;
Modify the template program, lookoutc on p with the following additional capabilities
a Repeat the following steps times this means, after seconds of running, your program should terminate without printing anything if there is no change detected.
i Wait seconds using sleep call
ii Call stat system call to extract the file attributes against given files in command line arguments the lookout.c program in p may accept up to files Your program should be able to accept up to files for monitoring.
iii. You program should check any changes in any of the following attributes:
stmode
stnlink
stsize
statime
stmtime
iv When your program detects any changes, your program should immediately print out number codes given below and EXIT!
Change of stmode print
Change of stnlink print
Change of stsize print
Change of statime print
Change of stmtime print
Once printing is done, your program should terminate. Make sure your condition checking and printing should be done in the above order! Make sure you print number codes in one line without any newline character
Example output when you change the file contents eg using vi:
If your program prints more than one number code, then place spaces in between.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started