In this article we will see how to use the ps
command to list all running services on Linux. In Linux, a process is an instance of a running program. Each process has a unique Process ID (PID) and can be in various states such as running, sleeping, or stopped. Services, on the other hand, are background processes that perform specific tasks, often started at boot time and managed by the system’s init system (like systemd
 or init
).
You can check more details about ps
command on the following link.
The ps
Command
The ps
(process status) command is used to display information about active processes. It provides a snapshot of the current processes, including details like PID, user, CPU usage, memory usage, and more.
Listing All Running Services
To list all running services using the ps
command, you can use various options and filters. Here are some common usages:
Basic Usage
ps -e
e
: Shows all processes.
This command lists all processes running on the system.
Detailed Information
ps -ef
e
: Shows all processes.f
: Displays full-format listing.
The -f
option provides a full-format listing, including additional details like the parent process ID (PPID) and the command that started the process.
Filtering by Service Name
ps -ef | grep <service_name>
Replace <service_name>
with the name of the service you want to filter. This command helps you find specific services.
Using ps
with aux
ps aux
a
: Shows processes for all users.u
: Displays the user-oriented format.x
: Shows processes not attached to a terminal.
The aux
options provide a detailed listing of all processes, including those not started by the current user.
Detailed Options
ps -A
orps -e
: Show all processes.ps -a
: Show all processes except session leaders and processes not associated with a terminal.ps -u [username]
: Show processes for a specific user.ps -p [pid]
: Show information for a specific process ID.ps --sort=[key]
: Sort the output based on the specified key (e.g., %cpu, %mem, pid).ps -o [format]
: Customize the output format. For example,ps -o pid,cmd
shows only the PID and command of each process.
Understanding the Output
When you run ps aux
, you typically see columns like:
- USER: The user who owns the process.
- PID: The process ID.
- %CPU: The percentage of CPU usage.
- %MEM: The percentage of memory usage.
- VSZ: Virtual memory size.
- RSS: Resident Set Size (the non-swapped physical memory that a task has used).
- TTY: The terminal associated with the process.
- STAT: The process state (e.g., S for sleeping, R for running).
- START: The start time of the process.
- TIME: The cumulative CPU time.
- COMMAND: The command that started the process.
Example
Listing All systemd
Services
systemd
is a popular init system used in many Linux distributions. To list all systemd
services, you can use:
ps -ef | grep systemd
This command will display all processes related to systemd
, helping you identify active services.
List all processes sorted by memory usage
ps aux --sort=-%mem
Display specific columns (PID, User, Command)
ps aux --sort=-%mem
Show processes of a specific user
ps -u username
Monitor the memory usage at regular intervals
watch -n 1 'ps aux --sort=-%mem | head -n 10'
You can also check this possiblity of Process Management