Effective system administration in Linux requires constant awareness of running processes. Whether diagnosing performance bottlenecks, identifying unauthorized tasks, or ensuring critical services remain operational, the ps aux
command is an indispensable tool.
This guide provides a comprehensive exploration of ps aux
, from foundational concepts to advanced filtering techniques, equipping you to extract actionable insights from process data.
To follow the tutorial:
Before we explore the ps aux
command, let's take a moment to understand what processes are in the context of a Linux system.
A process represents an active program or service running on your Linux system. Each time you execute a command, launch an application, or initiate a background service, you create a process.
Linux assigns a unique identifier, called a Process ID (PID), to each process. This PID allows the system to track and manage individual processes effectively.
Linux employs a hierarchical structure to organize processes. This structure resembles a family tree, where the initial process, init
(or systemd
), acts as the parent or ancestor.
All other processes descend from this initial process, forming a parent-child relationship. This hierarchy facilitates efficient process management and resource allocation.
The ps
(process status) command provides a static snapshot of active processes at the moment of execution. Unlike dynamic tools such as top
or htop
, which update in real-time, ps
is ideal for scripting, logging, or analyzing processes at a specific point in time.
The ps aux
syntax merges three key options:
a
: Displays processes from all users, not just the current user.u
: Formats output with user-oriented details like CPU and memory usage.x
: Includes processes without an attached terminal, such as daemons and background services.This combination offers unparalleled visibility into system activity, making it a go-to tool for troubleshooting and analysis.
Executing ps aux
generates a table with 11 columns, each providing critical insights into process behavior. Below is a detailed explanation of these columns:
This column identifies the process owner. Entries range from standard users to system accounts like root
, mysql
, or www-data
. Monitoring this field helps detect unauthorized processes or identify which users consume excessive resources.
The Process ID (PID) is a unique numerical identifier assigned to each task. Administrators use PIDs to manage processes—for example, terminating a misbehaving application with kill [PID]
or adjusting its priority using renice
.
These columns display the percentage of CPU and RAM resources consumed by the process. Values above 50% in either column often indicate performance bottlenecks. For instance, a database process consuming 80% CPU might signal inefficient queries or insufficient hardware capacity.
VSZ (Virtual Memory Size) denotes the total virtual memory allocated to the process, including memory swapped to disk.
On the other hand, RSS (Resident Set Size) represents the physical memory actively used by the process.
A process with a high VSZ but low RSS might reserve memory without actively utilizing it, which is common in applications that preallocate resources.
This field shows the terminal associated with the process. A ?
indicates no terminal linkage, which is typical for background services like cron
or systemd-managed
tasks.
The STAT column reveals process states through a primary character + optional attributes:
Primary States:
Key Attributes:
For example, a STAT
value of Ss
denotes a sleeping session leader, while l<
indicates an idle kernel thread with high priority.
START indicates the time or date the process began. Useful for identifying long-running tasks.
TIME represents the cumulative CPU time consumed since launch. A process running for days with minimal TIME
is likely idle.
This column displays the command or application that initiated the process. It helps identify the purpose of a task—for example, /usr/bin/python3
for a Python script or /usr/sbin/nginx
for an Nginx web server.
While ps aux provides a wealth of data, its output can be overwhelming on busy systems. Below are methods to refine and analyze results effectively.
To focus on a particular service—such as SSH—pipe the output to grep
:
ps aux | grep sshd
Example output:
root 579 0.0 0.5 15436 5512 ? Ss 2024 9:35 sshd: /usr/sbin/sshd -D [listener] 0 of 10-100 startups
root 2090997 0.0 0.8 17456 8788 ? Ss 11:26 0:00 sshd: root@pts/0
root 2092718 0.0 0.1 4024 1960 pts/0 S+ 12:19 0:00 grep --color=auto sshd
This filters lines containing sshd
, revealing all SSH-related processes. To exclude the grep
command itself from results, use a regular expression:
ps aux | grep "[s]shd"
Example output:
root 579 0.0 0.5 15436 5512 ? Ss 2024 9:35 sshd: /usr/sbin/sshd -D [listener] 0 of 10-100 startups
root 2090997 0.0 0.8 17456 8788 ? Ss 11:26 0:00 sshd: root@pts/0
Identify CPU-intensive processes by sorting the output in descending order:
ps aux --sort=-%cpu | head -n 10
Example output:
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
mysql 1734280 0.4 36.4 1325172 357284 ? Ssl Jan30 87:39 /usr/sbin/mysqld
redis 1424968 0.3 0.6 136648 6240 ? Ssl Jan18 112:25 /usr/bin/redis-server 127.0.0.1:6379
root 1 0.0 0.6 165832 6824 ? Ss 2024 5:51 /lib/systemd/systemd --system --deserialize 45
root 2 0.0 0.0 0 0 ? S 2024 0:00 [kthreadd]
root 3 0.0 0.0 0 0 ? I< 2024 0:00 [rcu_gp]
root 4 0.0 0.0 0 0 ? I< 2024 0:00 [rcu_par_gp]
root 5 0.0 0.0 0 0 ? I< 2024 0:00 [slub_flushwq]
root 6 0.0 0.0 0 0 ? I< 2024 0:00 [netns]
root 8 0.0 0.0 0 0 ? I< 2024 0:00 [kworker/0:0H-events_highpri]
Similarly, you can sort by memory usage to detect potential leaks:
ps aux --sort=-%mem | head -n 10
Example output:
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
mysql 1734280 0.4 36.4 1325172 357284 ? Ssl Jan30 87:39 /usr/sbin/mysqld
root 330 0.0 4.4 269016 43900 ? S<s 2024 22:43 /lib/systemd/systemd-journald
root 368 0.0 2.7 289316 27100 ? SLsl 2024 8:19 /sbin/multipathd -d -s
root 1548462 0.0 2.5 1914688 25488 ? Ssl Jan23 2:08 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
root 1317247 0.0 1.8 1801036 17760 ? Ssl Jan14 22:24 /usr/bin/containerd
root 556 0.0 1.2 30104 11956 ? Ss 2024 0:00 /usr/bin/python3 /usr/bin/networkd-dispatcher --run-startup-triggers
root 635 0.0 1.1 107224 11092 ? Ssl 2024 0:00 /usr/bin/python3 /usr/share/unattended-upgrades/unattended-upgrade-shutdown --wait-for-signal
root 2090997 0.0 0.8 17456 8788 ? Ss 11:26 0:00 sshd: root@pts/0
root 2091033 0.0 0.8 9936 8480 pts/0 Ss 11:26 0:00 bash --rcfile /dev/fd/63
Combine ps aux
with the watch
command to refresh output every 2 seconds:
watch -n 2 "ps aux --sort=-%cpu"
This provides a dynamic view of CPU usage trends.
Zombie processes, though largely harmless, clutter the process list. Locate them with:
ps aux | grep 'Z'
Persistent zombies often indicate issues with parent processes failing to clean up child tasks.
Now, let’s explore some common use cases of the ps aux
command in Linux:
Follow the below steps:
ps aux --sort=-%cpu
kill [PID]
Or forcibly with:
kill -9 [PID]
Simply do the following:
Sort processes by memory usage:
ps aux --sort=-%mem
%MEM
values.List all processes owned by a specific user (e.g., Jenkins):
ps aux | grep ^jenkins
This helps enforce resource quotas or investigate suspicious activity.
Let’s now take a quick look at some best practices to keep in mind when managing Linux processes:
Graceful Termination: Prefer kill [PID]
over kill -9
to allow processes to clean up resources.
Log Snapshots: Periodically save process lists for audits:
ps aux > /var/log/process_audit_$(date +%F).log
Contextual Analysis: A high %CPU
value might be normal for a video encoder but alarming for a text editor. Hence, it’s essential to consider the context when making an analysis.
Here are some pitfalls to look out for when using ps aux
in Linux:
COMMAND
field before using kill to avoid disrupting essential services.The ps aux
command is a cornerstone of Linux system administration, offering deep insights into process behavior and resource utilization. You can diagnose performance issues, optimize resource allocation, and maintain system stability by mastering its output interpretation, filtering techniques, and real-world applications.
For further exploration, consult the ps manual (man ps
) or integrate process monitoring into automated scripts for proactive system management.