forked from h2oai/h2o-2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flush.c
38 lines (36 loc) · 1.07 KB
/
flush.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
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
int main(void) {
printf("Flushing page cache, dentries and inodes...\n");
if (geteuid() != 0) {
fprintf(stderr, "flush-cache: Not root\n");
exit(EXIT_FAILURE);
}
if (system("sync") != 0) {
fprintf(stderr, "flush-cache: sync failed (first time)\n");
exit(EXIT_FAILURE);
}
if (system("sync") != 0) {
fprintf(stderr, "flush-cache: sync failed (second time)\n");
exit(EXIT_FAILURE);
}
if (system("sync") != 0) {
fprintf(stderr, "flush-cache: sync failed (third time)\n");
exit(EXIT_FAILURE);
}
FILE* f;
f = fopen("/proc/sys/vm/drop_caches", "w");
if (f == NULL) {
fprintf(stderr, "flush-cache: Couldn't open /proc/sys/vm/drop_caches\n");
exit(EXIT_FAILURE);
}
if (fprintf(f, "3\n") != 2) {
fprintf(stderr, "flush-cache: Couldn't write 3 to /proc/sys/vm/drop_caches\n");
exit(EXIT_FAILURE);
}
fclose(f);
printf("Done flushing.\n");
return 0;
}