Created
July 3, 2012 20:28
-
-
Save alexras/3042839 to your computer and use it in GitHub Desktop.
Tell the kernel to drop the page cache
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <unistd.h> | |
| #include <sys/types.h> | |
| #include <sys/stat.h> | |
| #include <fcntl.h> | |
| int main(int argc, char **argv) { | |
| sync(); | |
| int fd = open("/proc/sys/vm/drop_caches", O_WRONLY); | |
| if (fd == -1) { | |
| perror("open()"); | |
| return 1; } | |
| ssize_t result = write(fd, "1", 1); | |
| if (result == -1) { | |
| perror("write()"); | |
| return 2; | |
| } | |
| if (close(fd) == -1) { | |
| perror("close()"); | |
| return 3; | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment