A Guide to Linux Process Management with `ps`, `top`, and `htop`
Jul 25, 2025 am 02:55 AMUsing ps, top and htop is the core method of managing Linux processes. 1. Use ps to view process snapshots, which are suitable for quick inspection, script automation or finding specific processes. For example, ps aux can list all processes, combined with grep to filter specified processes, ps auxf can display process tree structure. 2. Use top for real-time monitoring, provide dynamically updated system resources and process information, sorted by CPU usage by default, and supports interactive operations such as reordering by P or M, killing processes, adjusting priority, and exiting by q. 3. Use htop to get a more friendly enhancement interface. It needs to be installed first. Its advantages include color display, complete command line, resource usage bar, mouse support and F6 sorting, F9 killing process, F7/F8 adjustment priority, F4 search, F10 exit and other convenient functions. According to the scene selection tool: PS is suitable for static viewing and scripting, top is suitable for real-time monitoring of a graphless environment, htop is suitable for interactive in-depth analysis, and mastering the three can fully control the operating status of the system.
Managing processes is a fundamental skill for anyone working with Linux. Whether you're troubleshooting performance issues, monitoring system resources, or just trying to understand what's running on your machine, tools like ps
, top
, and htop
are essential. Here's a practical guide to using each of them effectively.

Understanding Processes in Linux
Before diving into the tools, it helps to know that in Linux, every running program is a process . Each process has a unique Process ID (PID), runs under a user, consumes CPU and memory, and can be in various states (running, sleeping, stopped, etc.). Process management lets you view, monitor, and control these running tasks.
1. ps
: View Snapshot of Running Processes
The ps
command gives you a static snapshot of current processes. It's lightweight and perfect for scripting or quick checks.

Common ps
Commands
-
Basic usage
ps
Shows processes associated with the current terminal session.
Full listing of all processes
ps aux
-
a
: all users' processes -
u
: display in user-friendly format -
x
: include processes not attached to a terminal
Output includes:
- USER : who owns the process
- PID : process ID
- %CPU and %MEM : resource usage
- STAT : process state (eg,
S
= sleeping,R
= running) - COMMAND : the command that started the process
-
Filter processes by name
ps aux | grep nginx
Useful to find specific processes.
Show process tree
ps auxf
Displays processes in a hierarchical tree view, helpful for seeing parent-child relationships.
Pro tip: Combine
ps
withgrep
,awk
, orsort
for powerful one-liners. For example:ps aux --sort=-%mem | head -10Lists the top 10 memory-consuming processes.
2. top
: Real-Time Process Monitoring
top
provides a dynamic, real-time view of running processes and system resource usage.
Getting Started with top
Run it simply with:
top
Key Features
- Live updates : Refreshes every few seconds (default: 3 sec)
- System summary at the top:
- Uptime, load averages
- CPU usage breakdown (user, system, idle, etc.)
- Memory and swap usage
- Process list below, sorted by CPU usage by default
Useful Interactive Commands in top
While top
is running, press:
- P → Sort by CPU usage
- M → Sort by memory usage
- k → Kill a process (prompts for PID and signal)
- r → Renice a process (change schedule priority)
- q → Quit
- h → Help menu
You can also start
top
in batch mode for scripting:top -b -n 5Runs in non-interactive mode and exits after 5 iterations.
3. htop
: Enhanced, User-Friendly Process Viewer
htop
is an improved version of top
with a more intuitive interface, color coding, and mouse support. It's not installed by default on most systems, so you may need to install it:
# Ubuntu/Debian sudo apt install htop # CentOS/RHEL sudo yum install htop # or on newer versions: sudo dnf install htop
Why htop
Is Better Than top
- Color-coded output for easy reading
- Vertical and horizontal scrolling through processes and command lines
- Visible resource meters (CPU, memory, swap) at the top
- Mouse support for clicking and selecting
- Easier process management (kill, renice) via a visual interface
Key Controls in htop
- Arrow keys : Navigate
- F6 → Sort by field (eg, PID, CPU%, MEM%)
- F9 → Kill selected process
- F7/F8 → Increase/decrease process priority (nice value)
- F4 → Search for a process
- F10 → Quit
Unlike
top
,htop
shows full command lines even if they're long — no more...
truncation.
When to Use Which Tool?
-
Use
ps
when:- You need a quick snapshot
- Writing scripts or automation
- Looking for a specific process
-
Use
top
when:- You want real-time monitoring without installing extra tools
- Working on a minimum or remote server
-
Use
htop
when:- You want a clearer, more interactive view
- Doing detailed troubleshooting
- Prefer a more modern, user-friendly interface
Process monitoring doesn't have to be intimidating. With ps
, top
, and htop
, you've got the right tools for every situation — from quick checks to deep system analysis. Get comfortable with all three, and you'll always know what's happening under the hood.
The above is the detailed content of A Guide to Linux Process Management with `ps`, `top`, and `htop`. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

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

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

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)

LXD is described as the next-generation container and virtual machine manager that offers an immersive for Linux systems running inside containers or as virtual machines. It provides images for an inordinate number of Linux distributions with support

When encountering DNS problems, first check the /etc/resolv.conf file to see if the correct nameserver is configured; secondly, you can manually add public DNS such as 8.8.8.8 for testing; then use nslookup and dig commands to verify whether DNS resolution is normal. If these tools are not installed, you can first install the dnsutils or bind-utils package; then check the systemd-resolved service status and configuration file /etc/systemd/resolved.conf, and set DNS and FallbackDNS as needed and restart the service; finally check the network interface status and firewall rules, confirm that port 53 is not

If you find that the server is running slowly or the memory usage is too high, you should check the cause before operating. First, you need to check the system resource usage, use top, htop, free-h, iostat, ss-antp and other commands to check CPU, memory, disk I/O and network connections; secondly, analyze specific process problems, and track the behavior of high-occupancy processes through tools such as ps, jstack, strace; then check logs and monitoring data, view OOM records, exception requests, slow queries and other clues; finally, targeted processing is carried out based on common reasons such as memory leaks, connection pool exhaustion, cache failure storms, and timing task conflicts, optimize code logic, set up a timeout retry mechanism, add current limit fuses, and regularly pressure measurement and evaluation resources.

As a system administrator, you may find yourself (today or in the future) working in an environment where Windows and Linux coexist. It is no secret that some big companies prefer (or have to) run some of their production services in Windows boxes an

Frankly speaking, I cannot recall the last time I used a PC with a CD/DVD drive. This is thanks to the ever-evolving tech industry which has seen optical disks replaced by USB drives and other smaller and compact storage media that offer more storage

In Linux systems, 1. Use ipa or hostname-I command to view private IP; 2. Use curlifconfig.me or curlipinfo.io/ip to obtain public IP; 3. The desktop version can view private IP through system settings, and the browser can access specific websites to view public IP; 4. Common commands can be set as aliases for quick call. These methods are simple and practical, suitable for IP viewing needs in different scenarios.

Built on Chrome’s V8 engine, Node.JS is an open-source, event-driven JavaScript runtime environment crafted for building scalable applications and backend APIs. NodeJS is known for being lightweight and efficient due to its non-blocking I/O model and

Data replication is the process of copying your data across multiple servers to improve data availability and enhance the reliability and performance of an application. In MySQL replication, data is copied from a database from the master server to ot
