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).

> 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.

> 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.

/Niels

Reply via email to