Process Management
View running processes, kill tasks, and manage background jobs.
ps aux, top, and kill in your real terminal.What You'll Learn
- ps and top — viewing running processes
- kill, killall, pkill — stopping processes
- Background jobs with &, bg, fg, and Ctrl+Z
- nohup — processes that survive logout
Viewing and Killing Processes
⚙️ Real-World Analogy: Think of processes as employees. ps is the employee directory. top is a live dashboard showing who's busy. kill is asking someone to leave (or escorting them out with -9).
$ ps aux # List all processes $ ps aux | grep node # Find Node.js processes $ top # Live process monitor (q to quit) $ htop # Better monitor (install separately) $ kill 1234 # Graceful stop (SIGTERM) $ kill -9 1234 # Force kill (SIGKILL) $ killall chrome # Kill all Chrome processes $ pkill -f "server.js" # Kill by command pattern
⚠️ Common Mistake
Always try kill PID (SIGTERM) first. Only use kill -9 as a last resort — it doesn't give the process a chance to clean up (close files, save data, release ports).
Processes & Signals
View and manage running processes.
// Process Management — simulated
console.log("=== ps — View Running Processes ===");
console.log("$ ps");
console.log(" PID TTY TIME CMD");
console.log(" 1234 pts/0 00:00:02 bash");
console.log(" 5678 pts/0 00:00:15 node");
console.log();
console.log("$ ps aux (ALL processes, detailed)");
console.log("USER PID %CPU %MEM VSZ RSS TTY STAT TIME COMMAND");
console.log("root 1 0.0 0.1 225M 9M ? Ss 0:03 /sbin/init");
console.log("user 1234 0.1 0.5 430
...Background Jobs
You can run commands in the background so you keep using your terminal:
$ node server.js & # Start in background $ jobs # List background jobs $ fg %1 # Bring job 1 to foreground $ bg %1 # Resume job 1 in background # Ctrl+Z pauses the current foreground process # Then use bg to continue it in the background
💡 Pro Tip
When you need a process to survive after closing the terminal (e.g., a long-running server), use nohup command &. For production, consider using pm2, systemd, or screen/tmux.
Background Jobs
Practice managing background and foreground jobs.
// Background Jobs — simulated
console.log("=== Running in Background ===");
console.log("$ node server.js &");
console.log("[1] 1234");
console.log(" → The & puts the command in the background");
console.log(" → You get your terminal back immediately!");
console.log();
console.log("=== Ctrl+Z and bg/fg ===");
console.log("1. Start a process: $ node server.js");
console.log("2. Pause it: Ctrl+Z");
console.log(" [1]+ Stopped node server.js");
console.log("3. Resume in backgr
...📋 Quick Reference
| Command | Description |
|---|---|
| ps aux | List all running processes |
| top / htop | Live process monitor |
| kill PID | Graceful stop |
| kill -9 PID | Force kill |
| command & | Run in background |
| nohup cmd & | Survive logout |
🎉 Lesson Complete!
You can now monitor and control processes like a sysadmin! Final lesson: file permissions, chmod, chown, and user management.
Sign up for free to track which lessons you've completed and get learning reminders.