[Dev] HOWTO write a daemon
Paul D. Boyle
dev@trilug.org
Thu, 23 May 2002 21:56:38 -0400 (EDT)
>
> Just curious but what is wrong with just writing a program that doesn't
> put out any text to the console and starting it with a script with a
> command like this:
>
> mydaemon&
>
> Besides the fact that it's a little less elegant?
What distinguishes a daemon from a "regular" process (either foreground
or background) is that the process becomes (according to Stevens) a
session leader of a new session, it becomes a process group leader of
a new process group, and it has no controlling terminal. In addition,
very often daemon change their current working directory to a specific
directory (often, but not always, "/"), so that filesystems can be
unmounted while the daemon is running (did you ever try to unmount a
file system and got a 'device busy' message?).
Under Unix (Linux) all processes automatically open three I/O streams,
stdin, stdout, stderr, these are often closed in a daemon process.
Paul
--
Paul D. Boyle | boyle@laue.chem.ncsu.edu
Director, X-ray Structural Facility | phone: (919) 515-7362
Department of Chemistry - Box 8204 | FAX: (919) 515-5079
North Carolina State University |
Raleigh, NC, 27695-8204
http://laue.chem.ncsu.edu/web/xray.welcome.html