How to List Running Services on Linux
In Linux systems, managing services is a critical task for system administrators. Services, also known as daemons, are background processes that perform various functions, from managing network connections to running scheduled tasks. Knowing how to list running services is essential for monitoring system health, troubleshooting issues, and ensuring that essential services are operational. This article will guide you through different methods to list running services on Linux, using various tools and commands, with detailed examples.
Understanding the status of running services helps in maintaining a Linux system efficiently. Services can be managed through different init systems, such as SysVinit, Upstart, or systemd. Each system has its own set of tools and commands for managing services. In this article, we will focus primarily on systemd
, the most widely used init system in modern Linux distributions, but will also cover other methods where applicable.
Using Systemd to List Running Services
Systemd is the default init system for many Linux distributions, including Ubuntu, CentOS, Fedora, and Debian. It provides a unified method for managing system services and offers a range of commands to list and manage running services.
Listing All Active Services
To list all active services using systemd
, you can use the systemctl
command. This command interacts with the systemd system and service manager.
systemctl list-units --type=service --state=running
list-units
: Lists all active units.--type=service
: Filters the output to show only services.--state=running
: Shows only services that are currently running.
Example
$ systemctl list-units --type=service --state=running
Output:
UNIT LOAD ACTIVE SUB DESCRIPTION
acpid.service loaded active running ACPI event daemon
apache2.service loaded active running The Apache HTTP Server
dbus.service loaded active running D-Bus System Message Bus
...
Listing All Services, Including Inactive and Failed
If you need to see all services, including those that are inactive or failed, you can omit the --state
option.
systemctl list-units --type=service
Example
$ systemctl list-units --type=service
Output:
UNIT LOAD ACTIVE SUB DESCRIPTION
acpid.service loaded active running ACPI event daemon
apache2.service loaded active running The Apache HTTP Server
dbus.service loaded active running D-Bus System Message Bus
example.service loaded inactive dead Example service
...
Checking the Status of a Specific Service
To check the status of a specific service, use the systemctl status
command followed by the service name.
systemctl status [service-name]
Example
$ systemctl status apache2
Output:
● apache2.service - The Apache HTTP Server
Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2024-07-19 12:34:56 UTC; 2h 15min ago
Main PID: 1234 (apache2)
Tasks: 6 (limit: 4915)
Memory: 15.3M
CGroup: /system.slice/apache2.service
├─1234 /usr/sbin/apache2 -k start
├─1235 /usr/sbin/apache2 -k start
...
Affordable VPS Hosting With Dracula Servers
Looking for reliable and budget-friendly Virtual Private Server (VPS) hosting? Look no further than Dracula Servers. Dracula Servers offers a range of VPS hosting plans tailored to meet diverse needs. With competitive pricing, robust performance, and a user-friendly interface, it’s an excellent choice for individuals and businesses alike.
Explore the Dracula Servers website to discover hosting solutions that align with your requirements and take your online presence to new heights with their affordable and efficient VPS hosting services.
Visit Dracula Servers and experience reliable VPS hosting without breaking the bank.
Using the service
Command
For systems that use SysVinit or Upstart, the service
command is a traditional method for managing services. This command provides a simpler interface for checking the status of services.
Listing All Services
service --status-all
This command lists the status of all services, showing +
for running services and -
for stopped services.
Example
$ service --status-all
Output:
[ + ] acpid
[ - ] apache2
[ + ] dbus
[ - ] example
...
Checking the Status of a Specific Service
To check the status of a specific service:
service [service-name] status
Example
$ service apache2 status
Output:
apache2 is running
Using the ps
Command
The ps
command can be used to list processes, which includes services running in the background. While not specifically designed for service management, it can be useful for a general overview.
Listing Processes
ps aux
a
: Show processes for all users.u
: Display the user/owner column.x
: Show processes not attached to a terminal.
Example
$ ps aux
Output:
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.1 22560 1824 ? Ss Jul19 0:01 /sbin/init
www-data 1234 0.0 0.3 23456 3456 ? S Jul19 0:02 /usr/sbin/apache2 -k start
...
Using the top
Command
The top
command provides a real-time view of running processes and their resource usage. It’s useful for monitoring system performance and identifying resource-intensive services.
Running top
top
In the top
output, you can see processes, their status, and resource usage.
Example
$ top
Output:
top - 12:50:20 up 2:15, 2 users, load average: 0.10, 0.15, 0.10
Tasks: 152 total, 2 running, 150 sleeping, 0 stopped, 0 zombie
%Cpu(s): 2.5 us, 1.0 sy, 0.0 ni, 96.0 id, 0.5 wa, 0.0 hi, 0.0 si, 0.0 st
KiB Mem : 2048348 total, 556972 free, 856828 used, 635548 buff/cache
KiB Swap: 0 total, 0 free, 0 used. 1084884 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1234 www-data 20 0 23456 3456 1234 S 0.1 0.2 0:01.23 apache2
...
Using htop
for Enhanced Visualization
htop
is an interactive process viewer that provides a more user-friendly and colorful display compared to top
.
Installing htop
On Debian-based systems:
sudo apt install htop
On Red Hat-based systems:
sudo yum install htop
On Fedora:
sudo dnf install htop
Running htop
htop
Example
$ htop
Output:
A color-coded, interactive process list with CPU, memory, and swap usage graphs.
Additional Tips
- Understanding Service States: Knowing the different states of services (active, inactive, failed) can help in diagnosing system issues. Use
systemctl list-units --type=service
to see these states. - Checking Logs: If a service is not running as expected, check its logs using
journalctl -u [service-name]
for systemd services or/var/log/
for traditional services. - Service Management: Besides listing, you may need to start, stop, or restart services. Commands like
systemctl start [service-name]
,systemctl stop [service-name]
, andsystemctl restart [service-name]
are useful in such scenarios.
Wrap up
Listing running services is an essential skill for Linux system administrators. Whether using systemd
, SysVinit
, or Upstart
, understanding how to view and manage services ensures that your system runs smoothly and reliably.
From using systemctl
to explore service statuses to employing ps
, top
, and htop
for process insights, each tool provides unique advantages for monitoring and managing your Linux environment.
Check out More Linux Tutorials Here!