Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It depends on what you mean by "definitely started". If you mean that fork(2) has completed and the new process exists, then each process is started by the time nohup returns. A new process has been created.</p> <p>The problem you are running into is that there is no guarantee how long the nohup'ed process gets to run before the shell returns. When the process you start is "definitely started" depends on what the process does for initialization. If you do not have source of the applications or are not able to modify them for some other reason, you will be limited to looking at their output. Many daemons will output a log message at various stages of their initialization. You can modify your script to </p> <ol> <li>Look for a log file, and create an empty one if it does not exist</li> <li>Open the log file for reading (at the end to avoid false messages from previous invocations), watching for the log message that indicates the process has started,</li> <li>Start your process with nohup,</li> <li>Wait for your log file watcher</li> </ol> <p>In bash, it would look something like this might work (this code is completely untested):</p> <pre class="lang-bsh prettyprint-override"><code>log=&lt;path to log file&gt; msg=&lt;message service prints when it is ready&gt; svc=&lt;path to service&gt; # Create log file if it does not exist if [ ! -f "$log" ] ; then echo &gt; "$log" fi # watch for message to appear on a single line in the log file tail -0 -f "$log" | egrep "$msg" | head -1 &amp; ready_pid=$! # Start the service nohup "$svc" &lt; /dev/null &gt;&gt; "$log" 2&gt;&amp;1 &amp; # Wait for the message wait $ready_pid </code></pre> <p>You want to start watching the log file before forking the service, because otherwise, the message might go by in the log before the script starting the service can attach to the log file.</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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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