The Art of Process Management – Controlling the Chaos
In the mystical world of Linux, everything you run is a process—from opening a terminal to running a server. But some processes are obedient, while others… go rogue. 😈
Today, we learn to create, monitor, and terminate processes with precision.
Understanding Processes
Want to see all running processes? Use:
ps aux
You’ll get something like:
ninja 1234 1.2 0.3 45678 5678 ? S 10:00 0:01 python3 script.py
What does this mean?
🏷 Column | 🧐 Meaning |
---|---|
ninja | User who owns the process |
1234 | Process ID (PID) |
1.2 | CPU usage (%) |
0.3 | Memory usage (%) |
S | Process state (S = Sleeping, R = Running, Z = Zombie) |
python3 | The command running |
If you need live monitoring, use:
top
or its fancy cousin:
htop # Install it with 'sudo apt install htop'
Starting Processes – The Summoning Ritual
Run a program normally:
firefox
But it locks your terminal! 😱 To run it in the background, use:
firefox &
The &
tells Linux: "Run this, but don’t hold my terminal hostage!" 🎭
Want to see background jobs? Use:
jobs
To bring a background job back to the foreground:
fg %1 # If it's job number 1
Finding a Process
To find a specific process, use:
ps aux | grep firefox
or
pgrep -l firefox
This will show the process ID (PID), which is important for… 👇
Killing a Process – When Things Go Wrong
Sometimes, programs freeze or consume too many resources. You need to terminate them with style:
kill PID
Example:
kill 1234 # Politely asks process 1234 to exit
If the process ignores you? Bring out the big guns:
kill -9 1234 # Immediate termination. No mercy. 🚀
Or just use:
pkill firefox # Kill all processes with "firefox" in their name
For extreme measures, wipe out everything from a user:
killall -u ninja
Careful! This logs the user out instantly. 😈
Controlling Running Processes
⏸ Pausing a Process
Ever wanted to pause a process without killing it? Use:
Ctrl + Z # Freezes the running process
To resume it in the foreground:
fg
To resume it in the background:
bg
Giving a Process Superpowers (Nice & Renice)
To change process priority:
nice -n 10 long_running_script.sh # Lower priority
nice -n -5 important_task.sh # Higher priority
To change the priority of an existing process:
renice -n 5 -p 1234 # Adjust priority of process 1234