How can I stop the execution of a thread until a file is created ?
I would like to avoid doing it in a busy loop, and use something with a behavior similar to select(). Is something like this possible?
I only found ways to check if a file exists at a given time.
Asked
Active
Viewed 3,830 times
4

Nicolas Jean
- 775
- 6
- 19
-
2Punch "file alteration monitor" into your favorite search engine. – David Schwartz Sep 07 '16 at 09:38
-
3You can't do this in pure C. If you're on a Linux system, have a look at `inotify`. – EOF Sep 07 '16 at 09:40
-
... created by what/how? – 4pie0 Sep 07 '16 at 10:42
-
@DavidSchwartz seems that I wasn't punching the right keywords in my favorite search engine, the results with "file alteration monitor" is indeed much more interesting than what I found previously, thanks for your comment! – Nicolas Jean Sep 07 '16 at 11:57
-
Thank you @EOF I think this is what I was looking for – Nicolas Jean Sep 07 '16 at 11:58
-
@where_is_tftp : created by another thread or process, on a linux system – Nicolas Jean Sep 07 '16 at 11:59
1 Answers
3
You are probably looking for inotify(7)
. At the botton of the man page linked, there's example showing how to monitor for various events.

P.P
- 117,907
- 20
- 175
- 238
-
There are [APIs with similar features (but completely different names and functions) for Windows and OSX](http://stackoverflow.com/a/3517567/364696). – ShadowRanger Sep 07 '16 at 10:09
-
@usr: thank you, I think this is what I was looking for. More precisely, watching the directory that will contain the file for the IN_CREATE event and then checking if the file is there should work fine! – Nicolas Jean Sep 07 '16 at 12:01