09/07/10 23:51:59
>>827
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
#define SLEEP_TIME 1
int main(int argc, char *argv[])
{
struct stat file;
time_t prev_mtime;
if (argc != 2) {
printf("Usage: exp7 file1 file2\n");
exit(1);
}
if (stat(argv[1], &file) != 0) {
printf("%s not found\n", argv[1]);
exit(1);
}
prev_mtime = file.st_mtime;
while (1) {
stat(argv[1], &file);
if (file.st_mtime != prev_mtime) {
printf("\nModified %s %s", argv[1],
asctime(localtime(&file.st_mtime)));
prev_mtime = file.st_mtime;
}
sleep(SLEEP_TIME);
}
}