This article focuses on how to list all running services under systemd in Linux. Different services run on your Linux system, and while some are started at system boot, you have room to start, stop, and manage the Linux services at your convenience. All Linux services are managed through Systemd, and with the systemctl command, you can quickly list all the services running in the background to check their state. We will give different examples of listing all running services in Linux. Take a look!
Working with Systemd in Linux
Linux systemd is a system and service manager that allows users to control various services running in the background. Whenever your Linux kernel boots, the systemd is one of the init tools that gets started to bring up the system. All the services in Linux are available as unit files and can be found in the /usr/lib/systemd/.
When run alone, the systemctl command will list all the loaded services in your system. You will get an output like the one below.
The key drawback with using this option to check the running services is that you can’t see the state of each service. Some services are loaded but currently disabled. To list only the running services, you must use the systemctl command with other options.
1) Listing All Services
There is a neater way of listing all the running services under systemd. You only need to add the list-units option followed by the –type=service to specify that we only want to access the services. The final command would be as follows.
You will get an output showing different sections with their headers, like the one below.
The first column header, UNIT, represents the name of each of the services under Systemd. Next, the LOAD shows if the named service is parsed by Systemd. It tells if a given service is loaded or not.
The ACTIVE column shows the state of a service. For instance, a service could be active or inactive. As for the SUB, it describes the low-level state of the particular service. You will see different low-level states, such as running, exited, failed, etc. Lastly, each service briefly describes what it does under the DESCRIPTION section.
2) Listing All Running Services Under Systemd
The list we get from the previous command doesn’t meet our expectations for checking only the running services. Thus, we must add another option, –state=running, to filter the listed services.
Here’s the command to use.
Now, we can verify that the SUB section only shows a running state, and we have a list of all the running services under Systemd for our Linux system.
With the above results, you can search for a given service to check if it’s listed as running. We will combine the earlier command and pipe it with the grep command. For instance, if we want to check if snapd.service is among the running services, we would change our command as follows.
The above output filters the results and confirms that the snapd.service is among the running services. Feel free to try the command with a different service and see what you get.
Suppose you wanted to check the running services to change their state. You can utilize the systemctl command for the same. First, let’s check the status of the snapd.service in detail using the command below.
You will notice that we now get results similar to those we got when we listed all the running services. However, our results only focus on the target service. We can see that snapd.service is marked as loaded, active, and running for this case.
To stop such a service, you must use systemctl with the stop option. Use the following command.
You must have sudo privileges to execute this command. Upon execution, you get a warning that the service has been stopped.
If we try rechecking its status, we verify that its previous active(running) state is inactive(dead).
Even when we try using the systemctl with grep to filter snapd.service from the running services, we don’t get any output. This further shows that snapd.service is no longer running.
That’s how you control Linux services under Systemd using systemctl. You can rerun the systemctl command to start the service and make it run again, as demonstrated below.
Conclusion
When you want to list all the running services under Systemd in Linux, you need the systemctl command. The command has different options that allow you to define how you want to list the Linux services. We’ve highlighted what command to use when accessing the running services. Refer to the article for more details.