
Individual was in a Unix, Linux programming practice book, do here didn't force, I try to use the stat function to read/dev/PTS/19 command shown in the terminal name (ps), and obtain atim and mtim, and/dev/the atim tty7 and mtim,
My idea is that
Set a itimer, first read/dev/PTS/19 atime, read your program I set the maximum time taccess, set the countdown to taccess seconds of itimer, and after a timeout, triggering a SIG_ALRM signal, awaken the signal service program, atime reading again, if there is no change, program exits, if have change, return the service procedure,
Ps: this time really not enough accurate
But I try to service program in the timer to run only after the print tty atime, found tty atime won't have change, even if I won't refresh, type the command in bash in distress, is the place where I read it? Few words said, the first code,
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
Void sendKill (int s);
Int set_ticker (int n_msecs);
Int Tcount=0;
Int pid=0;
Int Taccess=0;
Int times=0;
Struct stat file_info;
//set a timer, the when it drained, the program will send a sigkill signal to the pid you want
Int main (int ac, char * * av)
{
Tcount=atoi (av [1]);
Pid=atoi (av [2]);
Printf (" \ t Tcount: % d ", Tcount);
Printf (" pid: % d \ n ", pid);
If (stat ("/dev/PTS/19 ", & amp; File_info))
Perror (" stat ");
Taccess=file_info. St_atim. Tv_nsec;
//set itimer
Set_ticker (5000);
Alarm (5);
Signal (SIGALRM sendKill);
Printf (" Taccess first % d \ n ", Taccess);
While (1) {
Pause ();
}
}
Void sendKill (int s)
{
Signal (SIGALRM sendKill);
Int TMP.
If (stat ("/dev/PTS/19 ", & amp; File_info))
Perror (" stat ");
TMP=file_info. St_mtim. Tv_nsec;
Printf (" \ n \ n % d ", TMP);
Times++;
If (times & gt; 3)
exit(1);
}
CodePudding user response:

There is still no change even if I refresh the terminal time