Skip to content

Instantly share code, notes, and snippets.

@keyurdg
Created May 28, 2013 05:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save keyurdg/5660719 to your computer and use it in GitHub Desktop.
Save keyurdg/5660719 to your computer and use it in GitHub Desktop.
Create tons of dentry cache entries
#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <errno.h>
int main(int argc, char **argv) {
char *prefix;
char *open_mode;
char filename[1024];
int i = 0;
FILE *fd = NULL;
if (argc < 3) {
fprintf(stderr, "2 params expected: fopen <temp dir name> <file open mode>\n");
return 1;
}
prefix = argv[1];
open_mode = argv[2];
sprintf(filename, "/tmp/%s", prefix);
if (mkdir(filename, 0777)) {
if (errno != EEXIST) {
fprintf(stderr, "Unable to create %s\n", filename);
return 2;
}
}
while (1) {
sprintf(filename, "/tmp/%s/%d", prefix, i);
fd = fopen(filename, open_mode);
if (fd != NULL) fclose(fd);
++i;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment