* daemonization
@ 2002-06-28 20:49 xlp
2002-06-28 21:03 ` daemonization Jan-Benedict Glaw
0 siblings, 1 reply; 3+ messages in thread
From: xlp @ 2002-06-28 20:49 UTC (permalink / raw)
To: linux-c-programming
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?.
bye
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: daemonization
2002-06-28 20:49 daemonization xlp
@ 2002-06-28 21:03 ` Jan-Benedict Glaw
2002-06-28 22:13 ` daemonization Glynn Clements
0 siblings, 1 reply; 3+ messages in thread
From: Jan-Benedict Glaw @ 2002-06-28 21:03 UTC (permalink / raw)
To: linux-c-programming
[-- 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 --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: daemonization
2002-06-28 21:03 ` daemonization Jan-Benedict Glaw
@ 2002-06-28 22:13 ` Glynn Clements
0 siblings, 0 replies; 3+ messages in thread
From: Glynn Clements @ 2002-06-28 22:13 UTC (permalink / raw)
To: xlp; +Cc: linux-c-programming
xlp wrote:
> 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?.
Daemonisation isn't covered in any particular manual page. However, it
gets its own chapter in Stevens[1].
[1] Advanced Programming in the UNIX(R) Environment
W Richard Stevens
Addison-Wesley
This book is highly recommended, but not cheap (I paid UKP42,
~= EUR60).
However, it doesn't cover sockets; there is another book on network
programming by the same author but, IIRC, it covers both sockets and
TLI, and you're unlikely to need to use TLI.
Jan-Benedict Glaw wrote:
> - chdir() to "/"
>
> Most important are these:
>
> - become session leader: setsid()
> - fork() and let parent exit(0)
The fork() comes first; everything else should be done in the child.
> - close() stdin, stdout and stderr and re-open() them with /dev/null
And try to close() all other descriptors.
--
Glynn Clements <glynn.clements@virgin.net>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2002-06-28 22:13 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-06-28 20:49 daemonization xlp
2002-06-28 21:03 ` daemonization Jan-Benedict Glaw
2002-06-28 22:13 ` daemonization Glynn Clements
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).