Note that there are some explanatory texts on larger screens.

plurals
  1. POLinux: Program A runs Program B that kills A, replaces A, and restarts A -- problems with inherited open file descriptors
    primarykey
    data
    text
    <p>I have a server process, and this server process can be given a command to update itself. What it does is store the update and then use system() to run an update script in the background. The update script kills the parent process, deletes the binary, replaces it, and then restarts it.</p> <p>The restarted process has failed for various reasons as I have tried to debug it, but this time, it's because a TCP port I'm trying to allocate is already in use. I'm guessing that the child process inherits the open port, which is then inherited by the updated server process, and as a result, the port isn't free for the process to allocate it again.</p> <p>The way the update script is launched is this:</p> <pre><code>system("/usr/local/bin/update_script.sh &gt; /dev/null 2&gt;&amp;1 &amp;"); </code></pre> <p>Then the script does this:</p> <pre><code>killall server_process rm /usr/local/bin/server_process cp /tmp/update/server_process /usr/local/bin server_process &gt; /dev/null 2&gt;&amp;1 &amp; </code></pre> <p>Any suggestions on how I might make this work? Is there some way I can detach the update script so that the server process is no longer its parent before it performs the update? Or make the child process not inherit any of the parent's resources?</p> <p>Thanks.</p> <p>Addendum: A solution would be to set <code>FD_CLOEXEC</code> on every open file descriptor. Unfortunately, some of those fd's are buried in libraries, which I'd have to seriously hack up in order to make them set <code>FD_CLOEXEC</code>. Somehow, I need to make <code>FD_CLOEXEC</code> the default. Or I need to do something drastic, like iterate over all open fd's (how?) and set <code>FD_CLOEXEC</code>. </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.
    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