Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the behavioral differences between a daemon and a normal process?

Tags:

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?

like image 922
Lazer Avatar asked Aug 31 '10 20:08

Lazer


People also ask

What is the difference between daemon and a process?

Daemon (Linux)A process which runs in the background and is not interactive. They have no controlling terminal on their own from the user's perspective from the desktop. They continue to exist and operate regardless of any user being logged into the server if the computer is on.

What is the difference between a daemon and a service?

The word daemon for denoting a background program is from the Unix culture; it is not universal. A service is a program which responds to requests from other programs over some inter-process communication mechanism (usually over a network).

What is the difference between job and daemon?

A job is a task that runs until it's finished, i.e. it has no more work to do. A daemon is a background process, such as a server, that runs until someone, typically an administrator, tells it to stop.


2 Answers

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.

like image 95
Tyler McHenry Avatar answered Nov 13 '22 05:11

Tyler McHenry


The key difference between a Process and a Daemon is that a Daemon's parent is init - the first process started during *Nix booting. And that is why a Daemon is not connected to a terminal. So when you close your terminal it will not be killed by OS. But still you can send signals to your Daemon.

like image 28
vwvolodya Avatar answered Nov 13 '22 06:11

vwvolodya