Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Modify the template program, lookout . c on p . 5 6 - 5 7 with the following additional capabilities Repeat the following steps 5
Modify the template program, lookoutc on p with the following additional capabilities
Repeat the following steps times this means, after seconds of running, your program should terminate without printing anything if there is no change detected.
Wait seconds using sleep call
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.
You program should check any changes in any of the following attributes:
stmode
stnlink
stsize
statime
stmtime
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.
Important: if your program doesnt print the corresponding number codes or if it prints more information than number codes, then your program will fail the tests, and you will get zero point for the tests. If there is no change detected during your program's execution, your program should exit without printing anything.
Testing of your program can be done by opening two terminals, and run lookout in one terminal and, in another terminal, make some changes to the file contents, file permission modes, number of links, by using a variety of shell commands such as vichmodlinkunlink etc.
In the terminal where lookoutc is running, the program should print the assigned code into display and exit.
Here is the lookout.c template program:
lookout print message when file changes
#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;
int statconst char path struct stat buf;
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;
Please show test runs so I can compare if something goes wrong when I test it myself.
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