[Gllug] Starting a daemon

Richard W.M. Jones rich at annexia.org
Thu Dec 30 14:43:31 UTC 2010


On Thu, Dec 30, 2010 at 02:16:50PM +0000, John G Walker wrote:
> 
> 
> On Thu, 30 Dec 2010 14:09:47 +0000 Andy Millar <andy at andymillar.co.uk>
> wrote:
> 
> > On Thu, 2010-12-30 at 14:01 +0000, Lucian wrote:
> > > On Thu, Dec 30, 2010 at 12:40 PM, t.clarke <tim at seacon.co.uk> wrote:
> > > `setsid program` might work as well.  
> > 
> > #!/bin/bash
> > cd /
> > /path/to/program </dev/null >/dev/null 2>/dev/null &
> > disown
> 
> Thanks for the quote from the disown manual. I still can't work out,
> however, the difference between what you've suggested here and thye use
> of setsid. Nor do i understand what disown would achieve (which is
> perhaps the word I should have used) if I've used nohup.

Different things.

The use of 'disown' in Lucian's script is so that bash doesn't send a
SIGHUP to the program when the bash script exits (which is does just
after the 'disown' command).  See bash(1) for the details.

setsid is different: It creates a new session and new "process group",
which is a kernel concept for grouping processes together: amongst
other things, it allows you to conveniently send a signal to all
processes in a group at once, and only one _session_ can be in the
"foreground" on a tty (so it maps the concept of 'fg' and 'bg'
commands).  Having said that I've never understood if there is a
difference between "session" and "process group" and the man page
doesn't explain it very well either.

Rich.

-- 
Richard Jones
Red Hat
-- 
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug




More information about the GLLUG mailing list