Introduction
Have you ever started a Python script for a machine learning experiment, popped to make a cup of tea, and then promptly forgotten all about it? Hours later, you glance at your system monitor and wonder whether it’s still working or just quietly sulking in the corner.
I once left a script running for three days before realising it was printing “Hello World” in an infinite loop thanks to a misplaced indent. Embarrassing? Absolutely. Educational? Without question.
Sometimes these things need our attention — whether to check their progress, free up system resources, or save our fans from sounding like an aircraft taking off. Processes can be obedient helpers or stubborn little gremlins hiding in the background, and knowing how to find, monitor, and, when necessary, end them is a vital skill.
In this post, we’ll tour the essentials of process management on Linux, macOS, and Windows. We’ll talk about background and foreground execution, and you’ll learn to recognise when a process needs encouragement… or when it’s time to show it the door.
Understanding Processes
Think of your computer as a busy workshop, and each process as one of its workers. When you open a program or run a script, your operating system issues that worker a unique badge — a Process ID (PID) — along with a workspace and the tools to do its job.
Some of these workers are quiet, efficient types. Others gobble up CPU cycles like biscuits at a meeting. A few might wander off and stop doing anything useful, in which case you may need to intervene.
Checking Running Processes
Before managing processes, we first need to see who’s on shift.
Linux/macOS: The Unix Way
Two classic tools reign supreme here: ps
and top
. One gives you a snapshot; the other offers a constantly updating live view.
ps
: The Instant Snapshot
ps
(short for “process status”) lists what’s running at the moment you call it. It can be terse or detailed depending on the options you choose.
ps aux
– the Swiss Army knife of process snapshots:a
: show processes for all usersu
: user-friendly output with CPU and memory columnsx
: include processes without a terminal (often background tasks)
ps aux
Example output:
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.1 103764 6332 ? Ss May02 0:02 /sbin/init
you 5678 0.0 0.5 45678 3210 pts/0 S+ 10:30 0:00 python my_script.py
The columns tell you who owns the process, how much CPU/memory it’s using, when it started, and the command that launched it. STAT
deserves special mention: R
means running, S
means sleeping, and Z
is a “zombie” — a process that’s finished but still hanging around in the table.
Tip: Zombie processes aren’t undead in the horror-film sense — they’ve already finished but their “desk” in the system hasn’t been cleared. Usually harmless, but if you see a lot of them, it’s worth investigating.
-
ps -ef
– similar information in a different layout. Some people prefer it; I tend to stick withaux
. -
Filtering with
grep
– for hunting down that one stubborn script:
ps aux | grep python
Watch out: The `grep` command will show up in its own results — don’t panic, that’s normal.
top
: The Live Dashboard
If ps
is a photo, top
is a CCTV feed.
Run:
top
and watch as the busiest processes bubble to the top in real time. Press q
to quit, P
to sort by CPU, M
for memory, N
for PID.
Tip: If you’re investigating performance issues, leave `top` running for a while — you’ll spot “spikes” that a single `ps` snapshot might miss.
Windows: Friendly Faces and Command Lines
Windows offers both the visual comfort of Task Manager and the precision of tasklist
.
Task Manager
- Open it with
Ctrl + Shift + Esc
or right-click the taskbar → Task Manager. - Processes tab – applications and background tasks with CPU/memory usage.
- Details tab – like
ps aux
, but in a neat grid.
Tip: The Details tab in Task Manager is perfect for finding the PID you’ll need for `taskkill`.
tasklist
: The Console View
tasklist
Similar in spirit to ps
, this lists the image name, PID, session, and memory usage.
Filter with:
tasklist | findstr python
Killing Processes
“Killing” is just the technical term for ending a process — no actual violence involved.
Linux/macOS: kill
kill
sends a signal to a process:
SIGTERM
(15) – the polite “please wrap up”:
kill 5678
SIGKILL
(9) – the “pull the plug” option:
kill -9 5678
Watch out: `SIGKILL` doesn’t give a process the chance to clean up. Use it only if gentler signals fail.
killall
ends all processes by name:
killall python3
Warning: `killall` will happily terminate every process matching the name. Triple-check before running it on a shared system.
Windows
In Task Manager:
- Right-click → End task (single process)
- End process tree (main process + children)
From the console:
taskkill /PID 1234
taskkill /IM python.exe
taskkill /F /IM python.exe :: force
Tip: `/F` is the nuclear option — much like `kill -9` — and should be your last resort.
Background and Foreground
On Unix-like systems, appending &
runs a job in the background:
python long_task.py &
If you’ve already started it:
Ctrl+Z
– suspendbg
– resume in background
List jobs with jobs
, bring one back with:
fg %1
To survive terminal closure:
nohup python script.py &
- Or start normally, then
disown
.
Tip: `nohup` saves the output to `nohup.out` — check that file later to see what your background task did while you were away.
Windows handles background tasks differently — often via services, scheduled tasks, or using pythonw.exe
to avoid a console window.
Preventing Unwanted Starts
Stopping processes before they start saves hassle.
Linux/macOS – check:
- Startup scripts (
/etc/systemd/system/
,~/.bashrc
) - Cron jobs (
crontab -l
)
Windows – look in:
- Startup folder (
shell:startup
) - Registry Run keys
- Task Scheduler
- Services (
services.msc
)
Tip: If something keeps reappearing no matter how many times you close it, it’s probably set up as a scheduled task or service.
Conclusion
Managing processes is part observation, part intervention. Remember:
- Look before you leap – use
ps
/Task Manager to understand the situation. - Start gently –
kill
beforekill -9
,/PID
before/F
. - Use background execution wisely – it’s a productivity multiplier.
- Learn your escape hatches – they save reboots.
Watch out: Everyone has ended the wrong process at least once — the trick is to learn from it and avoid taking down your own session again.
Happy process wrangling.
References
Did you like this post? Please let me know if you have any comments or suggestions.
Git posts that might be interesting for you