List running services in Ubuntu
How To

List Running Services in Ubuntu

Pranav Krishna
Pranav Krishna

Table of Contents

If you have written a service, or apparently some functionality is not working, you might have to check the services list.

For that, you should know what system manager you're using.

Most systems use a software suite called systemd, and that's what Ubuntu distributions are based on. Hence, I will cover systemd-based methods in this article.

How to list running services using systemctl

The systemctl is a command found in systemd-based kernels, that is used to manage services. And it can also be used to monitor services.

To do that, it's very simple. Just type

systemctl
systemctl output (initial view)
The output of systemctl (normal view)

That's the list of all the services running in your system. You can scroll through this list which follows Vim keystrokes.

Listing services based on their states

But that's not it!

You can tune the output as per your need by using the --state flag as shown:

systemctl list-units --state=<state>

Here are several examples of how you can use the --state flag.

1. List failed services using the systemctl command

Here, I am listing the services that have failed. It is done by adding a "failed" attribute to the variable, like

systemctl list-units --state=failed
List of failed services
Failed services being listed (if any)

2. List active services using the systemctl command

To list all the active services, you'd have to append active to the --state flag as shown:

systemctl list-units --state=active
List of active services
Active services being listed

You are free to try out other states too by experimenting with your system.

Service status Description
active Service is running in the background
inactive Service is not running.
enabled Service is enabled to run automatically at boot time.
disabled Service is disabled and will not be started automatically at boot time.
static Service can be started by another systemd unit automatically.
masked Service is completely disabled and any start operation on it always fails.
alias Service name is an alias and is symlink to another unit file.
failed Service failed.

How to search for a process using systemctl

Locating specific services is also a thing. For this, you've got two options:

  • Search through the list (with Vim keystrokes)
  • Use grep or similar command to filter the output

Searching through the list

If you have used Vim previously, you can tackle this easily. When inside this long list, press slash (/) and enter the search term.

Suppose I am looking for snap-based services, I can search the list as shown below.

Searching through the list via Vim keystrokes
Searching through the list

Using the grep command

The grep command filters the output of a command with the search term. It is given while entering the command itself.

For example, here I wanted to list the inactive service named apparmor, so I used the --state=inactive flag with the grep command:

systemctl list-units --state=inactive | grep apparmor
Inactive services searched through grep
Inactive services searched through grep

Bonus: View the running processes in tree format

So if you want to view the running processes in a tree format, you can use the pstree command. This gives you an idea of the origin of each service you're looking for and might help you with troubleshooting at times.

Command execution is pretty simple and all you need to do is run pstree:

pstree
pstree output
Output of pstree

Want to create a systemd service by yourself?

If you don't know, you can create a specific service tuned as per your needs using the systemd.

Want to know how? We have a detailed guide for that purpose:

How to create a systemd service in Linux
Learn the steps for creating systemd services in Linux with the practical example demonstrated in this tutorial.

I hope you will find this guide helpful. Still have doubts? Leave a comment.



Pranav Krishna

Pranav Krishna

This is Pranav Krishna, a Proud Linux user in twelfth grade.