-
Notifications
You must be signed in to change notification settings - Fork 3
/
interrupt.c
84 lines (76 loc) · 1.87 KB
/
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include "main.h"
#define MYARRSIZE 3
int endingCondition(ll time, char *c[]){
struct timeval tv;
tv.tv_usec = 0;
tv.tv_sec = time;
fd_set fd;
FD_ZERO(&fd);
FD_SET(0, &fd);
select(1, &fd, NULL, NULL, &tv);
return FD_ISSET(0, &fd);
}
void interrupt(long long totalArgsInEachCommand, char *c[]) {
// Openfile
FILE * file = fopen("/proc/interrupts","r");
if(!file) {
perror("Error ");
return;
}
// Stores each line in the file
char CPU_line[SIZE];
ll time = atoi(c[2]);
fgets(CPU_line, SIZE, file);
printf("%s\n", CPU_line);
fclose(file);
ll lenCPU = strlen(CPU_line);
int i = lenCPU - 1;
while(i >= 0) {
if(!(CPU_line[i] == '\n' || CPU_line[i] == '\t' || CPU_line[i] == ' ')) {
i--;
break;
}
else {
CPU_line[i] = '\0';
i--;
}
}
int pos = 0;
char inputKey;
lenCPU = strlen(CPU_line);
while(pos == 0) {
file = fopen("/proc/interrupts", "r");
if(!file) {
perror("Error ");
return;
}
char myArr[MYARRSIZE][SIZE];
i = 0;
while(i < MYARRSIZE) {
fgets(myArr[i], SIZE - 1, file);
i++;
}
myArr[MYARRSIZE - 1][lenCPU] = '\0';
i = 0;
while(i < lenCPU) {
if(myArr[MYARRSIZE - 1][i] == ':'){
myArr[MYARRSIZE - 1][i] = ' ';
myArr[MYARRSIZE - 1][i-1] = ' ';
i++;
break;
}
else {
myArr[MYARRSIZE - 1][i] = ' ';
i++;
}
}
printf("%s\n", myArr[MYARRSIZE - 1]);
fclose(file);
pos = endingCondition(time, c);
if(pos != 0) {
inputKey = fgetc(stdin);
if(inputKey != 'q') pos = 0;
else pos = 1;
}
}
}