一、在安卓的输入子系统中如何监听文件的产生以及监听文件是否有数据的输入,文件的监听主要使用的是inotify机制来监听文件的创建以及删除。使用epoll可以用来监听文件是否有数据的变化。下面针对这两种机制分别编程,简单的了解以及如何使用. 二、使用inotify监听文件的创建以及删除. 2.1我们先来看看现象之后在来看看具体的代...
编译命令:gcc -o inotify inotify.c,之后按照2.1截图的步骤运行即可。 三、使用epoll来监听文件是否有数据的写入. 3.1代码的具体实现如下: 1#include <sys/epoll.h>2#include <stdio.h>3#include <unistd.h>4#include <sys/types.h>5#include <sys/stat.h>6#include <fcntl.h>7#include <string.h>8910...
//demo 代码#include<sys/inotify.h>#include<unistd.h>#include<string.h>#include<stdio.h>intwatch_inotify_events(intfd){charevent_buf[512];intret;intevent_pos=0;intevent_size=0;structinotify_event*event;/*读事件是否发生,没有发生则会阻塞*/ret=read(fd,event_buf,sizeof(event_buf));/*若...