"Niels M�ller" wrote:
> 
> Thayne Harbaugh <[EMAIL PROTECTED]> writes:
> 
> > daemonization cannot be done be a shell script - it has to happen
> > in the executeable.  It is quite easy to do, however:
> 
> Ok, I guess I should drop that idea. Even if I'm not sure I see why it
> can't be done (at least on this machine, there's a setsid program that
> should be usable from a script).

Okay, you _might_ be able to do it with a script.  I don't know
everything ;-)  It's just a basic function that is very convenient
to roll into the program itself.

> 
> > cd /
> > fork/exec - parent exits
> > set sid
> > close all file descriptors (more of a concern on sysV)
> > fork/exec - parent exits
> > syslog all messages
> >
> > It's also a good idea to add some commandline args to tell it
> > to not fork/exec and become a daemon and also dump messages to
> > stdout/stderr instead of syslog.
> 
> Another case is if the deamon is started directly by init (listed in
> inittab). In this case it's a bad idea to fork and let the parent
> exit. Perhaps
> 
>  if ( (getppid() != 1) && fork() ) exit(0);
> 
> should do that trick.

Yep, there is the option of starting it from init - this can be rolled
into an option that tells it not to run as a daemon while it still
should syslog or have some other logging facility.  There's also some
stuff you can drop in if you intend for it to be run by inetd.

> 
> > If you have any questions concerning the above - let me know.
> 
> Thanks.
> 
> > Hmmm.  I guess I'm just as liable telling you how to do it as
> > writing the code - maybe I'll just write some code . . . I dunno
> > (stinking munition laws).
> >
> 
> Somebody else just offered to write the code. So we'll see what
> happens.

Cool.  Another "feature" would be to have it write its pid to a file.

Thanks.

> 
> /Niels

Reply via email to