Question: #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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!