summaryrefslogtreecommitdiff
path: root/inotify.c
diff options
context:
space:
mode:
Diffstat (limited to 'inotify.c')
-rw-r--r--inotify.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/inotify.c b/inotify.c
new file mode 100644
index 0000000..6059d20
--- /dev/null
+++ b/inotify.c
@@ -0,0 +1,29 @@
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+typedef int FD ;
+
+int main() {
+ FD filed = open("/tmp/test_inotify", O_RDWR );
+ char buf[128];
+
+ if( !filed ) {
+ printf("Openfile error\n");
+ exit(-1);
+ }
+
+ int nbytes;
+ while(1) {
+ nbytes = read(filed, buf, 16);
+ printf("read %d bytes from file.\n", nbytes);
+ if(nbytes > 0) {
+ printf("%s\n", buf); // split buffer by new line.
+ }
+ sleep(1);
+ }
+ return 0;
+}