<div dir="ltr">The directory is irrelevant.  fork() + exec() is not an atomic operation:<br><div><div><br>* Thread 1 writes its file completely (opens and closes an Fd 1, using O_CLOEXEC)<br>
* Thread 2 starts writing its file (Fd 2 open for writing, using O_CLOEXEC)<br>
* Thread 1 starts executing "myBinary" by calling <b>fork()</b>. Fd 2 is inherited by the child process<br>
* Thread 2 finishes writing (closes its Fd 2)<br>
* Thread 2 executes "myBinary", which fails with `Text file busy`<br>
because an Fd is still open to it in the child of Process 1<br>* Thread 1 executes "myBinary" (calling exec()). Fd 2 is automatically closed during exec(), but it's too late.<br><br></div><div>You need the file descriptor to not be inherited by a child process, which is != from O_CLOEXEC.<br></div><div><br></div><div>Alexander<br></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Aug 28, 2015 at 10:14 PM, Brandon Allbery <span dir="ltr"><<a href="mailto:allbery.b@gmail.com" target="_blank">allbery.b@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><span class=""><div class="gmail_quote">On Fri, Jul 24, 2015 at 6:29 PM, Alexander Kjeldaas <span dir="ltr"><<a href="mailto:alexander.kjeldaas@gmail.com" target="_blank">alexander.kjeldaas@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><div>I think CLOEXEC should be the default, but it doesn't seem to solve your problem. What if thread 2 executes "myBinary" before thread 1 called exec()?<span><font color="#888888"><br></font></span></div></div></div></div></div></blockquote></div><br></span>I think you missed that each thread is using its own temporary directory --- they're not all running at the same time in the same directory, which would be pretty much guaranteed to fail.<span class="HOEnZb"><font color="#888888"><br clear="all"><div><br></div>-- <br><div><div dir="ltr"><div>brandon s allbery kf8nh                               sine nomine associates</div><div><a href="mailto:allbery.b@gmail.com" target="_blank">allbery.b@gmail.com</a>                                  <a href="mailto:ballbery@sinenomine.net" target="_blank">ballbery@sinenomine.net</a></div><div>unix, openafs, kerberos, infrastructure, xmonad        <a href="http://sinenomine.net" target="_blank">http://sinenomine.net</a></div></div></div>
</font></span></div></div>
</blockquote></div><br></div>