#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/inotify.h>
#include <string.h>
#include <sys/select.h>
#define EVENT_SIZE ( sizeof (struct inotify_event) )
#define BUF_LEN ( 1024 * ( EVENT_SIZE + 16 ) )
#define MAXLEN 1024
char buffer[BUF_LEN];
fd_set set;
fd_set rset;
int check_set[MAXLEN];
int max_fd;
int arrlen = 0;
static void handle_read(int fd)
{
int length = read( fd, buffer, BUF_LEN );
if ( length < 0 ) {
perror( "read" );
}
int i = 0;
while ( i < length ) {
struct inotify_event *event = ( struct inotify_event * ) &buffer[ i ];
if ( event->len ) {
if ( event->mask & IN_CREATE ) {
if ( event->mask & IN_ISDIR ) {
printf( "The directory %s was created.\n", event->name );
}
else {
printf( "The file %s was create
inotify结合select监控目录下文件变动
最新推荐文章于 2025-03-04 17:00:46 发布