Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I hear a lot of talk about Daemons running on my Ubuntu computer - what are they?

share|improve this question

1 Answer 1

up vote 10 down vote accepted

In short, a Daemon is a background process.

Daemons can just be normal programs that run in the background, however most are created by starting a process, forking it and exiting the parent.

To fork a process means to create an exact copy of it. The parent of that process, if the real parent terminates right away, is now the init process at /sbin/init, which is the first thing started on every Unix-like operating system. Now, the process is termed a Daemon, it has no TTY associated with it.

Here's an example of a Daemon in Python:

import sys, os, time

pid = os.fork()

# there now exist two processes
if pid > 0: # If this is the parent,
    sys.exit(0) # quit.

# this is the background part:
time.sleep(5)
print "Hello, World!"

It's not yet one, strictly speaking. You'd also have to change the current working directory, redicted standard input and output to log-files and so on. You can read up on the gory details in this wikipedia article.

If you run the example, you'll notice, after two seconds it prints, even though the process you started on the command-line has terminated. The copy of this process is run 'by' init now.

share|improve this answer
7  
to expand on this, if you're coming to Linux from Windows, you can think of daemons as the *nix equivalent of Windows' "services". –  nathwill Feb 15 '11 at 22:32

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.