Question: PLEASE HELP! C PROGRAM ONLY, PLEASE!!! TNX! Create 2 programs with the following functionalities: Prog1.c: (1st new code to be written) Open up a new
PLEASE HELP! C PROGRAM ONLY, PLEASE!!! TNX!
Create 2 programs with the following functionalities:
Prog1.c: (1st new code to be written)
- Open up a new file, test.txt, for reading and writing (and with a permission mode of 0644)
- Repeat the following steps 10 times
- Write a string abcdefg to the file
- Wait 2 seconds using sleep() call
- Change the files permission mode to 0666
- Wait 2 seconds using sleep() system call
- Link the file test.txt with a different file name tset.txt using the link system call
- Wait 2 seconds using the sleep() system call
- Unlink the file name tset.txt using the unlink system call
- Wait 2 seconds using the sleep() system call
- Read 80 characters from test.txt
Prog2.c:
Modify the template program, lookout.c below these questions with the following additional capabilities
- Repeat the following steps 100 times
- Wait 1 seconds using sleep() call
- Call stat system call to extract the file attributes against test.txt
- If you find any changes in any of the attributes,
- 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.
prog2.c (2nd code to be modified)
// lookout -- print message when file changes
#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);
}
//int stat(const char *path, struct stat *buf);
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); } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
