/*************************************************************************
> File Name: inotify.c
> 监测一个目录下的文件变化,增加或删除提示
> Created Time: Thu 21 Sep 2017 02:41:48 PM CST
************************************************************************/ #include <stdio.h>
#include <sys/inotify.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h> int read_process_inotify_fd(int inotify_fd)
{
int res;
char event_buf[];
int event_size;
int event_pos = ;
struct inotify_event *event;
res = read(inotify_fd, event_buf, sizeof(event_buf));
if(res < sizeof(struct inotify_event))
{
if(errno == EINTR)
{
return ;
}
printf("can not get event ,%s\n",strerror(errno));
return -;
} while(res >= (int)sizeof(*event)) {
event = (struct inotify_event *)(event_buf + event_pos); //指向下一个结构体
if(event->len) {
if(event->mask & IN_CREATE) {
printf("Add device '%s' due to inotify event\n", event->name);
} else {
printf("Removing device '%s' due to inotify event\n", event->name);
}
}
event_size = sizeof(*event) + event->len;
res -= event_size;
event_pos += event_size; //跳转到下一个结构体
}
return ;
} int main(int argc ,char **argv)
{
int fd;
if(argc < )
{
printf("Usage: %s <dir>\n",argv[]);
return -;
}
// inotify_init
fd = inotify_init();
// add watch
//添加监控:argv[1]监控目录,IN_DELETE|IN_CREATE 监控 创建和删除
inotify_add_watch(fd, argv[], IN_DELETE|IN_CREATE);
// read
while()
{
read_process_inotify_fd(fd);
}
return ;
}

inotify监测实例的更多相关文章

  1. 源码包的安装、rsync同步、inotify监测

    一.源码包的安装 1.源码包的作用:yum 使用的是rpm包,rpm包安装的不能指定安装位置 源码包可以按需选择/定制,及时修复bug ,适用于各种平台 2.大致过程:源码包——>make gc ...

  2. Inotify机制的简单应用

    编程之路刚刚开始,错误难免,希望大家能够指出. 一.Inotify机制 1.简单介绍inotify:Inotify可用于检测单个文件,也可以检测整个目录.当检测的对象是一个目录的时候,目录本身和目录里 ...

  3. 028_rync和inotify实现实时备份

    一.服务节点安装inotify-tools. 确保系统后以下输出=> [root@xxxx]# ll /proc/sys/fs/inotify/ total 0 -rw-r--r-- 1 roo ...

  4. Linux内核Inotify机制学习笔记

    一.Inotify简介: Inotify是一种文件变化通知机制,Linux内核从2.6.13开始引入.它是一个内核用于通知用户空间程序文件系统变化的机制.开源社区提出用户态需要内核提供一些机制,以便用 ...

  5. Windows Azure Cloud Service (10) Role的生命周期

    <Windows Azure Platform 系列文章目录> 在上一章内容中,我们提到了Windows Azure会依次调用角色(Role)实例的OnStart()方法和Run()方法. ...

  6. Windows与Linux下文件操作监控的实现

    一.需求分析: 随着渲染业务的不断进行,数据传输渐渐成为影响业务时间最大的因素.究其原因就是因为数据传输耗费较长的时间.于是,依托于渲染业务的网盘开发逐渐成为迫切需要解决的需求.该网盘的实现和当前市场 ...

  7. kvo本质探寻

    一.概述 1.本文章内容,须参照本人的另一篇博客文章“class和object_getClass方法区别”加以理解: 2.基本使用: //给实例对象instance添加观察者,监听该实例对象的某个属性 ...

  8. TypeScript完全解读(26课时)_11.TypeScript完全解读-类型推论和兼容性

    11.TypeScript完全解读-类型推论和兼容性 在一些时候省略指令,ts会帮我们推断出省略的类型的地方适合的类型,通过学习ts的类型推论了解ts的推论规则 类型兼容性就是为了适应js灵活的特点, ...

  9. 10.5 android输入系统_Reader线程_使用EventHub读取事件和核心类及配置文件_实验_分析

    4. Reader线程_使用EventHub读取事件 使用inotify监测/dev/input下文件的创建和删除 使用epoll监测有无数据上报 细节: a.fd1 = inotify_init(& ...

随机推荐

  1. 使用Bus.js进行兄弟(非父子)组件通信

    首先需要在任意地方添加一个bus.js: 在bus.js里面 写入下面信息 import Vue from 'vue' export default new Vue; 在需要通信的组件都引入Bus.j ...

  2. Python+Flask+MysqL的web建设技术过程

    一.前言(个人学期总结) 个人总结一下这学期对于Python+Flask+MysqL的web建设技术过程的学习体会,Flask小辣椒框架相对于其他框架而言,更加稳定,不会有莫名其妙的错误,容错性强,运 ...

  3. Jquery倒计时源码分享

    在静态页添加显示倒计时的容器,并引用下面脚本,代入时间参数即可使用. timeoutDate——到期时间,时间格式为2014/01/01或2014/1/1 D——天 H——小时 M——分钟 S——秒 ...

  4. 进程间通信IPC

    body, table{font-family: 微软雅黑; font-size: 13.5pt} table{border-collapse: collapse; border: solid gra ...

  5. ASPX 后台调用前台Js

    1.UpdatePanel 使用中 protected void Button1_Click(object sender, EventArgs e) { this.Label1.Text = &quo ...

  6. java中break,continue,标签实现goto效果(编程思想)

    goto 编程语言中一开始就有goto关键词了.事实上,goto起源于汇编语言的程序控制:“若条件A成立,则调到这里:否则跳到那里”. goto语句时在源码级别上的跳转,这导致了其不好的名誉.于是go ...

  7. Outpost Security Suite Pro 8.1 – 免费4个月

    OSS( 简称 )一款来自俄罗斯Agnitum公司的互联网安全产品. Outpost以网络防火墙知名,AVG和avast!等知名安全企业都有使用Outpost的防火墙技术. Outpost Secur ...

  8. New Concept English Two 26 70

    $课文68  纠缠不休 712. I crossed the street to avoid meeting him, but he saw me and came running towards m ...

  9. Field 'id' doesn't have a default value 原因

    Field 'id' doesn't have a default value昨晚做项目的时候遇到一个问题,在测试数据存储的时候老是报Field 'id' doesn't have a default ...

  10. npm 与 package.json 快速入门

    npm 是前端开发广泛使用的包管理工具,之前使用 Weex 时看了阮一峰前辈的文章了解了一些,这次结合官方文章总结一下,加深下理解吧! 读完本文你将了解: 什么是 npm 安装 npm 更新 npm ...