From: Jan-Benedict Glaw <jbglaw@lug-owl.de>
To: linux-c-programming@vger.kernel.org
Subject: Re: daemonization
Date: Fri, 28 Jun 2002 23:03:48 +0200 [thread overview]
Message-ID: <20020628210348.GT17216@lug-owl.de> (raw)
In-Reply-To: <20020628154913.A377@nietzsche>
[-- Attachment #1: Type: text/plain, Size: 929 bytes --]
On Fri, 2002-06-28 15:49:13 -0500, xlp <xlp@emtel.net.co>
wrote in message <20020628154913.A377@nietzsche>:
> Hi, I want to understand How can a executale object in Unix can become a "daemon" ? How can it deal with stdout, and ttys it's connected to? What are the C library function I should read man?.
- chdir() to "/"
Most important are these:
- become session leader: setsid()
- fork() and let parent exit(0)
- close() stdin, stdout and stderr and re-open() them with /dev/null
- maybe do a chroot()
- maybe open any IP ports to listen on them
- Drop root privileges: setuid(), setgid()
- Ready (TM)
- Afterwards: At any file you open, don't forget O_NOCTTY!
MfG, JBG
PS: And ___always___ check the return values of those library calls!!!
--
Jan-Benedict Glaw . jbglaw@lug-owl.de . +49-172-7608481
-- New APT-Proxy written in shell script --
http://lug-owl.de/~jbglaw/software/ap2/
[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]
next prev parent reply other threads:[~2002-06-28 21:03 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-06-28 20:49 daemonization xlp
2002-06-28 21:03 ` Jan-Benedict Glaw [this message]
2002-06-28 22:13 ` daemonization Glynn Clements
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20020628210348.GT17216@lug-owl.de \
--to=jbglaw@lug-owl.de \
--cc=linux-c-programming@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).