How to List All Running Services Under Systemd in Linux
Linux systems provide various system services (such as process management, login , syslog, cron, etc.) and network services (such as remote login, email, printer, web hosting, data storage, file transfer, domain name resolution (using DNS), dynamic IP address allocation (using DHCP ), etc.).
Technically, a service is a process or group of process (often called a daemon ) that runs continuously in the background, waiting for incoming requests (especially from the client).
Linux supports different ways to manage services (start, stop, restart, enable automatic startup at system startup, etc.), usually through a process or service manager. Almost all modern Linux distributions now use the same process manager: systemd .
What is Systemd?
Systemd is the system and service manager of Linux; it is a direct replacement for the init process, compatible with SysV and LSB init scripts, and the systemctl command is the main tool for managing systemd .
Why list services running in Linux?
It is important to know which services are running on your Linux system because:
- Monitor resource utilization
- Troubleshoot performance issues
- Ensure critical services are active
- Optimize system performance and security
Systemd simplifies service management using powerful systemctl commands (also known as basic commands), making it easy to list, monitor, and manage active services.
In this guide, we will demonstrate the process of listing all running services under Systemd in Linux, providing a comprehensive walkthrough for users of all experience levels.
List the running services under SystemD in Linux
When you run the systemctl command without any parameters, it displays a list of all loaded systemd units (read the systemd documentation for more information about the systemd unit), including services, showing their status (active or not).
<code># systemctl</code>
List all loaded services in Linux
To list all loaded services on the system (whether active, running, exited, or failed, use the list-units subcommand and --type
switch with the value of service.
<code># systemctl list-units --type=service OR # systemctl --type=service</code>
List only active services in Linux
To list all loaded but active services, including running and exited services, you can add the --state
option with the value active as shown below.
<code># systemctl list-units --type=service --state=active OR # systemctl --type=service --state=active</code>
Use systemctl to list running services in Linux
However, to quickly see all running services (i.e. all loaded and actively running services), run the following command.
<code># systemctl list-units --type=service --state=running OR # systemctl --type=service --state=running</code>
Let's explore the key terms related to Systemd units and their state:
- Unit – A unit can be a service, socket, device, or various other entities.
- Load – It indicates whether the unit is loaded. The cell can be loaded, but not necessarily active.
- Active – It shows if the unit is running actively, or if it is having problems and is in a failed or inactive state.
- SUB – It provides more details about unit-specific status. For a service, it may indicate whether the service is running (running), stopped (exited), or encountered a problem (failed).
- Description – It helps users identify and understand the purpose of the unit without delving into detailed configuration files.
Create an alias for the systemctl command
If you use previous commands frequently, you can create an alias command in the ~/.bashrc file as shown to make it easy to call it.
<code># vim ~/.bashrc</code>
Then, add the following line under the alias list as shown in the screenshot.
<code>alias running_services='systemctl list-units --type=service --state=running'</code>
Save changes in the file and close it. From now on, use the " running_services " command to view all loaded and actively running services on the server.
<code># running_services #use the Tab completion</code>
Find the port that the service is using
Furthermore, another important aspect of services is the ports they use. To determine which port the daemon is listening on, you can use the netstat or ss command as shown below.
Where the flag -l
means printing all listening sockets, -t
shows all TCP connections, -u
shows all UDP connections, -n
means printing the digital port number (not the application name), -p
means displaying the application name.
<code>netstat -ltup | grep zabbix_agentd OR ss -ltup | grep zabbix_agentd</code>
The fifth column shows the socket: Local address: Port. In this case, the process zabbix_agentd is listening on port 10050 .
List open firewall services and ports
Additionally, if your server is running a firewall service that controls how to block or allow data flow to a selected service or port, you can use the firewall-cmd or ufw command (depending on the Linux distribution you are using) to list the services or ports that have been opened in the firewall, as shown below.
<code>firewall-cmd --list-services [FirewallD] firewall-cmd --list-ports sudo ufw status [UFW Firewall]</code>
Automating service monitoring in Linux
Manually checking for running services can be cumbersome, especially on production servers. Automating this process ensures that you are always aware of changes in service status without manual checking.
Check running services every 5 minutes using Cron jobs
A cron job is a scheduled task in Linux that runs at specific intervals. You can use it to log running services regularly and view them later in the event of a failure or unexpected shutdown.
<code>crontab -e</code>
Add this line to record the running service every 5 minutes.
<code>*/5 * * * * systemctl list-units --type=service --state=running > /tmp/running_services.log</code>
The output will be saved in the /tmp/running_services.log
file, you can check the latest recorded services using the following command:
<code>cat /tmp/running_services.log OR tail -f /tmp/running_services.log</code>
Restart the service when the service fails
By default, if the service crashes or stops unexpectedly, it will not automatically restart unless explicitly configured. To ensure that the service restarts on failure, you can modify its systemd service unit file.
For example, edit the service configuration using the following command (replace apache2
with the actual service name you want to restart automatically):
<code>systemctl edit apache2</code>
After entering the editor, add the following lines.
<code>[Service] Restart=always RestartSec=5s</code>
Now reload systemd to apply the changes.
<code>systemctl daemon-reload</code>
Then restart the service to make sure it picks up the new settings
<code>systemctl restart apache2</code>
Confirm that systemd is set to automatically restart the service.
<code>systemctl show apache2 --property=Restart</code>
in conclusion
That's it now! In this guide, we demonstrate how to view the running services under systemd in Linux. We also covered how to check the ports the service is listening on and how to view the service or port that is open in the system firewall.
Do you have any supplements or questions? If so, please contact us using the comment form below.
The above is the detailed content of How to List All Running Services Under Systemd in Linux. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











The Internet does not rely on a single operating system, but Linux plays an important role in it. Linux is widely used in servers and network devices and is popular for its stability, security and scalability.

The average annual salary of Linux administrators is $75,000 to $95,000 in the United States and €40,000 to €60,000 in Europe. To increase salary, you can: 1. Continuously learn new technologies, such as cloud computing and container technology; 2. Accumulate project experience and establish Portfolio; 3. Establish a professional network and expand your network.

The main tasks of Linux system administrators include system monitoring and performance tuning, user management, software package management, security management and backup, troubleshooting and resolution, performance optimization and best practices. 1. Use top, htop and other tools to monitor system performance and tune it. 2. Manage user accounts and permissions through useradd commands and other commands. 3. Use apt and yum to manage software packages to ensure system updates and security. 4. Configure a firewall, monitor logs, and perform data backup to ensure system security. 5. Troubleshoot and resolve through log analysis and tool use. 6. Optimize kernel parameters and application configuration, and follow best practices to improve system performance and stability.

The main differences between Linux and Windows in virtualization support are: 1) Linux provides KVM and Xen, with outstanding performance and flexibility, suitable for high customization environments; 2) Windows supports virtualization through Hyper-V, with a friendly interface, and is closely integrated with the Microsoft ecosystem, suitable for enterprises that rely on Microsoft software.

The main uses of Linux include: 1. Server operating system, 2. Embedded system, 3. Desktop operating system, 4. Development and testing environment. Linux excels in these areas, providing stability, security and efficient development tools.

Learning Linux is not difficult. 1.Linux is an open source operating system based on Unix and is widely used in servers, embedded systems and personal computers. 2. Understanding file system and permission management is the key. The file system is hierarchical, and permissions include reading, writing and execution. 3. Package management systems such as apt and dnf make software management convenient. 4. Process management is implemented through ps and top commands. 5. Start learning from basic commands such as mkdir, cd, touch and nano, and then try advanced usage such as shell scripts and text processing. 6. Common errors such as permission problems can be solved through sudo and chmod. 7. Performance optimization suggestions include using htop to monitor resources, cleaning unnecessary files, and using sy

For years, Linux software distribution relied on native formats like DEB and RPM, deeply ingrained in each distribution's ecosystem. However, Flatpak and Snap have emerged, promising a universal approach to application packaging. This article exami

This guide explores various methods for comparing text files in Linux, a crucial task for system administrators and developers. We'll cover command-line tools and visual diff tools, highlighting their strengths and appropriate use cases. Let's assum
