Answered step by step
Verified Expert Solution
Link Copied!

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 10
void cmp(const char *, time_t);
struct stat sb;
int main(int argc, char **argv)
{
int j;
time_t last_time[MFILE+1];
if (argc <2){
fprintf(stderr, "usage: lookout filename ...
");
exit(1);
}
if (--argc > MFILE ){
fprintf(stderr, "lookout: too many filenames
");
exit(1);
}
/*Initialization*/
for(j =1, j <= argc; j++;)
if(stat(argv(j), &sb)==-1)
{
fprintf(stderr, "lookout: couldn't stat %s
", argv(j));
exit(1);
}
last_time(j)= sb.st_mtime;
/*loop until file changes*/
for(;;)
{
for(j =1; j <= argc; j++)
cmp(argv(j), last_time(j));
/*rest for 60 SECONDS "sleep" is a standard UNIX library routine */
sleep(60);
}
}
void cmp(const char *name, time_t last)
{
/*as long as statics about the file can be read check the modification time */
if(stat(name, &sb)==-1|| sb.st_mtime != last)
{
fprintf(stderr, "lookout: %s changed
", name);
exit(0);
}
}
Modify the template program, lookout.c on p.56-57 with the following additional capabilities
a. Repeat the following steps 5 times (this means, after 5 seconds of running, your program should terminate without printing anything if there is no change detected.)
i. Wait 1 seconds using sleep(1) call
ii. Call stat system call to extract the file attributes against given files in command line arguments (the lookout.c program in p.56 may accept up to 10 files). Your program should be able to accept up to 10 files for monitoring.
iii. You program should check any changes in any of the following attributes:
1. st_mode
2. st_nlink
3. st_size
4. st_atime
5. st_mtime
iv. When your program detects any changes, your program should immediately print out number codes given below and EXIT!
1. Change of st_mode print 1
2. Change of st_nlink print 2
3. Change of st_size print 3
4. Change of st_atime print 4
5. Change of st_mtime print 5
6. 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)!
7. Example output when you change the file contents (e.g, using vi): 345
8. 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The World Wide Web And Databases International Workshop Webdb 98 Valencia Spain March 27 28 1998 Selected Papers Lncs 1590

Authors: Paolo Atzeni ,Alberto Mendelzon ,Giansalvatore Mecca

1st Edition

3540658904, 978-3540658900

More Books

Students also viewed these Databases questions