Entry
How do I background something in bash over openssh and still be able to logout?
How can I make a script act like a daemon?
How can I completely detach a process so it is owned only by init?
Jul 15th, 2003 04:03
Simon Ryan, Xcrash, http://www.snailbook.com/faq/background-jobs.auto.html
The trick is to redirect ALL streams. The one that people typically
forget is the STDIN stream:
progname </dev>& /dev/null&
But! The process group still remains set to that of the original parent
If this causes problems such as where the original parent is killed as
the child shuts down then you need to do a setpgrp() if you are writing
the code, or you can also do it as follows:
setsid progname </dev>&/dev/null &
The problem of the parent being killed as the child shuts down is, of
course, exacerbated when that process is the 'cron' or 'at' daemon,
since usually those daemons can potentially be the parents of many other
processes which then are terminated.
If your process is particularly reliable the simplest solution is to
just use 'cron' or 'at' to start it, but nothing beats the simplicity of
command line redirection ;-)