Created
January 28, 2013 12:05
-
-
Save khayrov/4654988 to your computer and use it in GitHub Desktop.
Try to remove file from page cache
This file contains 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 <string.h> | |
#include <errno.h> | |
#include <unistd.h> | |
#include <sys/types.h> | |
#include <sys/stat.h> | |
#include <fcntl.h> | |
int main(int argc, char **argv) | |
{ | |
int i; | |
if (argc < 2) | |
{ | |
fprintf(stderr, "Usage: %s <file> [<files>]\n", argv[0]); | |
return 1; | |
} | |
for (i = 1; i < argc; ++i) | |
{ | |
const char *fname = argv[i]; | |
struct stat st; | |
int fd = open(fname, O_RDONLY); | |
if (fd < 0) | |
{ | |
printf("Cannot open '%s': %s\n", fname, strerror(errno)); | |
continue; | |
} | |
if (fstat(fd, &st)) | |
{ | |
printf("Cannot stat() '%s': %s\n", fname, strerror(errno)); | |
close(fd); | |
continue; | |
} | |
if (posix_fadvise(fd, 0, st.st_size, POSIX_FADV_DONTNEED)) | |
{ | |
printf("posix_fadvise() failed on '%s': %s\n", fname, strerror(errno)); | |
close(fd); | |
continue; | |
} | |
close(fd); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment