Process Management Basics: Understanding System Operations
All programs running on a Linux system are managed as processes. In this basics guide, you'll learn safe and reliable methods from basic process concepts to monitoring and termination operations.
Table of Contents
1. Basic Process Concepts
What is a Process?
A process is an instance of a running program. It refers to the state of being loaded into memory and executed by the CPU.
Examples: Text editor, web browser, backup script, etc.
Process Hierarchy
In Linux, all processes have a parent-child relationship. The init process (PID 1) at system startup is the ancestor of all processes.
Process States
- R (Running): Running or runnable
- S (Sleeping): Interruptible wait state
- D (Uninterruptible sleep): Uninterruptible wait
- Z (Zombie): Terminated but awaiting parent collection
- T (Traced/stopped): Stopped or being traced
Important Concepts
- PID (Process ID): Unique identifier for each process
- PPID (Parent Process ID): PID of parent process
- UID: User ID running the process
- CPU Usage: Percentage of CPU used by process
- Memory Usage: Amount of memory used by process
2. ps - Display Processes
The ps command is a basic tool for displaying information about currently running processes.
Basic Usage
Current Terminal's Processes
$ ps
PID TTY TIME CMD 1234 pts/0 00:00:00 bash 1456 pts/0 00:00:00 ps
Commonly Used Options
All Processes
$ ps aux
Detailed display of all processes for all users
Hierarchical Display
$ ps auxf
Display process parent-child relationships in tree format
Specific User
$ ps -u username
Display only specified user's processes
Process Search
$ ps aux | grep nginx
Search for nginx processes
Filtering and Customization
Sort by CPU Usage
$ ps aux --sort=-%cpu | head -10
Display top 10 by CPU usage in descending order
Sort by Memory Usage
$ ps aux --sort=-%mem | head -10
Display top 10 by memory usage in descending order
Custom Output Format
$ ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%cpu
Display only specified fields
3. top/htop - Real-time Monitoring
top - System Monitoring
Basic Usage
$ top
Displayed Information:
- System uptime and load average
- Task count (running, stopped, zombie)
- CPU usage (user, system, idle)
- Memory usage (physical, swap)
- Detailed information for each process
Interactive Commands in top
q
Quit
k
Kill process (enter PID)
r
Change nice value
P
Sort by CPU usage
M
Sort by memory usage
T
Sort by running time
u
Filter by specific user
1
Toggle individual CPU display
htop - Improved top
htop is an improved version of top that provides a more user-friendly interface.
Installation (Ubuntu/Debian)
$ sudo apt install htop
Execution
$ htop
4. kill - Terminate Processes
The kill command sends signals to processes to control them.
Main Signals
| Signal | Number | Description | Use Case |
|---|---|---|---|
| TERM | 15 | Graceful termination request | Normal termination (default) |
| KILL | 9 | Force kill | Unresponsive processes |
| HUP | 1 | Restart | Reload configuration |
| INT | 2 | Interrupt | Equivalent to Ctrl+C |
| STOP | 19 | Suspend | Temporarily suspend process |
| CONT | 18 | Resume | Resume stopped process |
Usage Examples
Normal Termination
$ kill 1234
Send graceful termination signal (TERM) to process PID 1234
Force Kill
$ kill -9 1234
Force kill process PID 1234
Terminate by Process Name
$ killall firefox
Terminate all processes named firefox
Terminate by Pattern Match
$ pkill -f "python script.py"
Terminate processes matching command line
Terminate Multiple Processes
$ kill -9 $(ps aux | grep 'python script.py' | awk '{print $2}')
Batch terminate multiple matching processes
⚠️ Safe Termination Sequence
- Try TERM signal first:
kill PID - Wait a few seconds and check process status
- Use KILL signal only if unresponsive:
kill -9 PID
Use KILL signal (-9) as a last resort only.
⚠️ Common Mistakes and Pitfalls
Common beginner mistakes in process management and how to avoid them.
🚫 Mistake 1: Using kill -9 Immediately
❌ Bad Example
$ kill -9 1234 # Immediate force kill
Risk of data loss or file corruption.
✅ Correct Method
$ kill 1234 # Try graceful termination first $ sleep 3 # Wait a bit $ ps -p 1234 # Check process status $ kill -9 1234 # Only if absolutely necessary
Terminate safely with a gradual approach.
🚫 Mistake 2: Accidentally Terminating System Processes
❌ Dangerous Example
$ kill 1 # init process (absolutely NO) $ kill 2 # kthreadd (kernel process)
Can cause system instability or crashes.
✅ Safe Verification Method
# Verify process details before executing $ ps -p 1234 -o pid,ppid,cmd,user $ ps aux | grep 1234 # Check if it's a system process $ ps -eo pid,cmd | grep -E "^\s*[0-9]+ \[.*\]"
Always verify process details before operation.
🚫 Mistake 3: Misidentifying grep Results
❌ Example Requiring Caution
$ ps aux | grep python user 1234 0.0 0.1 1234 456 pts/0 S+ 14:30 0:00 grep python
The grep command itself can appear as a process.
✅ Correct Search Method
# Use pgrep (recommended) $ pgrep -f python # Techniques when using grep $ ps aux | grep python | grep -v grep $ ps aux | grep [p]ython # Bracket technique
Use specialized commands or techniques for accurate search.
🚫 Mistake 4: Not Understanding PID Reuse
❌ Misunderstanding Example
# Using PID noted yesterday as-is $ kill 1234 # Might be a different process!
PIDs are reused, so over time they may refer to different processes.
✅ Safe Verification Method
# Verify current process before executing $ ps -p 1234 -o pid,cmd,etime $ pgrep -f "specific_command_name"
Always verify the process before operation.
🚫 Mistake 5: Ignoring Permission Errors
❌ Dangerous Response
$ kill 1234 kill: (1234) - Operation not permitted $ sudo kill -9 1234 # Immediate sudo force kill
Using sudo without understanding the cause of permission errors is dangerous.
✅ Appropriate Response
# First check process owner $ ps -p 1234 -o pid,user,cmd # If not your process, make careful judgment $ ls -la /proc/1234/ # Verify process details $ sudo ps -p 1234 -o pid,user,cmd # Verify with root privileges
Understand the cause of permission errors before responding appropriately.
💡 Tips to Prevent Mistakes
- Verification Habit: Always verify process details before killing
- Gradual Approach: Follow sequence: TERM signal → wait → KILL signal
- Backup Verification: Record process state beforehand for important processes
- Test Environment Use: Verify operation in test environment before production
- Log Verification: Check system logs for impact after process termination
📊 Complete Process Management Series
- Basics (This Article) - ps, top, kill fundamental operations
- Practical Guide - Job control, nice, system monitoring
As an Amazon Associate, this site earns from qualifying purchases through product links. This is at no additional cost to you. Book recommendations are from Amazon.co.jp (Japan), chosen for their value to Japanese-speaking learners.
📚 Recommended Books for Process Management & System Programming Learning
To efficiently master the basics of process management and system programming, we've carefully selected practical learning books. Deepen your understanding of ps, top, kill and acquire programming skills.
📚 新しいLinuxの教科書
Target Level: Beginner to Intermediate
Systematically learn from basic process management concepts to practical operations. A comprehensive textbook for acquiring essential real-work knowledge like shell operations, process monitoring, and signal control step by step. Ideal for beginners.
📚 Linuxコマンドブック ビギナーズ 第5版
Target Level: Entry to Beginner
Complete reference coverage of process management commands like ps, top, kill. Detailed explanations of command usage and options with practical examples. A practical guide to keep at hand.
📚 Linuxシステムプログラミング
Target Level: Intermediate to Advanced
Deep understanding of process management internal implementation and system calls (fork, exec, wait). A specialized book for practically learning low-level APIs like signal handling, inter-process communication, and memory management. A must-read for programmers.
📚 ゼロからわかる Linux超入門[Ubuntu対応版]
Target Level: Entry
Carefully explains Linux basics including process management from a beginner's perspective. An introductory book for learning command operations from scratch in Ubuntu environment. Designed with abundant illustrations to minimize frustration. Ideal material for Linux beginners.