I am using inotify to monitor a local file, for example "/ root / temp", using
inotify_add_watch(fd, "/root/temp", mask).
When this file is deleted, the program will be blocked by the read(fd, buf, bufSize) function read(fd, buf, bufSize) . Even if I create a new file "/ root / temp", the program is still blocked by the read function. I am wondering if inotify can detect that the monitoring file has been created and the read function can get something from fd so that the read will not be blocked forever. Here is my code:
uint32_t mask = IN_ALL_EVENTS; int fd = inotify_init(); int wd = inotify_add_watch(fd, "/root/temp", mask); char *buf = new char[1000]; int nbytes = read(fd, buf, 500);
I tracked all the events.
source share