은 :
IN_CREATE File/directory created in watched directory (*).
는이 이벤트를 잡기하여 수행 할 수 있습니다. 맨 페이지에서 다시
:
Limitations and caveats
Inotify monitoring of directories is not recursive: to monitor subdirectories under a directory, additional watches must be created. This can take a significant
amount time for large directory trees.
그래서, 당신은 재귀 부분을 직접 수행해야합니다. here에서 예를 찾아 볼 수 있습니다. 의견에 질문으로 당신은 또한 프로젝트 notify-tools
예를 살펴이 있어야합니다
[email protected] ~ $ ./a.out
In /tmp/inotify1:
The file abhijeet was created.
In /tmp/inotify2:
The file rastogi was created.
^C
[email protected] ~ $
: 그것은 새로운 파일에 대한 /tmp/inotify1
& /tmp/inotify2
이 & 표시에게 이벤트 #include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/inotify.h>
#define EVENT_SIZE (sizeof (struct inotify_event))
#define BUF_LEN (1024 * (EVENT_SIZE + 16))
int main(int argc, char **argv)
{
int length, i = 0;
int fd;
int wd[2];
char buffer[BUF_LEN];
fd = inotify_init();
if (fd < 0) {
perror("inotify_init");
}
wd[0] = inotify_add_watch(fd, "/tmp/inotify1", IN_CREATE);
wd[1] = inotify_add_watch (fd, "/tmp/inotify2", IN_CREATE);
while (1){
struct inotify_event *event;
length = read(fd, buffer, BUF_LEN);
if (length < 0) {
perror("read");
}
event = (struct inotify_event *) &buffer[ i ];
if (event->len) {
if (event->wd == wd[0]) printf("%s\n", "In /tmp/inotify1: ");
else printf("%s\n", "In /tmp/inotify2: ");
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 created.\n", event->name);
}
}
}
}
(void) inotify_rm_watch(fd, wd[0]);
(void) inotify_rm_watch(fd, wd[1]);
(void) close(fd);
exit(0);
}
테스트 실행을 생성 모니터링
운영 체제는 무엇입니까? –
@VJovic inotify는 리눅스와 관련이 있습니다. –
@AbhijeetRastogi 그럼,이 질문은 리눅스 용입니까? –