Understanding the services running on your Linux system is crucial for system administration, performance monitoring, and troubleshooting. Knowing how to list running services in Linux empowers you to identify resource-intensive processes, verify the status of critical applications, and gain a comprehensive overview of your system's activity.

This detailed guide will explore various command-line tools and techniques to effectively manage & list running services in Linux, enhancing your system control.  

Why is Listing Running Services Important?

Before diving into the commands, let's understand why the ability to list running services Linux is so vital:

  • System Health Monitoring: By examining the running services, you can identify any unusual or unexpected processes that might be consuming excessive resources (CPU, memory) or indicating a potential security breach.
  • Troubleshooting Application Issues: If an application is malfunctioning, checking its associated services can help pinpoint whether the service is running correctly or encountering errors.
  • Verifying Service Status: After starting, stopping, or restarting a service, you need to confirm its current status to ensure the operation was successful.
  • Resource Management: Understanding which services are running allows you to optimize resource allocation by disabling non-essential services.
  • Security Auditing: Identifying all running services is a fundamental step in security audits to ensure only authorized services are active.

Powerful Command-Line Tools to List Running Services in Linux:

Linux offers several command-line tools to provide insights into the running services. Here are some of the most commonly used and effective methods to list running services Linux:  

1. The systemctl Command (For Systemd-Based Systems)

Most modern Linux distributions (like Ubuntu, Fedora, Debian, CentOS 7 and later) utilize systemd as their init system and service manager. The systemctl command is the primary tool for managing and inspecting services under systemd.  

Listing all active (running) services:

systemctl list-units --type=service --state=running
  • systemctl: The main command for interacting with systemd.
  • list-units: Displays a list of units that systemd manages.
  • --type=service: Filters the list to show only units of the "service" type.
  • --state=running: Further filters the list to display only services that are currently in the "running" state.

Output Interpretation:

The output typically includes columns like:

  • UNIT: The name of the service unit file (e.g., apache2.service, ssh.service).
  • LOAD: Indicates whether the unit definition has been loaded successfully.
  • ACTIVE: Shows the high-level activation state of the unit (e.g., active, inactive, failed). For our command, all listed services will have an active state.
  • SUB: Provides more detailed information about the unit's state (e.g., running, exited, waiting). For running services, this will usually be running.
  • DESCRIPTION: A brief description of the service.

Listing all services (active, inactive, failed, etc.):

To get a comprehensive list of all services managed by systemd, regardless of their current state, use:

systemctl list-units --type=service

Filtering by state:

You can also filter by other states like inactive, failed, or enabled (services configured to start at boot):

systemctl list-units --type=service --state=inactive
systemctl list-units --type=service --state=failed
systemctl list-units --type=service --state=enabled

2. The service Command (Compatibility Layer)

The service command is often provided as a compatibility layer for systems using init systems other than systemd (like SysVinit or Upstart). On systemd-based systems, it typically acts as a wrapper around systemctl.

Listing all running services using service:

service --status-all | grep "\[ + \] "
  • service --status-all: Attempts to query the status of all known services. The output format can vary depending on the underlying init system.
  • | grep "\[ + \] ": This pipes the output to the grep command, which filters lines containing "[ + ]", typically indicating a running service in many service implementations.

Note: The output format and the effectiveness of this command can vary across different Linux distributions and init systems. systemctl is generally the more reliable and consistent method on modern distributions.

3. The ps Command (Process Status)

The ps command provides information about running processes. While it doesn't directly list services in the same way as systemctl, you can use it to identify the processes associated with running services.

Listing all processes associated with services:

ps aux | grep -E 'systemd.*--user|/sbin/init|/usr/sbin/.*d' | grep -v grep
  • ps aux: Displays a detailed list of all running processes on the system.
    • a: Show processes of all users.
    • u: Display the user who owns the process.
    • x: Show processes not attached to a terminal.
  • | grep -E 'systemd.*--user|/sbin/init|/usr/sbin/.*d': This pipes the output to grep and uses extended regular expressions (-E) to find lines containing:
    • systemd.*--user: User-specific systemd instances.
    • /sbin/init: The main initialization process (typically PID 1).
    • /usr/sbin/.*d: Processes that often represent system daemons (services), usually ending with "d".
  • | grep -v grep: This further filters out the grep process itself from the results.

Listing processes by a specific user (often associated with services):

ps -u <username>

Replace <username> with the user account under which the service might be running (e.g., www-data for Apache or Nginx).

4. The /proc Filesystem

The /proc filesystem is a virtual filesystem that provides information about running processes and the kernel. While not a direct way to list running services Linux in a user-friendly format, you can explore the /proc/<PID>/cmdline file for each process to see the command that started it.

Listing command lines of all processes (can be overwhelming):

for pid in /proc/[0-9]*; do echo "$pid: $(cat $pid/cmdline)"; done

This command iterates through all directories under /proc that represent process IDs and displays the command line used to start each process. You would then need to manually identify the processes associated with services.

Filtering by common service paths:

You can combine this with grep to look for processes started from common service directories:

for pid in /proc/[0-9]*; do cat "$pid/cmdline" | grep -q "/usr/sbin/" && echo "$pid: $(cat $pid/cmdline)"; done

This command looks for processes whose command line includes /usr/sbin/, a common location for service executables.

5. Graphical System Monitor Tools

While this article focuses on command-line tools for SEO purposes related to "list running services Linux," it's worth mentioning that most Linux desktop environments provide graphical system monitor tools (e.g., GNOME System Monitor, KDE System Monitor, htop in graphical mode) that offer a visual representation of running processes and services. These tools often provide more user-friendly interfaces for browsing and managing services.  

Choosing the Right Tool:

  • For modern systemd-based distributions, systemctl is the most reliable and recommended tool to list running services Linux and manage their state.
  • The service command can be used for compatibility but might have varying output.
  • ps provides a broader view of all running processes, which can be helpful for identifying processes associated with services.
  • The /proc filesystem offers low-level process information but requires more manual interpretation.
  • Graphical system monitors are excellent for visual inspection but are not ideal for scripting or remote access.

Tips for Effective Service Management:

Once you know how to list running services Linux, you can further manage them using the same tools:

  • Check the status of a specific service:
    systemctl status <service_name>
    service <service_name> status
    

    Replace <service_name> with the actual name of the service (e.g., apache2.service, ssh).

  • Start a service:
    sudo systemctl start <service_name>
    sudo service <service_name> start
    
  • Stop a service:
    sudo systemctl stop <service_name>
    sudo service <service_name> stop
    
  • Restart a service:
    sudo systemctl restart <service_name>
    sudo service <service_name> restart
    
  • Enable a service to start at boot:
    sudo systemctl enable <service_name>
    
  • Disable a service from starting at boot:
    sudo systemctl disable <service_name>
    

Conclusion:

Mastering the ability to list running services Linux is a fundamental skill for any Linux user or administrator. By utilizing the powerful command-line tools like systemctl, service, and ps, you gain valuable insights into your system's operation, enabling effective monitoring, troubleshooting, and resource management & you can list running services in Linux.

Remember that systemctl is the preferred method on modern Linux distributions for its clarity and comprehensive service management capabilities. This knowledge empowers you to take control of your Linux environment and ensure its smooth and efficient operation.

We are giving you exclusive deals to try Linux Servers for free with 100$ credit, check these links to claim your 100$,

DigitalOcean - 100$ free credit & Linode - 100$ free credit

Check some Exclusive Deals, HERE.

Also, check out DevOps Book You should read section.