Skip to content

Instantly share code, notes, and snippets.

@alexras
Created July 3, 2012 20:28
Show Gist options
  • Select an option

  • Save alexras/3042839 to your computer and use it in GitHub Desktop.

Select an option

Save alexras/3042839 to your computer and use it in GitHub Desktop.
Tell the kernel to drop the page cache
#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