title: Monitoring file using inotify
body: <p>I am using inotify to monitor a local file, for example "/root/temp" using </p>
  
  <pre><code>inotify_add_watch(fd, "/root/temp", mask).
  </code></pre>
  
  <p>When this file is deleted, the program will be blocked by <code>read(fd, buf, bufSize)</code> function. Even if I create a new "/root/temp" file, the program is still block by read function. I am wondering if inotify can detect that the monitored file is created and the read function can get something from fd so that read will not be blocked forever.
  Here is my code:</p>
  
  <pre><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);
  </code></pre>
  
  <p>I monitored all events.</p>