Process Management
In Linux, every running program is a process consuming CPU cycles, memory, and I/O resources. Some processes run quietly in the background, while others demand immediate attention. Mastering process management allows you to observe, prioritize, and control these tasks, ensuring system stability and performance.
What is a Process?
A process is an instance of a running program. Each process has:
- PID (Process ID): A unique identifier assigned by the kernel.
- Parent Process: The process that created it (e.g., the shell).
- Resources: CPU cycles, memory, file handles, and I/O.
- Types: Foreground (interactive) or background (silent).
Core Process Commands
| # | Command | Description |
|---|---|---|
| 1 | ps | Lists active processes. |
| 2 | top | Displays live resource usage of processes. |
| 3 | htop | Interactive, colorful version of top. |
| 4 | jobs | Lists background processes started in the shell. |
| 5 | fg / bg | Moves processes between foreground and background. |
| 6 | kill | Terminates a process by PID. |
| 7 | killall | Terminates all processes with a given name. |
| 8 | nice / renice | Adjusts process priority (CPU scheduling weight). |
Process Lifecycle
| Stage | Description |
|---|---|
| Created | Summoned by a parent process (e.g. shell). |
| Ready | Waiting for CPU time. |
| Running | Actively executing instructions. |
| Waiting | Paused, waiting for resources. |
| Terminated | Process ends, resources released. |
Signals: Messages to Processes
Processes can be controlled using signals:
| # | Signal | Description |
|---|---|---|
| 1 | SIGTERM (15) | Politely requests termination. |
| 2 | SIGKILL (9) | Forcefully kills a process. |
| 3 | SIGSTOP | Pauses a process. |
| 4 | SIGCONT | Resumes a paused process. |
kill -9 1729
# โ Forcefully kills process with PID 1729Practical Exercises
Try these commands to practice process management:
# Adjust process priority
nice -n 10 ./heavy_spell.sh
renice -n -5 <PID>
# Terminate a process
kill -9 <PID>
# Move process to foreground
fg %1
# Start a background process
sleep 100 &
jobs
# Monitor live processes
top
# List all processes
ps auxHackers Quest - Mini Project
Create a Potion Lab Simulation:
- Run three background processes (
sleep,yes,ping). - Use
psandtopto observe them. - Adjust one processโs priority with
nice. - Kill one process gracefully, another forcefully.
- Document the lifecycle of each process in your spellbook.
Hackers Notebook
Processes are the living heartbeat of Linux. Some bubble gently, others roar with intensity. To master Linux, you must not only create programs but also control and manage the processes that run them. Command the cauldrons, and you command the kingdom.
