Do we need a second thread to process time-consuming jobs with inotify? <p>Referenc: <a href="http://stackoverflow.com/questions/9067175/how-to-monitor-a-folder-with-all-subfolders-and-files-inside">How to monitor a folder with all subfolders and files inside?</a></p> <p>I need to monitor a directory for any file with extension of *.log. If a new file is created or is moved in, I will process the file. it takes variable time to process each file.</p> <p>Question> Do I need to create one thread to listen the inotify event and push the new file name into queue and use another thread to process the queue? My concern is that if I don't use separate threads, then the inotify may fail to track changes caused by some large files.</p> <p>I have simulated the problem with <code>sleep</code> while processing each log file without any multi-thread code. It seems to me that inotify always corrects get all created/moved files in the directory.</p> <p>Here is my simulation.</p> <p><strong>Terminate 1</strong>: I run the app and listen the inotify event within the main. Whenever processing one log file, I will sleep for 10 second then print the file name to console.</p> <p><strong>Terminte 2</strong>: I will copy multiple files at time T1 to the monitored directory. Before the app finishing processing all previous files, I will move multiple files at time T2. Then again time T3, I will copy multiple files to the directory before the app finishes.</p> <p>Observation: The app processed all log files as I expected.</p> <p>Question> Is this expected behavior of inotify or I just run lucky this morning? In other words, will inotify cache unprocessed events in case of simulation as above?</p> <p>FYI: the code snippet I used:</p> <pre><code>#define EVENT_SIZE ( sizeof (struct inotify_event) ) #define BUFFER_LEN ( 1024 * ( EVENT_SIZE + NAME_MAX + 1) ) wd = inotify_add_watch( fd, root.string().c_str(), IN_CREATE | IN_MOVED_TO ); while ( true ) { length = read( fd, buffer, BUFFER_LEN ); for ( int i = 0; i &lt; length; ) { const inotify_event *ptrEvent = reinterpret_cast&lt;inotify_event *&gt;(&amp;buffer[i]); ... // processing the event sleep(10); // to simulate the long work i += INO_EVENT_SIZE + ptrEvent-&gt;len; } } </code></pre>