Note that there are some explanatory texts on larger screens.

plurals
  1. POSpawn process from multithreaded application
    primarykey
    data
    text
    <p>I have a situation where I need to spawn a helper process from within a very large, multithreaded application, which I do not have complete control over.</p> <p>Right now I'm using <code>fork()</code>/<code>exec()</code>. This works a lot of the time, but in some circumstances the child crashes weirdly before the <code>exec()</code> happens. I'm suspecting this is because <code>fork()</code>ing multithreaded applications is generally considered to be a Really Bad Idea.</p> <p>I would really, really like a way to start a process atomically, without <code>fork()</code>ing the parent: with all file descriptors closed, environment set up the way I want, CWD set, etc. This should avoid all the horror of <code>fork()</code>ing my multithreaded parent app, and dealing with file descriptor inheritance, etc. <code>posix_spawn()</code> should be ideal. Unfortunately, on Linux, <code>posix_spawn()</code> is implemented using <code>fork()</code> and <code>exec()</code>...</p> <p><code>vfork()</code> is defined to suspend the parent process until the child calls <code>exec()</code>. This would appear to be more like what I want, but my understanding was that <code>vfork()</code> is generally considered a historical relic these days and is equivalent to <code>fork()</code> --- is this still the case?</p> <p>What's the least bad way of dealing with this?</p> <p>Note that: </p> <ul> <li>I cannot spawn my process before any threads start (because I can't run code at that point)</li> <li>I cannot redesign my application not to need the helper process, due to external requirements</li> <li>I cannot suspend all my threads before spawning the helper process, because they don't belong to me</li> </ul> <p>This is on Linux. Java is involved, but all <em>my</em> code is in C.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload