Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>As NSD asked, it really depends on how it is spawned. If you are using a shell script, for example, you can use the <code>nohup</code> command to run the child through.</p> <p>If you are using <code>fork/exec</code>, then it is a little more complicated, but no too much so. </p> <p>From <a href="http://code.activestate.com/recipes/66012/" rel="noreferrer">http://code.activestate.com/recipes/66012/</a></p> <pre><code>import sys, os def main(): """ A demo daemon main routine, write a datestamp to /tmp/daemon-log every 10 seconds. """ import time f = open("/tmp/daemon-log", "w") while 1: f.write('%s\n' % time.ctime(time.time())) f.flush() time.sleep(10) if __name__ == "__main__": # do the UNIX double-fork magic, see Stevens' "Advanced # Programming in the UNIX Environment" for details (ISBN 0201563177) try: pid = os.fork() if pid &gt; 0: # exit first parent sys.exit(0) except OSError, e: print &gt;&gt;sys.stderr, "fork #1 failed: %d (%s)" % (e.errno, e.strerror) sys.exit(1) # decouple from parent environment os.chdir("/") os.setsid() os.umask(0) # do second fork try: pid = os.fork() if pid &gt; 0: # exit from second parent, print eventual PID before print "Daemon PID %d" % pid sys.exit(0) except OSError, e: print &gt;&gt;sys.stderr, "fork #2 failed: %d (%s)" % (e.errno, e.strerror) sys.exit(1) # start the daemon main loop main() </code></pre> <p>This is one of the best books ever written. It covers these topics in great and extensive detail.</p> <p><strong>Advanced Programming in the UNIX Environment, Second Edition (Addison-Wesley Professional Computing Series) (Paperback)</strong></p> <p>ISBN-10: 0321525949<br /> ISBN-13: 978-0321525949</p> <p>5 star amazon reviews (I'd give it 6).</p>
 

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