Skip to main content

Chapter 4.1 - Introduction to Processes

Learning Objectives​

By the end of this chapter, you will be able to:

  • Understand what a process is
  • Explain the lifecycle of a process
  • Identify running processes
  • Understand process hierarchy

What is a Process?​

A process is an instance of a program in execution. Each process has its own resources: memory, open files, etc.

Characteristics:

  • PID (Process ID): Unique identifier
  • PPID (Parent Process ID): Parent process
  • Memory space: Isolated from other processes
  • Resources: Open files, network, etc.

The Management Problem​

Without proper management:

  • How to see which programs are running?
  • How to stop a program that is not responding?
  • How to manage used resources?
  • How to understand the hierarchy?

The Solution: Management Tools​

Linux provides many tools to manage processes:


Process Lifecycle​

States:

  • Created: Process created (fork)
  • Ready: Ready to execute
  • Running: Currently executing
  • Blocked: Waiting (I/O, signal)
  • Terminated: Finished

Process Hierarchy​

Processes form a tree:

Characteristics:

  • init/systemd: PID 1, parent of all
  • Child processes: Created by fork()
  • Orphan processes: Adopted by init if parent dies
  • Zombie processes: Finished but not cleaned up

Basic Commands​

ps - View Processes​

# All processes
ps aux

# User's processes
ps

# Custom format
ps -eo pid,ppid,cmd,%mem,%cpu

# By user
ps -u user1

# Process tree
ps auxf
ps -ejH

top - Real-Time Monitoring​

# Interactive interface
top

# Options
top -u user1 # By user
top -p 1234 # Specific process
top -d 2 # Update every 2 seconds

Commands in top:

  • q: Quit
  • k: Kill a process
  • r: Change priority
  • M: Sort by memory
  • P: Sort by CPU

htop - Enhanced Version​

# More user-friendly interface
htop

# Install if necessary
sudo apt install htop # Ubuntu/Debian
sudo yum install htop # Red Hat/CentOS

Summary​

In this chapter, you learned:

Processes: Instance of a program in execution
PID/PPID: Unique identifiers, hierarchy
Lifecycle: Created → Ready → Running → Blocked → Terminated
Hierarchy: Tree with init as root
Tools: ps, top, htop to view and monitor


Next Steps​

Chapter 4.2: Process Visualization
Chapter 4.3: Process Control


Chapter created on: December 2024