Your Linux PC Has Daemons. Here’s Everything You Need to Know About Them

Summary

  • Daemons are essential Linux programs performing tasks. systemd’s ;systemctl provides procedures to manage, start, or stop them efficiently.
  • Daemons were inspired by Maxwell’s Demon concept in physics. systemd manages modern Linux system tasks. Knowing daemons’ functions is crucial.
  • Use commands like systemctl to view running daemons, enable/disable daemons, and start/stop services on a Linux system. Understanding daemons can make system management effortless.

You may have heard the term “daemon” concerning Linux. What are they? Are they something to be scared of? These little helper programs are an important part of Linux and will help take care of your systems and run essential services.

What Are Daemons?

In Linux, daemons are programs that run independently to perform various tasks on the system. These are things like running cron to execute tasks at specific times, listening for incoming network connections, and cleaning up the filesystem, among others. They typically have names ending in “-d.”

The concept arose in the 1960s with the MULTICS project, an ambitious attempt to create what would now be called “cloud computing.” MIT computer scientist Fernando Carbató is credited with coining the term in a computing context, taking inspiration from the physicist James Clark Maxwell’s thought experiment about an imaginary demon sorting molecules, known as “Maxwell’s demon.”

Corbató later wrote about the inspiration for the term:

Maxwell’s daemon was an imaginary agent which helped sort molecules of different speeds and worked tirelessly in the background. We fancifully began to use the word daemon to describe background processes which worked tirelessly to perform system chores.

On other multitasking operating systems, these kinds of programs are often referred to as “services.” That might be the best way to think of them.

A good example is crond (pronounced “cron-d”), which runs the tasks specific in the crontab files. On modern major Linux distros, tasks that would have been handled by a separate daemon are coming increasingly under the systemd umbrella. If you look at the running daemons, that would include things like systemd-networkd, systemd-journald, and systemd-timesyncd.

Related

Why Linux’s systemd Is Still Divisive After All These Years

A decade after it was first introduced, systemd is still the target of some savage opposition–but why? Is the outrage justified?

Modern Linux systems will have lots of daemons running in the background, especially on servers. Even on desktop systems, there may be tens, even hundreds, in the background. That’s one reason that you should gracefully shut down your system instead of just pressing the power button when you can.

Viewing Running Daemons

You can see which daemons are running on your system with a few simple commands.

The easiest way on most modern distros is to use the systemctl command supplied by systemd. You can view all the services on your system by just using systemctl by itself. A “unit” is a small text file that tells systemd how to load a program, and other units that a unit might require, known as “dependencies,” carrying over from package management.

        
systemctl list-units
Output of Linux systemctl --list units in the terminal.

You can also view the systemd units that are actually daemons by listing the services, which is the term that systemd has adopted:

        systemctl list-units --type=service
    
Output of systemctl-list-units --type=service in the Linux terminal

This will list all the service units installed on your system. To see which ones are actually running, you can use this command:

        systemctl list-units --type-service state=active
    
Listing running services in Linux using systemctl.

This will give you a list of running services. On this Debian virtual machine, we have a number of active services, including Avahi, which allows the system to connect automatically to other devices like printers on the local network, NetworkManager, which handles the network connection. I like how it’s neatly laid out in a table. The “description” section tells you what these services actually do.

The Windows Task Manager just leaves you to search what these mysterious-sounding services do on your own, but they at least have a quick link to search for it.

The other classic way to view running daemons is to use the ps command. We can use the “aux” options to view all the processes on the system, no matter who they belong to, since most processes belong to the superuser, and you most likely aren’t the superuser. If you are, you should probably change that quickly by setting up your own user account.

To see all the processes on the system with ps:

ps aux
List of running processes from "ps aux" on Linux.

You won’t have as much information about which ones are daemons, but a good clue is that if the name ends in “-d” as I mentioned earlier. The “TTY” field will also typically have a “?” (question mark), which indicates that they were started without a controlling terminal.

Running processes in htop in the Linux terminal.

You can also view all running processes, including daemons, with top or htop, which offers more colorful output.

Enabling and Disabling Daemons

You can enable and disable daemons at will. Linux is traditionally a system for experts, and puts few barriers in your way to managing your system the way you want to manage it.

The most common way to add a new daemon to your system is to install it from your package manager. For example, if you wanted to install the NGINX web server on a Debian or Ubuntu system, assuming you have administrative privileges:

        
sudo apt install nginx

What happens afterward depends on what distro you’re running. Some distros, like Debian and Ubuntu, will enable a service on boot. Others, like Arch, will typically leave that job to you. It’s easy to do with systemctl. Y

To enable a daemon:

        sudo systemctl enable daemon.service
    

For example, to enable NGINX:

        sudo systemctl enable nginx.service
    
Enabling NGINX with systemctl.

Disabling daemons using systemctl is similar

sudo systemctl disable nginx.service
Disabling NGINX with systemctl.

Make sure you know what a daemon does before you disable it, especially ones that were installed with your system. If in doubt, leave it alone.

Starting and Stopping Daemons

You don’t have to wait for reboots to make changes to running daemons. You can start and stop daemons at will as long as you have administrative permissions. On most Linux systems, this would mean you either have access through the root password or sudo. We’ll use the latter.

You might want to start a daemon when you’ve installed one. Depending on the distro, it might be started automatically when you install a daemon from your distro’s package manager. Debian and Ubuntu are good examples. On other distros, you might be responsible for starting it yourself. Arch Linux is a good example of the latter.

Or you might want to start a daemon back up after you stopped it earlier.

Suppose you wanted to start the NGINX web server. To do that using systemctl:

        systemctl start nginx.service
    

You can also stop services that are running. Again, you can use systemctl to stop the process

        sudo systemctl stop nginx.service
    

Starting and stopping processes this way will only affect the current boot. To make more permanent changes, you’ll have to enable or disable services using the methods mentioned in the “enabling and disabling daemons” section.

Often, you’ll want to restart a daemon. You might have updated the version of the running daemon, or made a change to its configuration command. One way to do this would be to stop and then start the daemon again:

        sudo systemctl stop daemon.service
sudo systemctl start daemon.service

You can do this in one command line and save a bit of wear and tear on your fingers with the systemctl restart command. Suppose you made changes to your NGINX server and want to test them. You can use this command:

        sudo systemctl restart nginx.service
    

Related

Why I’m Sticking With systemd-based Linux Distros

How I learned to stop worrying and love systemd.

That’s how easy it is on a modern Linux system. Even with complaints about systemd’s supposed bloat, it made starting and stopping processes easier without having to dig through symbolic links the way I had to with the old SysVInit system. I suppose a lot of other developers and sysadmins feel the same way, given how quickly systemd was accepted in the Linux ecosystem


Daemons might seem scary if you’re not used to them, but a few commands is all it takes to tame them on your Linux system. You might not notice them, but they’re always around on your Linux system, making life easier for you.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top