Linux/Unix: Process Overview & Commands β ps, pstree, top, htop Explained
Introduction β Why Learn Process Management in Linux?
Processes are the core running programs on any Linux/Unix system. Managing and monitoring them is essential for troubleshooting performance, identifying resource hogs, and understanding system behavior. Tools like ps, pstree, top, and htop provide various levels of visibility into active processes.
In this guide, youβll learn:
- What a process is in Linux/Unix
- How to view, analyze, and manage processes using popular commands
- Outputs and options for
ps,pstree,top, andhtop
What is a Process?
A process is a running instance of a program. Each process has:
- A PID (Process ID)
- A PPID (Parent Process ID)
- A UID (User ID)
- A State (Running, Sleeping, Zombie, etc.)
ps β Snapshot of Active Processes
Syntax:
ps [options]
Example 1: View current userβs processes
ps
Output:
PID TTY TIME CMD
1023 pts/0 00:00:00 bash
1055 pts/0 00:00:00 ps
Example 2: View all processes with full format
ps -ef
Output:
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 09:00 ? 00:00:01 /sbin/init
user 1023 1 0 09:01 pts/0 00:00:00 bash
Example 3: Tree structure of all processes
ps -ejH
π΄ pstree β View Process Tree Hierarchy
Syntax:
pstree [options]
Example:
pstree -p
Output:
systemd(1)ββ¬βsshd(656)βββsshd(1050)βββbash(1051)
ββcron(678)
Shows parent-child relationships using a tree format. -p shows PIDs.
top β Real-Time Process Monitor
Syntax:
top
Description:
Displays dynamic real-time stats including:
- CPU/Memory usage
- Process list with PID, USER, %CPU, %MEM, TIME+, COMMAND
- Load averages and system uptime
Sample Output:
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1023 user 20 0 5384 1608 1348 S 0.3 0.1 0:00.03 bash
1055 user 20 0 5800 820 716 R 0.7 0.0 0:00.01 top
Press:
qto quitkto kill a processPto sort by CPUMto sort by memory
htop β Advanced Interactive Process Viewer
Syntax:
htop
Description:
- Colorful and user-friendly version of
top - Allows mouse navigation, search, and filtering
- Easier process tree view, CPU/RAM bar graphs
Features:
- F1βF10 function keys
- F9 to kill process
- F3 to search
- Arrow keys to navigate
Install it if not present:
sudo apt install htop # Debian/Ubuntu
sudo yum install htop # RHEL/CentOS
Functional Comparison Table
| Command | Purpose | Output Type | Interactivity | Ideal For |
|---|---|---|---|---|
ps | Static process snapshot | One-time output | Scripting, one-time listing | |
pstree | Tree view of processes | Hierarchical | Understanding process parentage | |
top | Live monitor | Real-time | (keyboard) | Resource monitoring |
htop | Enhanced top | Real-time | (mouse + kb) | Interactive system analysis |
Summary β Recap & Next Steps
Understanding and managing processes is essential to maintaining a healthy Linux/Unix environment. These tools offer different ways to inspect and interact with the processes that run your system.
Key Takeaways:
- Use
psfor a quick snapshot or scripting pstreehelps visualize process hierarchytopprovides real-time resource statshtopoffers an interactive and visual alternative
FAQs
What is the difference between ps and top?
ps shows a static snapshot, while top is real-time and interactive.
How can I kill a process using its PID?
Use:
kill <PID>
How do I sort by memory in top?
Press M to sort by memory usage.
Is htop better than top?
For interactive use, yes. Itβs more user-friendly, colorful, and supports keyboard/mouse controls.
How to find the parent of a process?
Use:
ps -o ppid= -p <PID>
Share Now :
