βš™οΈ Linux/Unix: Process & Job Control
Estimated reading: 3 minutes 41 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 output❌Scripting, one-time listing
pstreeTree view of processesHierarchical❌Understanding 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 :

Leave a Reply

Your email address will not be published. Required fields are marked *

Share

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

Or Copy Link

CONTENTS
Scroll to Top