When using any Linux distribution, some processes and services run alongside. Some can be running in the background even without users’ knowledge. Having unnecessary services running can consume much of the system resources or also pose a security issue if measures are not put into consideration.
Therefore, there comes a need to know all the running services on your system. In this article, we look at all the possible ways which you can use to list running services on your Linux machine.
How to check running services in Linux
Let us first get a good understanding of Linux services. If a service has an initialization – script, then it comes with three statuses:
- start
- stop
- restart
All which are executed with the – service command. For example, to restart the network-manager service, run the following command:
sudo service network-manager restart
The service command references each service using the init script stored in /etc/init.d for Ubuntu and any other Debian-based distro, and etc/rc.d/init.d for RedHat-based Linux distributions. Some service name varies from one distribution to another. For example, the Apache webserver service is httpd on CentOS and Apache2 on Ubuntu.
System V(SysV) | Upstart | Systemd
A lot of Linux distros fall under of the following init systems:
- System V, which was the initial init system.
- Upstart
- systemd, which is the latest init system as of writing this article.
System V (SysV)
System V or commonly known as SysV is an old init system used by older Linux distributions and dates back to the original Unix. SysV manages the startup process using shell script present in the /etc/init*. In case you are using /etc/init.d/sshd start to start or stop a service; then you are using on a System V system.
Upstart Init System
It is an event-based init system which served as a replacement for the /sbin/init daemon. Upstart init system was used to manage the start and stopping of services during boot, shutdown, and supervising them while the system is running. Upstart was initially developed for Ubuntu Linux distro to replace the old System V used in other older distributions.
Systemd
It is the new init system that most Linux distros are moving to. It was developed to speed up the boot process, managing dependencies, and much more. In case you are using systemctl restart sshd start to start or stop a service, then you are using on a Systemd system.
Check all running services in a System V(SysV) init system
Let’s look at some of the Terminal commands you can use to list all running services in a SysV init system.
service --status-all
The above command lists all the running services in your system. In case the services running are many, you can use additional parameters – more and less to list the services in an organized and clear view.
service --status-all | less
service --status-all | more
To list only services currently running on the system, execute the command below:
service --status-all | grep running
To view the status of a particular service, execute the command below:
service --status-all | grep [service_name] e.g service --status-all | grep httpd
Alternatively, you can execute the command below to view the status of a particular service.
service httpd status
To list all the services enabled in the boot, execute the command below:
chkconfig --list
Check all running services in an Upstart init system
To list all services running on a Linux system running Upstartinit system, execute the command below:
initctl list
Check all running services in a Systemd init system
To list all running services on a Linux system running Systemd init system, execute the command below:
systemctl
From the above command, we see that the data is displayed in five columns, namely, UNIT, LOAD, ACTIVE, SUB, and DESCRIPTION. Let’s look at what each column stands for:
- UNIT – Shows the corresponding Systemd unit name.
- LOAD – This column displays whether the current unit is loaded on memory or not.
- ACTIVE – This column indicates whether the unit is in use (active) or not.
- SUB – Describes the running state of a particular unit.
- DESCRIPTION – Gives a detailed description of a particular unit.
You can also list running services based on their type using the command below:
systemctl list-units --type service
You can also list services based on their current state. It is relatively similar to the output of the previous command but a little more straightforward.
systemctl list-unit-files --type service
To list the status of a particular service, execute the command below:
systemctl status [service_name] e.g systemctl status acpid.path
To list only services currently running on the system, execute the command below:
systemctl | grep running
To list all services enabled in the boot, execute the command below:
systemctl list-unit-files | grep enabled
You can also view top control groups and their system resource usage such as I/O, CPU, Tasks, and memory using the systemd-cgtop command.
systemd-cgtop
We can also use pstree to list all running services in the system. Pstree captures this information from Systemd system output.
pstree
The pstree can also be used with System V int system. It captures output from the SysVinit system.
pstree
You can also use chkservice utility to check all running services in a Systemd system. It does not come pre-installed. However, you can install via Terminal using the command below:
sudo apt-get install chkservice
To start chkservice, execute the command below. Note, you require superuser privileges.
sudo chkservice
To see all the features that come with this fantastic tool, press the [?] key. It opens the help menu.
Conclusion
These are some of the commands and utilities you can use to check all running services on your Linux system. If you have a command or tool that we have not discussed in this post, feel free to let our readers know in the comment section.