βš™οΈ Linux/Unix: Process & Job Control
Estimated reading: 3 minutes 288 views

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, and htop

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:

  • q to quit
  • k to kill a process
  • P to sort by CPU
  • M to 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

CommandPurposeOutput TypeInteractivityIdeal For
psStatic process snapshotOne-time outputScripting, one-time listing
pstreeTree view of processesHierarchicalUnderstanding process parentage
topLive monitorReal-time (keyboard)Resource monitoring
htopEnhanced topReal-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 ps for a quick snapshot or scripting
  • pstree helps visualize process hierarchy
  • top provides real-time resource stats
  • htop offers 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 :
Share

πŸ”΅ Linux/Unix: Process Overview & Commands (ps, pstree, top, htop)

Or Copy Link

CONTENTS
Scroll to Top