Skip to content

Instantly share code, notes, and snippets.

@kostja

kostja/inotify.c

Created Jan 14, 2015
Embed
What would you like to do?
#include <stdio.h>
#include <unistd.h>
#include <sys/inotify.h>
int main(int argc, char *argv[])
{
if (argc < 2) {
fprintf(stderr, "Usage: %s path\n", argv[0]);
return -1;
}
const char *path = argv[1];
if (access(path, R_OK)) {
fprintf(stderr, "Path %s does not exist\n", path);
return -1;
}
fprintf(stdout, "Watching %s\n", path);
int inotify_fd = inotify_init();
int i;
for (i = 0; i < 100000; i++) {
int wd = inotify_add_watch(inotify_fd, path, IN_ALL_EVENTS);
if (wd < 0) {
fprintf(stderr, "add watch failed\n");
return -1;
}
inotify_rm_watch(inotify_fd, wd);
}
close(inotify_fd);
return 0;
}
kostja@atlas ~ % gcc ./inotify.c; time ./a.out /home/kostja/work/tarantool/src/box/lua/schema.lua
Watching /home/kostja/work/tarantool/src/box/lua/schema.lua
./a.out /home/kostja/work/tarantool/src/box/lua/schema.lua 0.00s user 0.36s system 98% cpu 0.366 total
kostja@atlas ~ % time ./a.out /home/kostja/inotify.c
Watching /home/kostja/inotify.c
./a.out /home/kostja/inotify.c 0.00s user 0.23s system 97% cpu 0.237 total
kostja@atlas ~ % time ./a.out /home
Watching /home
./a.out /home 0.00s user 0.23s system 97% cpu 0.241 total
kostja@atlas ~ % time ./a.out /var
Watching /var
./a.out /var 0.00s user 0.25s system 98% cpu 0.263 total
kostja@atlas ~ % time ./a.out /tmp
Watching /tmp
./a.out /tmp 0.00s user 4.99s system 98% cpu 5.053 total
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.