Prog2.c: Modify the template program, "lookout.c on p. 56-57 with the following additional capabilities a. Repeat the following steps 100 times x. Wait 1 seconds using "sleep" call xi. Call "stat system call to extract the file attributes against "test.txt" xii. If you find any changes in any of the attributes, 1. Print the information on which attribute is changed. Make sure to print the previous value and the new value (i.e., the changed attribute value). There may exist more than 1 attribute values changed. 56 The file in context /display file information printf(" File is : ", pathname); printf("Size Uld bytesin", statbuf.st Sizel: printf("User-id id, Group-id d ", statbuf.st_uid, statbuf.st.gid); printf("Permissions: Is ", descrip); return (0) The following program lookout is a more useful tool. Given a list of filenames, it checks once a minute to see if any file in the list has changed. It does This by monitoring the modification time of each file (stuntine). It is a utility intended to be run as a background process. lookout - print message when file changes #include
include #include #define MFILE 10 void cmp(const char struct stat sb; tine_t); main(int arge, char **argv) int i; time_t last time IMBILE+11; if(argc MFILE) fprintf(stderr, "lookout: too many filenames "); exit (1) 1* initialization / for(j=1; jc-arge; j++) if (stat (argvlj), sb) == -1) fprintf(stderr, "lookout: couldn't stat Isin", argvlj)); exit(); last_tine 13) -sb.st_ntime; Obtaining file information: stat and fstat 57 /* loop until file changes */ for(;;) for (-1; j include #include #define MFILE 10 void cmp(const char struct stat sb; tine_t); main(int arge, char **argv) int i; time_t last time IMBILE+11; if(argc MFILE) fprintf(stderr, "lookout: too many filenames "); exit (1) 1* initialization / for(j=1; jc-arge; j++) if (stat (argvlj), sb) == -1) fprintf(stderr, "lookout: couldn't stat Isin", argvlj)); exit(); last_tine 13) -sb.st_ntime; Obtaining file information: stat and fstat 57 /* loop until file changes */ for(;;) for (-1; j