如何在linux中使用inotify实现linux文件系统详解的监控(php接口)

1 What&s inotify
The inotify API provides a mechanism for monitoring file system events. Inotify can be used to monitor individual files, or to monitor directories. When a directory is monitored, inotify will return events for the directory itself, and for files inside the directory.&&
2 How to use inotify
2.1 system calls used with this API
The following system calls are used with this API: inotify_init(orinotify_init1), inotify_add_watch, inotify_rm_watch, read, and close.
2.1.1 inotify_init
It creates an inotify instance and returns a file descriptor referring to the inotify instance. The more recent inotify_init1 is like inotify_init, but provides some extra functionality.
2.1.2 inotify_add_watch
It manipulates the &watch list& associated with an inotify instance. Each item (&watch&) in the watch list specifies the pathname of a file or directory, along with some set of events that the kernel should monitor for the file referred to by that pathname.
inotify_add_watch either creates a new watch item, or modifies an existing watch. Each watch has a unique &watch descriptor&, an integer returned by inotify_add_watch when the watch is created.
2.1.3 inotify_rm_watch
It removes an item from an inotify watch list.
When all file descriptors referring to an inotify instance have been closed, the underlying object and its resources are freed for all associated watches are automatically freed.
2.1.4 read
To determine what events have occurred, an application reads from the inotify file descriptor. If no events have so far occurred, then, assuming a blocking file descriptor, read will block until at least one event occurs (unless interrupted by a signal, in which case the call fails with the error EINTR; see signal(7)).
Each successful read returns a buffer containing one or more of the following structures:
struct inotify_event {
&&& int&&&&&&&&&&& /* Watch descriptor */
&&& uint32_&&&& /* Mask of events */
&&& uint32_&& /* Unique cookie associating related events (for rename ) */
&&& uint32_&&&&& /* Size of name field */
&&& char&&&& name[];&& /* Optional null-terminated name */
2.2 Inotify events
The inotify_add_watch mask argument and the mask field of the inotify_event structure returned when reading an inotify file descriptor are both bit masks identifying inotify events. The following bits can be specified in mask when calling inotify_add_watch and may be returned in the mask field returned by read:
IN_ACCESS &&&&&&&&&&&&&&&&&&&&&&&&&&& File was accessed (read) (*).
IN_ATTRIB &&&&&&&&&&&&&&&&&&&&&&&&&&&& Metadata changed, e.g., permissions, timestamps, extended attributes, link count (since Linux 2.6.25), UID, GID, etc. (*).
IN_CLOSE_WRITE &&&&&&&&&&&&&&&& File opened for writing was closed (*).
IN_CLOSE_NOWRITE &&&&&&&&&& File not opened for writing was closed (*).
IN_CREATE &&&&&&&&&&&&&&&&&&&&&&&&&&& File/directory created in watched directory (*).
IN_DELETE &&&&&&&&&&&&&&&&&&&&&&&&&&& File/directory deleted from watched directory (*).
IN_DELETE_SELF &&&&&&&&&&&&&&&&& Watched file/directory was itself deleted.
IN_MODIFY &&&&&&&&&&&&&&&&&&&&&&&&&& File was modified (*).
IN_MOVE_SELF&&&&&&&&&&&&&&&&&&&&& Watched file/directory was itself moved.
IN_MOVED_FROM &&&&&&&&&&&&&&& File moved out of watched directory (*).
IN_MOVED_TO &&&&&&&&&&&&&&&&&&&&& File moved into watched directory (*).
IN_OPEN &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& File was opened (*).
2.3 The flow for the systme calls used with inotify
3 Example used with Inotify
3.1 Description:
There are three subfunctions below : input_run, worker_thread,worker_cleanup.
The subfunction &input_run& is called by the main function .when it&s called,the input_run will creat a thread &worker_thread&. when the thread is exit it will call the &worker_cleanup&.
In the worker_thread we monitor the folder &/temp&.If a file(here it&s a picture) is move to the folder, we open it ,copy it&s context to a frame buffer for using ,then we delete the file if necessary.
3.2 source code:&
#include& &stdio.h&
#include& &stdlib.h&
#include& &unistd.h&
#include& &pthread.h&
#include& &sys/inotify.h&
/* global variables for this plugin */
static char *folder = /
staticint fd, rc, wd,
staticstruct inotify_event *
int input_run(int id)
&&& pglobal-&in[id].buf = NULL;
&&& rc = fd = inotify_init();
&&& if(rc == -1) {
&&&&&&& perror(&could not initilialize inotify&);
&&&&&&& return 1;
&&& rc = wd = inotify_add_watch(fd, folder, IN_CLOSE_WRITE | IN_MOVED_TO | IN_ONLYDIR);
&&& if(rc == -1) {
&&&&&&& perror(&could not add watch&);
&&&&&&& return 1;
&&& size = sizeof(struct inotify_event) + (1 && 16);
&&& ev = malloc(size);
&&& if(ev == NULL) {
&&&&&&& perror(&not enough memory&);
&&&&&&& return 1;
&&& if(pthread_create(&worker, 0, worker_thread, NULL) != 0) {
&&&&&&& free(pglobal-&in[id].buf);
&&&&&&& fprintf(stderr, &could not start worker thread\n&);
&&&&&&& exit(EXIT_FAILURE);
&&& pthread_detach(worker);
&&& return 0;
/* the single writer thread */
void *worker_thread(void *arg)
&&& char buffer[1&&16];
&&& size_t filesize = 0;
&&& struct
&&& /* set cleanup handler to cleanup allocated ressources */
&&& pthread_cleanup_push(worker_cleanup, NULL);
&&& while(!pglobal-&stop) {
&&&&&&& /* wait for new frame, read will block until something happens */
&&&&&&& rc = read(fd, ev, size);
&&&&&&& if(rc == -1) {
&&&&&&&&&&& perror(&reading inotify events failed&);
&&&&&&&&&&& break;
&&&&&&& /* sanity check */
&&&&&&& if(wd != ev-&wd) {
&&&&&&&&&&& fprintf(stderr, &This event is not for the watched directory (%d != %d)\n&, wd, ev-&wd);
&&&&&&&&&&& continue;
&&&&&&& if(ev-&mask & (IN_IGNORED | IN_Q_OVERFLOW | IN_UNMOUNT)) {
&&&&&&&&&&& fprintf(stderr, &event mask suggests to stop\n&);
&&&&&&&&&&& break;
/***************** your reaction to the enent******************/
&&&&&&& /* prepare filename */
&&&&&&& /* check if the filename matches specified parameter (if given)*/&&
&&&&&&& /* open file for reading */
&&&&&&& /* approximate size of file */
&&&&&&& /* copy frame from file to global buffer */
&&&&&&& pthread_mutex_lock(&pglobal-&in[plugin_number].db);
&&&&&&& /* allocate memory for frame */
&&&&&&& /* signal fresh_frame */
&&&&&&& pthread_cond_broadcast(&pglobal-&in[plugin_number].db_update);
&&&&&&& pthread_mutex_unlock(&pglobal-&in[plugin_number].db);
&&&&&&& /* close file */
&&&&&&& /* delete file if necessary */
/***************** your reaction to the event*******************/
&&& DBG(&leaving input thread, calling cleanup function now\n&);
&&& /* call cleanup handler, signal with the parameter */
&&& pthread_cleanup_pop(1);
&&& return NULL;
void worker_cleanup(void *arg)
&&& staticunsignedchar first_run = 1;
&&& if(!first_run) {
&&&&&&& DBG(&already cleaned up ressources\n&);
&&&&&&& return;
&&& first_run = 0;
&&& DBG(&cleaning up ressources allocated by input thread\n&);
&&& if(pglobal-&in[plugin_number].buf != NULL) free(pglobal-&in[plugin_number].buf);
&&&free(ev);
&&& rc = inotify_rm_watch(fd, wd);
&&& if(rc == -1) {
&&&&&&& perror(&could not close watch descriptor&);
&&& rc = close(fd);
&&& if(rc == -1) {
&&&&&&& perror(&could not close filedescriptor&);
旗下网站:
与非门科技(北京)有限公司 All Rights Reserved.
京ICP证:070212号
北京市公安局备案编号: 京ICP备:号如果修改了/etc/passwd文件,则把这个事件记录在文件/root/modify_passwd.txt里
inotifywait -m /etc/passwd -e
/root/modify_passwd.txt
如果不加参数-e的话,默认就是监控所有的事件,在日常运维时,这个工具可以帮助你监控服务器上重要文件和重要目录的变化情况。
相关资讯 & & &
& (11/20/:14)
图片资讯 & & &
   同意评论声明
   发表
尊重网上道德,遵守中华人民共和国的各项有关法律法规
承担一切因您的行为而直接或间接导致的民事或刑事法律责任
本站管理人员有权保留或删除其管辖留言中的任意内容
本站有权在网站内转载或引用您的评论
参与本评论即表明您已经阅读并接受上述条款出处:http://blog.csdn.net
inotify是用来监视文件系统事件的机制,在linux 2.6.13内核中引入。该机制可以用来监视文件和目录,当文件或目录发生变化时,内核会将文件或目录的变化发送给inotify文件描述符,在应用层只需调用read()就可以读取这些事件,非常的方便。更好的是,inotify文件描述符还可以使用select、poll、epoll这些接口来监听,当有事件发生是,inotify文件描述符会可读。
一、接口介绍
1、inotify_init()
定义如下:
#include &sys/inotify.h&
int inotify_init(void);
int inotify_init1(int flags);
inotify_init()用来初始化一个新的inotify实例,并返回一个文件描述符。这个描述符在inotify_add_watch()中会用到,发生的事件也是从这个描述中读取。
除了这个接口外,还有一个相同功能的接口inotify_init1()。inotify_init1()中多了一个参数flags,用来在初始化时设置inotify文件描述符的属性。flags中可以设置的标志有两个:IN_NONBLOCK和IN_CLOEXEC。这两个标志不难理解,前一个是用来将inotify文件描述设置为非阻塞状态,后一个是设置close-on-exec(FD_CLOEXEC)标志。通过使用这两个标志就避免在创建inotify文件描述后再调用fcntl()的消耗了,代码看起来也会简洁一些。
2、inotify_add_watch()
定义如下:
#include &sys/inotify.h&
int inotify_add_watch(int fd, const char *pathname, uint32_t mask);
其中fd是inotify文件描述符,inotify_init()的返回值;pathname是要监听的文件的路径;mask是指定要监视哪些事件,在后面具体介绍。
inotify_add_watch()用于将要监视的文件或目录添加到inotify中,返回值是一个inotify标识,注意不要和inotify_init()的返回值搞混淆了。inotify_init()的返回值是在读取事件、注册监听文件时使用,而inotify_add_watch()的返回值用来判断返回的事件属于哪个监听的文件(后面介绍inotify_event结构时会看到),以及移除监听文件时使用。
3、inotify_rm_watch()
定义如下:
#include &sys/inotify.h&
int inotify_rm_watch(int fd, uint32_t wd);
inotify_rm_watch()用于移除对某个文件的监听,其中fd是inotify文件描述符,由inotify_init()返回;wd是inotify标识,由inotify_add_watch()返回。
二、结构及事件介绍
当有事件发生时,notify文件描述符会变为可读,调用read()可以读取发生的事件,事件的描述结构为inotify_event结构体,定义如下:
struct inotify_event {
/* Watch descriptor */
/* Mask of events */
/* Unique cookie associating related
events (for rename(2)) */
/* Size of name field */
/* Optional null-terminated name */
其中wd是inotify标识符,inotify_add_watch()的返回值;mask就是发生的事件掩码;cookie这个好像只在rename中使用,这里不关心;len是name的长度,包括空字符,name是引发事件的文件名,不包括路径。
首先说明inotify_event的长度问题,从定义中可以看出name的长度是可变的,所以一个事件对应的长度应该是sizeof(struct inotify_event)+len。
还有一个问题要特别说明,在read()的时候如果指定的缓冲区长度小于一个事件的长度(即sizeof(struct inotify_event)+len),这时内核会返回EINVAL错误。估计很多人都以为是ENOSPC错误,但是程序中实际会返回EINVAL错误,当然个人也以为返回ENOSPC会好一些。看了下2.6.32的内核代码,这个错误是在inotify_read()调用的get_one_event()函数中返回的,代码如下:
static struct fsnotify_event *get_one_event(struct fsnotify_group *group,
size_t count)
size_t event_size = sizeof(struct inotify_event);
struct fsnotify_event *
if (fsnotify_notify_queue_is_empty(group))
return NULL;
event = fsnotify_peek_notify_event(group);
if (event-&name_len)
event_size += roundup(event-&name_len + 1, event_size);
if (event_size & count)
return ERR_PTR(-EINVAL);
/* held the notification_mutex the whole time, so this is the
* same event we peeked above */
fsnotify_remove_notify_event(group);
所以在调用read从inotify文件描述符读取事件时一定要保证你的缓冲区的大小至少为sizeof(struct inotify_event)+NAME_MAX+1,其中NAME_MAX是文件名的最大值,linux下默认为255.
接下来介绍inotify中的事件,及mask的取值。下面的这些宏代表不同的事件,这些值在inotify_add_watch()中的mask参数和inotify_event结构中的mask成员中都可以使用,如下所示:
    IN_ACCESS: 文件被访问
IN_ATTRIB:元数据被改变,例如权限、时间戳、扩展属性、链接数、UID、GID等
IN_CLOSE_WRITE:关闭打开写的文件
IN_CLOSE_NOWRITE: 和IN_CLOSE_WRITE刚好相反,关闭不是打开写的文件
IN_CREATE:这个是用于目录,在监控的目录中创建目录或文件时发生
IN_DELETE:这个也是用于目录,在监控的目录中删除目录或文件时发生
IN_DELETE_SELF:监控的目录或文件本身被删除
IN_MODIFY:文件被修改,这种事件会用到inotify_event中的cookie。
IN_MOVE_SELF:监控的文件或目录本身被移动
IN_MOVE_FROM: 从监控的目录中移出文件
IN_MOVE_TO:向监控的目录中移入文件
IN_OPEN: 文件被打开
(注:linuxi下都可以抽象为文件,如果没有特别说明,文件可以指普通文件或目录)。
inotify还为我们定义了一个IN_ALL_EVENTS宏,这个宏包含了上面提到的所有事件,这个宏在调用inotify_add_watch()中使用。
下面的这些bit位只在调用inotify_add_watch()中会用到:
IN_DONT_FOLLOW:如果监控的文件时一个符号链接,只监控符号链接本身,而不是链接指向的文件
IN_MASK_ADD:对已监控的文件增加要监控的的事件(不是替换原先的掩码)
IN_ONESHOT:只监控指定的文件一次,事件发生后从监控列表移除
IN_ONLYDIR:如果监控的是一个目录,只监控目录本身(待定)
下面的这些bit位可能在read()读取到的事件中设置:
IN_IGNORED:监控被显式移除(调用inotify_rm_watch()),或者自动移除(文件被删除或者文件系统被卸载)
IN_ISDIR:引发事件的是一个目录
IN_Q_OVERFLOW:事件队列溢出(这种情况下inotify_event结构中的wd为-1)
IN_UMOUNT:包含监控对象的文件系统被卸载
inotify的资源限制可以通过/proc文件系统来修改,涉及的接口有:
/proc/sys/fs/inotify/max_queued_events:指定每个inotify实例的事件队列的最大长度,即可以缓存的事件个数
/proc/sys/fs/inotify/max_user_instances:每个用户可以创建的inotify实例的个数
/proc/sys/fs/inotify/max_user_watches:每个用户可以监控的文件的上限
参考资料:
1、man手册,命令:man inotify
作者:moonvs2010 发表于 15:15:41
阅读:77 评论:0
相关 [linux 目录 文件] 推荐:
- CSDN博客研发管理推荐文章
inotify是用来监视文件系统事件的机制,在linux 2.6.13内核中引入. 该机制可以用来监视文件和目录,当文件或目录发生变化时,内核会将文件或目录的变化发送给inotify文件描述符,在应用层只需调用read()就可以读取这些事件,非常的方便. 更好的是,inotify文件描述符还可以使用select、poll、epoll这些接口来监听,当有事件发生是,inotify文件描述符会可读.
inotify_init()用来初始化一个新的inotify实例,并返回一个文件描述符. 这个描述符在inotify_add_watch()中会用到,发生的事件也是从这个描述中读取.
除了这个接口外,还有一个相同功能的接口inotify_init1().
- Lamo - LinuxTOY
想了解 Linux 文件系统树形结构,却又不愿翻阅 FHS 的朋友,可以参考 skill2die4 制作的这张简图. 此图算是 FHS 的图形化版本,简要的说明了 Linux 系统中各个目录的用途及层级关系,适合初学者使用参考. 不过其中较新的如 /run 目录并未在其中出现. 分类: Screenshots,
Tips |. 收藏到 del.icio.us |.
- Mountain - 小程序员的草稿箱
在多任务操作系统环境中,如果一个进程尝试对正在被其他进程读取的文件进行写操作,可能会导致正在进行读操作的进程读取到一些被破坏或者不完整的数据;如果两个进程并发对同一个文件进行写操作,可能会导致该文件遭到破坏. 因此,为了避免发生这种问题,必须要采用某种机制来解决多个进程并发访问同一个文件时所面临的同步问题,由此而产生了文件加锁方面的技术. 早期的 UNIX 系统只支持对整个文件进行加锁,因此无法运行数据库之类的程序,因为此类程序需要实现记录级的加锁. 在 System V Release 3 中,通过 fcntl 提供了记录级的加锁,此后发展成为 POSIX 标准的一部分. 本文将基于 2.6.23 版本的内核来探讨 Linux 中文件锁的相关技术.
- oak - linuxtoy.org
想了解 Linux 文件系统树形结构,却又不愿翻阅 FHS 的朋友,可以参考 skill2die4 制作的这张简图. 此图算是 FHS 的图形化版本,简要的说明了 Linux 系统中各个目录的用途及层级关系,适合初学者使用参考. 不过其中较新的如 /run 目录并未在其中出现.
- 桔子 - (jobs, news)
贝壳原来一直认为文件系统可以随便选,结果最近吃了两次苦头. 一个是btrfs对虚拟机支持不良,另一个是特定情况下xfs性能比ext3高20倍. 痛定思痛,打算列一下文件系统选型的方法和依据,欢迎拍砖. 下面我列一下纳入参考的文件系统,当然,ntfs就不要出来搞基了,玩嵌入式/光盘live之类的朋友也不要来凑热闹了阿. btrfs(简介), ext3, ext4(简介), jfs(简介), reiserfs, xfs,基本涵盖常用文件系统. 最下面加入ntfs和zfs对比,实际上不参与选型. 以下进制换算为1024,大小依次为KB,MB,GB,TB,PB,EB,ZB. [北京] 系统维护编辑 - 友好互动公司.
- Michael - shell's home
贝壳原来一直认为文件系统可以随便选,结果最近吃了两次苦头. 一个是btrfs对虚拟机支持不良,另一个是特定情况下xfs性能比ext3高20倍. 痛定思痛,打算列一下文件系统选型的方法和依据,欢迎拍砖.
下面我列一下纳入参考的文件系统,当然,ntfs就不要出来搞基了,玩嵌入式/光盘live之类的朋友也不要来凑热闹了阿. btrfs(简介), ext3, ext4(简介), jfs(简介), reiserfs, xfs,基本涵盖常用文件系统. 最下面加入ntfs和zfs对比,实际上不参与选型. 以下进制换算为1024,大小依次为KB,MB,GB,TB,PB,EB,ZB. 文件系统
最大卷容量
1 EB (16TB)
- L - 博客园-首页原创精华区
在linux中,一切都是文件,文件为操作系统服务和设备提供了一个简单而统一的接口,这就意味者程序可以像使用文件那样使用各种设备. 大多数情况下对于文件的操作只用到open,write,lseek,read,close五个系统调用. 本文通过一个简单的例子来介绍这五个调用及关联内容.
int file_des = open( &my_file.txt&, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR | S_IXUSR | S_IXOTH );.
这是一个简单的读写文件的例子,先创建一个文本文件,写入一些内容,再把文本内容输出到标准输出,下面开始分析这个例子:.
- 博客园_iTech's Blog
Linux系统上的/proc目录是一种文件系统,即proc文件系统. 与其它常见的文件系统不同的是,/proc是一种伪文件系统(也即虚拟文件系统),存储的是当前内核运行状态的一系列特殊文件,用户可以通过这些文件查看有关系统硬件及当前正在运行进程的信息,甚至可以通过更改其中某些文件来改变内核的运行状态. 基于/proc文件系统如上所述的特殊性,其内的文件也常被称作虚拟文件,并具有一些独特的特点. 例如,其中有些文件虽然使用查看命令查看时会返回大量信息,但文件本身的大小却会显示为0字节. 此外,这些特殊文件中大多数文件的时间及日期属性通常为当前系统时间和日期,这跟它们随时会被刷新(存储于RAM中)有关.
EXT4文件系统大家可能都比较熟悉了,现在流行的ubuntu 11.04和Fedora15都是默认采用的EXT4,ext4是Linux的第四代扩展文件系统,是EXT3的后继版本. Btrfs 被称为是下一代 Linux 文件系统. 近年来 ext2/3 遇到越来越多的扩展性问题,在期待 ext4 的同时,人们发现了
btrfs,据说它采用了很多先进的文件系统设计,不仅解决了 ext2/3 的扩展性问题,还让人们看到了下一代文件系统所具有的许多其他特性.
坚持分享优质有趣的原创文章,并保留作者信息和版权声明,任何问题请联系:@。页面导航:
→ 正文内容 linux inotify
使用Inotify 监控目录与文件的方法详解
本篇文章是对使用Inotify 监控目录与文件的方法进行了详细的分析介绍,需要的朋友参考下
1. 监控路径并打印所有发生在该路径的事件. 代码如下: 代码如下:#include &stdio.h&#include &string.h&#include &stdlib.h&#include &sys/inotify.h&#include &unistd.h&#define EVENT_NUM 12char *event_str[EVENT_NUM] = {&"IN_ACCESS",&"IN_MODIFY",&"IN_ATTRIB",&"IN_CLOSE_WRITE",&"IN_CLOSE_NOWRITE",&"IN_OPEN",&"IN_MOVED_FROM",&"IN_MOVED_TO",&"IN_CREATE",&"IN_DELETE",&"IN_DELETE_SELF",&"IN_MOVE_SELF"};int main(int argc, char *argv[]){&&&&&char buf[BUFSIZ];&struct inotify_event *&&if(argc & 2)&{&&fprintf(stderr, "%s path\n", argv[0]);&&return -1;&}&fd = inotify_init();&if( fd & 0 )&{&&fprintf(stderr, "inotify_init failed\n");&&return -1;&}&wd = inotify_add_watch(fd, argv[1], IN_ALL_EVENTS);&if(wd & 0)&{&&fprintf(stderr, "inotify_add_watch %s failed\n", argv[1]);&&return -1;&}&buf[sizeof(buf) - 1] = 0;&while( (len = read(fd, buf, sizeof(buf) - 1)) & 0 )&{&&nread = 0;&&while( len & 0 )&&{&&&event = (struct inotify_event *)&buf[nread];&&&for(i=0; i&EVENT_NUM; i++)&&&{&&&&if((event-&mask && i) & 1)&&&&{&&&&&if(event-&len & 0)&&&&&&fprintf(stdout, "%s --- %s\n", event-&name, event_str[i]);&&&&&else&&&&&&fprintf(stdout, "%s --- %s\n", " ", event_str[i]);&&&&}&&&}&&&nread = nread + sizeof(struct inotify_event) + event-&&&&len = len - sizeof(struct inotify_event) - event-&&&}&}&return 0;}运行 inotify_watch 监控一个目录:
代码如下:$ ./inotify_watch test/...& --- IN_OPEN& --- IN_CLOSE_NOWRITE.tmp.swp --- IN_CREATE.tmp.swp --- IN_OPEN.tmp.swpx --- IN_CREATE.tmp.swpx --- IN_OPEN.tmp.swpx --- IN_CLOSE_WRITE.tmp.swpx --- IN_DELETE.tmp.swp --- IN_CLOSE_WRITE.tmp.swp --- IN_DELETE.tmp.swp --- IN_CREATE.tmp.swp --- IN_OPEN.tmp.swp --- IN_MODIFY& --- IN_OPEN& --- IN_CLOSE_NOWRITE.tmp.swp --- IN_MODIFY...从上面的结果可以看到在 test 目录中使用 vim 创建一个 tmp 文件, 产生很多的冗杂事件. 因此需要对监控的事件做出小范围的选择而不是 IN_ALL_EVENTS .2. IN_MOVE_SELF 和 IN_DELETE_SELF 事件由于个人水平, 曾经对这两个事件的含义并没有理解正确. 当监控 path 时( path可以是文件或目录),
代码如下:$ ./inotify_watch path执行 代码如下:$ rm -f path则发生 IN_DELETE_SELF 事件;执行 代码如下:mv path path2则发生 IN_MOVE_SELF 事件. 3. 监控目录和文件监控目录中内容改变应监控的事件:
代码如下:IN_CREATE | IN_DELETE | IN_DELETE_SELF | IN_MODIFY | IN_MOVE_SELF | IN_MOVED_FROM | IN_MOVDED_TO监控文件内容的改变应监控的事件: 代码如下:IN_DELETE_SELF | IN_MODIFY | IN_MOVE_SELF
上一篇:下一篇:
最 近 更 新
热 点 排 行
12345678910

我要回帖

更多关于 linux 修复文件系统 的文章

 

随机推荐