-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinterrupt.c
66 lines (58 loc) · 995 Bytes
/
interrupt.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "interrupt.h"
int kbhit2()
{
struct timeval tv = { 0L, 0L };
fd_set fds;
FD_ZERO(&fds);
FD_SET(0, &fds);
return select(1, &fds, NULL, NULL, &tv);
}
int getch2()
{
int r;
unsigned char c;
if ((r = read(0, &c, sizeof(c))) < 0) {
return r;
} else {
return c;
}
}
void interrupt()
{
int pcnt=0;
int waittime = atoi(arg[i+2]);
time_t starttime,curtime;
starttime=time(NULL);
while(!kbhit2())
{
while(1)
{
curtime = time(NULL);
if(curtime - starttime >= waittime)
break;
}
FILE * fp = fopen("/proc/interrupts","r");
int linecount=0;
while (fgets(line, sizeof(line), fp) != NULL)
{
if (strstr(line,"CPU") && pcnt==0)
{
printf("%s", line);
pcnt=1;
}
if (strstr(line,"i8042"))
{
printf("%s", line);
linecount++;
if (linecount==2)
{
break;
}
}
}
sleep(waittime);
fclose(fp);
}
i+=4;
(void)getch2();
}