Baeldung Pro – Linux – NPI EA (cat = Baeldung on Linux)
announcement - icon

Learn through the super-clean Baeldung Pro experience:

>> Membership and Baeldung Pro.

No ads, dark-mode and 6 months free of IntelliJ Idea Ultimate to start with.

Partner – Orkes – NPI EA (tag=Kubernetes)
announcement - icon

Modern software architecture is often broken. Slow delivery leads to missed opportunities, innovation is stalled due to architectural complexities, and engineering resources are exceedingly expensive.

Orkes is the leading workflow orchestration platform built to enable teams to transform the way they develop, connect, and deploy applications, microservices, AI agents, and more.

With Orkes Conductor managed through Orkes Cloud, developers can focus on building mission critical applications without worrying about infrastructure maintenance to meet goals and, simply put, taking new products live faster and reducing total cost of ownership.

Try a 14-Day Free Trial of Orkes Conductor today.

1. Overview

A daemon is a program that runs in the background and performs system-related tasks in Linux. These tasks include handling network connections, handling system logs, or managing hardware. Monitoring and managing daemons helps ensure critical services are running and can help in troubleshooting system issues.

In this tutorial, we’ll discuss how to list all running daemons across different init systems. We’ll focus on the systemd, SysVinit, and OpenRc init systems.

2. Identifying Our System’s Init System

Before we list the running daemons, let’s first determine which init system is running on our Linux distribution:

$ ps -p 1 -o comm=
systemd

The above output indicates our system uses systemd as the init system.

To clarify, an init system is responsible for booting the system and managing services or daemons. It ensures that daemons are started, stopped, or restarted based on system needs.

3. Listing Running Daemons on systemd-Based Systems

systemd is the default init system and service manager in most popular Linux distributions such as Ubuntu, Fedora, and Debian. It groups processes into units, which are specified by configuration files with various extensions like .service for services.

3.1. Using systemctl

systemctl is a command-line utility used to manage and interact with the systemd init system.

To begin, let’s list all active daemons on our system:

$ systemctl list-units --type=service --state=running
  UNIT                          LOAD   ACTIVE SUB     DESCRIPTION
  accounts-daemon.service       loaded active running Accounts Service
  bluetooth.service             loaded active running Bluetooth service
  cups.service                  loaded active running CUPS Scheduler
...

Let’s understand the above output:

  • UNIT – represents the name of the service or daemon
  • LOAD – indicates whether the service units file is loaded into memory
  • ACTIVE – displays the current status of the service, which can be active, inactive, or failed
  • SUB – provides additional information about the state of the service; for instance, running indicates the service is actively running
  • DESCRIPTION – displays a short explanation of what the service is doing

In this example, we list all currently active and running services. The list-units subcommand lists all systemd units. Next, we use the –type=service option to filter the output to only show services. Lastly, the –state=running option filters the output to only show services that are actively running.

Furthermore, we can focus on a specific service by filtering the output. For example, let’s display all services related to bluetooth:

$ systemctl list-units --type=service --state=running | grep bluetooth
  bluetooth.service             loaded active running Bluetooth service

Here, we use the grep command to filter the list of running services and display only those related to Bluetooth.

Additionally, we can list all services regardless of whether they’re running, exited, or failed:

$ systemctl list-units --type=service
  UNIT                          LOAD   ACTIVE SUB     DESCRIPTION
  accounts-daemon.service       loaded active running Accounts Service
  alsa-restore.service          loaded active exited  Save/Restore Sound Card State
  apport.service                loaded active exited  LSB: automatic crash report generation
  bluetooth.service             loaded active running Bluetooth service
...

This command lists services in various states.

We can also get more details about a specific daemon:

$ systemctl status dbus
● dbus.service - D-Bus System Message Bus
     Loaded: loaded (/lib/systemd/system/dbus.service; static)
     Active: active (running) since Thu 2025-01-16 10:30:01 EAT; 40min ago
TriggeredBy: ● dbus.socket
       Docs: man:dbus-daemon(1)
   Main PID: 839 (dbus-daemon)
      Tasks: 1 (limit: 4491)
...

Above, we display some information about the dbus service, such as its current state, memory, and CPU usage, as well as log entries related to the service.

4. Listing Running Daemons on SysVinit-Based Systems

SysVinit is an init system used in older Linux distributions such as CentOS 6 or Debian 7. It manages services using scripts located in the /etc/init.d/ directory. These scripts are used to start, stop, restart, or check the status of a service.

4.1. Using the service Command

The service command enables us to interact with and manage services in SysVinit systems.

To list all daemons and their statuses, we use the service –status-all command:

$ service --status-all
 [ + ]  acpid
 [ ? ]  alsa-utils
 [ - ]  anacron
 [ + ]  avahi-daemon
 [ + ]  bluetooth
 ...

In the above command, –status-all lists the status of all services, both running and stopped. From the output, [ + ] indicates the service is running, [ – ] indicates the service has stopped, and [ ? ] indicates the service has an unknown status.

In addition to listing all services, we can also check the status of a specific service or daemon using the status action and the service name:

$ service acpid status
acpid is running.

The output indicates that the acpid service is running. We can use this approach to monitor specific services.

4.2. Examining the /etc/init.d/ Directory

The /etc/init.d/ directory contains scripts that manage system services or daemons. Each file in this directory is a script that represents a specific service or daemon. These scripts interact with and control background processes on a SysVinit-based system.

To display all service scripts available on our system, let’s list the files in the /etc/init.d/ directory:

$ ls /etc/init.d/
acpid       apparmor      cron          grub-common  kmod      procps                       spice-vdagent    whoopsie
alsa-utils  apport        cups          hwclock.sh   lightdm   pulseaudio-enable-autospawn  udev             x11-common
anacron     avahi-daemon  cups-browsed  irqbalance   openvpn   rsync                        ufw
...

Here, we list all service scripts in the /etc/init.d/ directory, including those for services that may not be currently running.

To determine which service is running or not, we can check the status of each service using its script. For instance, let’s check the status of the cron service:

$ /etc/init.d/cron status
cron is running.

The above output indicates the cron service is currently active and running.

On the other hand, we can loop through the scripts in the /etc/init.d/ directory and check their status to identify all running services:

$ for service in /etc/init.d/*; do
    $service status 2>/dev/null | grep -q 'running' && echo "$service is running";
done
/etc/init.d/acpid is running
/etc/init.d/acpid-fakekey is running
/etc/init.d/avahi-daemon is running
/etc/init.d/bluetooth is running
...

Let’s explain the above command:

  • for service in /etc/init.d/*; do – loops through all the files in the /etc/init.d/ directory
  • $service status 2>/dev/null – executes the status command on each service script, while 2>/dev/null ensures that any error messages are not shown
  • | grep -q ‘running’ – pipes the output of the status command to grep, which searches for the word running
  • && echo “$service is running” – prints a message indicating the service is running if the grep command finds the word running in the status output

Using this approach, we can determine which services are currently running.

5. Listing Running Daemons on OpenRc-Based Systems

OpenRc is a dependency-based init system that provides service management for Unix-like systems. It’s mainly used on Linux distributions like Alpine, Gentoo, and Artix. In addition, it organizes services into runlevels, which are different states or modes the system can run in.

5.1. Using the rc-status Command

rc-status is a command-line utility that displays the status of system services in OpenRc:

$ rc-status
Runlevel: default
  dbus           [ started ]
  syslog-ng      [ started ]
  acpid          [ started ]
  gpm            [ started ]
  ...
Dynamic Runlevel: hotplugged
Dynamic Runlevel: needed/wanted
  hdparm      [started]
  alsasound   [started]
  ...

In this example, we display the status of services on various runlevels. From the output, default, hotplugged, and needed/wanted represent the runlevels, while [ started ] indicates the service is currently active and running.

Furthermore, we can list the status of all services across all runlevels using the -a option:

$ rc-status -a
Runlevel: boot
   modules    [ started ]
   hwclock    [ started ]
   ...
Runlevel: default
  dbus        [ started ]
  syslog-ng   [ started ]
  ...
Runlevel: nonetwork
   local      [ started ]
...

The above command displays all services and their status across all runlevels.

In addition, we can check the status of a specific service using the rc-service command:

$ sudo rc-service modules status
* status: started

This output indicates the modules service is currently active and running.

6. Conclusion

In this article, we explored how to list all running daemons in the systemd, SysVinit, and OpenRc init systems. In systemd, we looked at the systemctl command. Next, in SysVinit, we discussed the service command and examined the /etc/init.d/ directory. Lastly, in OpenRc, we utilized the rc-status and rc-service commands.