Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program which allows the user to monitor a single file / collection of files and obtain information whenever any of them are modified.

Write a program which allows the user to monitor a single file / collection of files and obtain information whenever any of them are modified. Here is how the program should be run.

% monitor [-t delay] [-l count] fileName

If the fileName is a directory, all of the files inside the directory and sub-directories are scanned. The default time between scans is 10 seconds which can be overridden by the [-t delay] option. By default the monitor program should scan forever unless overridden by the [-l count] option (in which case it scans only count times). File modification is indicated as follows: ADDED - Indicates that the file was created since the last scan. Every file is given this label during the first scan CHANGED - Indicates that the file was modified since the last scan DELETED - Indicates that the file was deleted since the last scan A structure of this form will be helpful in completing your assignment:

struct statinfo { char fileName[MAX_FILENAME]; /* File Name */ int lastCycle, thisCycle; /* To detect changes */ struct stat status; /* Information from stat() */ };

Use the stat() function to obtain information on files, and getdents() to scan directories. The decoding of time can be done by using localtime() and asctime() or any other time functions. Here is a sample output. Your ouput should look similar to this. % monitor -t5 -l20 /temp (where temp is the name of a directory)

Scan 1: ADDED - /temp/a.txt ADDED - /temp/hello.c ADDED - /temp/java/more.java ADDED - /temp/java/hello.c

Scan 2: ADDED - /temp/data.txt

Scan 3:

Scan 4:

Scan 5: CHANGED - /temp/java/hello.c

Scan 6: DELETED - /temp/a.txt ... Scan 20: CHANGED - /temp/java/more.java

Note: 1. You have to perform error checking throughout your program. 2. Comment and document all code submitted!

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

Big Data, Mining, And Analytics Components Of Strategic Decision Making

Authors: Stephan Kudyba

1st Edition

1466568704, 9781466568709

Students also viewed these Databases questions

Question

What are the stages of project management? Write it in items.

Answered: 1 week ago

Question

why do consumers often fail to seek out higher yields on deposits ?

Answered: 1 week ago