I tried to do as torek suggested but it worked only partly as it changes the modification time no matter I touch the keyboard (during the sleep) or not. Here is what I did
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <time.h>
#include <unistd.h>
#include <signal.h>
#include <stddef.h>
#include <string.h>
char *modTime;
void getmt();
time_t modifiedTime;
struct stat statbuf;
int main(int argc, char **argv)
{
int i, status = 0;
time_t now;
if (argc == 1) {
fprintf(stderr, "usage: %s file \n", argv[0]);
return(1);
}
for (i = 1; i < argc; i++)
{
//struct stat statbuf;
if (lstat(argv[i], &statbuf)) {
perror(argv[i]);
status = 1;
}
else
{
getmt();
time(&now);
printf("\nNOW %ld\n", now);
}
}
sleep(20);
for (i = 1; i < argc; i++)
{
if (lstat(argv[i], &statbuf)) {
perror(argv[i]);
status = 1;
}
else
{
time(&now);
printf("after sleep %ld\n", now);
getmt();
}
}//for
return(status);
}
void getmt()
{
time_t modifiedTime;
//modification time of tty as string
modTime = ctime(&statbuf.st_mtime);
printf("\n last modified time as string %s\n", modTime);
//modification time of tty as long date
modifiedTime = statbuf.st_mtime;
printf ("last modified time as long date %ld\n", modifiedTime);
}