Subject: Re: [Dev] Re: [Dev] HOWTO write a daemon

From: "John F Davis" <[email-masked]>
Date: Fri, 24 May 2002 09:29:41 -0400

Hello

Well, I haven't really written a demon per se.

 I did write some code which was called during initiailization and forked
off a child.  The child ran an existing non-interactive app which in turn
would use syslog to record messages.  My code was only four lines long.  Oh
yeah, I also piped the output to /dev/null.  (Not all of its output was
sent to the logfiles.)

You are correct about the backgrounding of a app.  It will indeed die when
you log off.  For what its worth, you can use cron or one its ilk to
schedule the job.

It sounds to me that you are most of the way to your goal.  ie.

o  Your code uses syslog.
o  It doesn't use stdin/stdout/stderr

All you need is the code to run unintended.  You just need to tie it in
with the rc.d scripts.  The scripts will handle the start, stop and status
bit for you.  You can even hook in with inittab if you want to make sure it
stays running.  It is inittab which restarts daemons automatically when
there are killed, right?

JD

"Peter Long" <[email-masked]>@trilug.org on 05/24/2002 09:24:13 AM

Please respond to [email-masked]

Sent by:    [email-masked]

To:    [email-masked]
cc:
Subject:    [Dev] Re: [Dev] HOWTO write a daemon

> Hello Mike,
>
> That was a good read.   I like the bit about 'and this unknown led to
> this unknown etc'.  You tracked down each unknown in turn and learned a
> lot.  I can identify with that.
>
> If the original poster wants to talk about what they plan to do in more
> detail, I'm sure we can all help.

Well thanks for the offer to help. I planned to turn my application in to a
daemon all along so I wrote it to have no interface. It does not rely on
the existence of stdin/stdout/stderr and I log everything using calls to
syslog(). So what I needed to know what how to detach the io streams and
whatever else was necessary for a process to be considered a daemon.

BTW: I was under the impression that just typing 'mydaemon&' would not
work.
I thought that the process would be terminated when I logged off in any
case. Is there some way around that or am I just completely mistaken?

Thanks again for all the help.

--
Peter Long

_______________________________________________
Dev mailing list
[email-masked]
http://www.trilug.org/mailman/listinfo/dev