What is a Linux Service?
In simpler terms, a Linux service is a server’s response to a request that performs a specific task. It is an application or a program that generally executes in the background.
As a user, you are mostly unaware of all the services running in the background because there are plenty of them.
You might have run through the term daemon most probably while working or learning about services. Daemon is a non-interactive program that runs in the background and strictly does not provide any interfaces for the user to control it.
Some of the common characteristics of a Linux service are:
- There is no GUI(Graphical User Interface).
- Most of the native services start along with the start of the OS.
- Some services wait for an interrupt or a signal to get started.
Some common examples of Linux services are mysql, apparmor, httpd and nfs.
Table of Contents
Detecting the System Manger
Detecting the system manager of your Linux system is the elementary step to listing the running services. This step is essential as the commands for listing the services are based on the system manager.
The system manager is the first process that starts in your system. So, you can use the following command to list the first process in the system.
ps -p 1
The output looks like this if the system manager is systemd.
PID TTY TIME CMD 1 ? 00:00:02 systemd
systemd is used in the newer Linux distributions.
If the system manager used is
SysV, the output looks like this.
PID TTY TIME CMD 1 ? 00:00:02 init
SysV is also known as
init or initialization. It was used in early Linux distributions, and lately, it has been replaced by
Thus, you can find the system manager from the
CMD column of the outputs above. According to the service manager present, you can use the respective methods.
Listing Services in the systemd Service Manager
There are a couple of ways to list the running services when the system manager is
systemd, and let’s explore each of them.
Using the systemctl Command
You can use the systemctl command to list the services in your Linux system.
list-units subcommand with the
--type=service option will list all the services. It includes active, failed, active (exited), and active (running) services.
systemctl list-units --type=service
The output of the above command is shown below.
In the output above, you can notice several columns. Let’s get to know what they represent.
UNIT: It is an object that starts, stops and manages the services.
LOAD: It states whether the particular unit is correctly loaded.
ACTIVE: It is a high-level state that determines whether the unit is active.
SUB: It represents the low-level activation state of the unit.
DESCRIPTION: It describes the task that the unit performs.
In the sections below, you will learn to list the services according to their states. Some of the
systemd states are active, inactive, activating, deactivating, failed, not-found, dead, etc.
Listing the ACTIVE Services using the systemctl Command
You can use specific options and the
systemctl command to filter the services. With the
--state option, you can set the state of the services. For example, if you want only the active services listed, you can use the following command.
systemctl list-units --type=service --state=active
We have used the
--state option with the value
active to denote only the active services. In the output below, you can see the active status of all the units.
Listing the FAILED Services using the systemctl Command
Similarly, you can list only the failed services with the following command.
systemctl list-units --type=service --state=failed
Listing the running Services using the systemctl Command
To list only the running services, use the following command.
systemctl list-units --type=service --state=running
A running service has an active value for the ACTIVE state and a running value for the SUB state.
Listing the exited Services using the systemctl Command
Exited services are the one-shot type of services which does their job and are closed. The following command can be used to list the
systemctl list-units --type=service --state=exited
The ACTIVE state holds the value active for exited service, while the SUB state has the value exited.
Listing Services in the SysV Service Manager
In this section, you will learn a few ways of listing the system’s services that use the
SysV service manager.
Listing the Services with service Command
In the system with the
SysV service manager, you can use the
service command to list all the services.
The output of the command is shown below.
The symbols in the brackets represent the status of the services.
- –: It represents the services that are stopped.
- +: It represents the services that are running.
- ?: It represents the services without the status command.
To list only the running services, you can use the following command.
service --status-all | grep running
Listing Services with the ls Command
Another way you can list the services of
init scripts is using the
ls command. Using the
ls command on the directory containing the
init scripts does the job. The
init scripts are located in the path /etc/init.d. An example is shown below.
ls -l /etc/init.d/*
The output of the above command is shown below.
In this tutorial, you learned to identify the system manager used in your Linux system. Thus, you grasped the idea of using the various commands to list the Linux services.