views:

42

answers:

2

I know that daemons run in the background mostly i.e. they require very less interaction from the user.

Wikipedia lists some of the types of daemons that commonly exist:

  • Dissociating from the controlling tty
  • Becoming a session leader
  • Becoming a process group leader
  • Staying in the background by forking and exiting (once or twice). This is required sometimes for the process to become a session leader. It also allows the parent process to continue its normal execution. This idiom is sometimes summarized with the phrase "fork off and die"
  • Setting the root directory ("/") as the current working directory so that the process will not keep any directory in use that may be on a mounted file system (allowing it to be unmounted).
  • Changing the umask to 0 to allow open(), creat(), et al. calls to provide their own permission masks and not to depend on the umask of the caller
  • Closing all inherited open files at the time of execution that are left open by the parent process, including file descriptors 0, 1 and 2 (stdin, stdout, stderr). Required files will be opened later.
  • Using a logfile, the console, or /dev/null as stdin, stdout, and stderr

I want to know if there can be any differences in behavior in a daemon as differentiated from a normal process, apart from the one I mentioned in the first line. Both kinds of processes do their work, and interact with the user depending on the amount of interaction they need to do their job.

Is there more to daemons than this?

+2  A: 

Not really. A daemon is just a term for a process that runs continuously and usually is not attached to a terminal.

Daemons are not a separate class of processes and they have no special privileges or attributes.

There is a BSD/Linux C function called daemon (man page), but this is just really a simple way to detach your process from its terminal. It is so named because that's what daemons usually do, not the other way around.

Tyler McHenry
Lazer
I would say no -- that's just a background process. It's still associated with your terminal, even if it's output is being temporarily suppressed, and if the program runs indefinitely, it was most likely was written with interactivity in mind. A daemon automatically detaches from the terminal in which it is started and is written with the expectation of non-interactivity.
Tyler McHenry
A: 

The question is a little vague, but I'll try anyways:

Technically, daemons are just processes like any other. They usually, but are not required to, have misc file descriptors closed and other behavior suited for processes that live a long time. For a high level look at how most daemon processes are set up (in Python), check out: http://www.noah.org/wiki/Daemonize_Python

So the differences really come down to lifecycle and users. Daemon processes live for long periods of time, usually as long as a given runlevel. They also usually provide services to other system-wide processes, or processes higher up than the average user run process..

I wouldn't say that they are usually system-wide, they could just as well be local for a given user session.
Christo