-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdirty.c
More file actions
101 lines (97 loc) · 1.35 KB
/
Copy pathdirty.c
File metadata and controls
101 lines (97 loc) · 1.35 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include"header.h"
int kbhit()
{
struct timeval tv;
fd_set fds;
tv.tv_sec=0;
tv.tv_usec=0;
FD_ZERO(&fds);
FD_SET(0,&fds);
select(1,&fds,NULL,NULL,&tv);
return FD_ISSET(0,&fds);
}
void nonblock(int state)
{
struct termios ttystate;
tcgetattr(0,&ttystate);
if (state==0)
{
ttystate.c_lflag&=~ICANON;
ttystate.c_cc[VMIN]=1;
}
else
{
ttystate.c_lflag|=ICANON;
}
tcsetattr(0,TCSANOW,&ttystate);
}
void finddirtysize()
{
FILE* f=fopen("/proc/meminfo","r");
char buf[10000];
for(int i=0;i<50;i++)
{
fscanf(f,"%s",buf);
}
printf("Dirty Mem : %s kB\n",buf);
}
void dirty(char **c)
{
if(!(size1==2 || size1==4))
{
printf("watch : Invalid Syntax\n");
return ;
}
int tim;
if(size1==2 && strcmp(c[1],"dirty")==0)
{
tim=2;
}
else
{
if(size1==4 && strcmp(c[1],"-n")==0)
{
if(strcmp(c[3],"dirty")==0)
{
tim=atoi(c[2]);
}
else
{
printf("watch : Invalid Syntax\n");
return ;
}
}
else
{
printf("watch : Invalid Syntax\n");
return ;
}
}
int i=0;
long long int initime=time(0),prev=-1,inter;
char ch;
nonblock(0);
while(!i)
{
i=kbhit();
inter=time(0);
if((inter-initime)%tim==0 && prev!=inter)
{
prev=inter;
finddirtysize();
}
if(i!=0)
{
ch=fgetc(stdin);
if(ch=='q')
{
i=1;
}
else
{
i=0;
}
}
}
nonblock(1);
}