Linux Process Management: ps, kill,
top, nice - Training Notes & Lab Guide
Overview
This training covers Linux process management including identifying, managing,
prioritizing, and terminating processes using commands like ps, kill, top, nice, renice, jobs,
fg, bg, and control signals.
Key Concepts
- A process is an instance of a running program.
- Every process has a unique Process ID (PID) and a Parent Process ID (PPID).
- Process states: Running, Sleeping, Stopped, Zombie.
- Foreground vs Background processes.
- Scheduling and priority: Managed via 'nice' levels and system schedulers.
Essential Process Commands
Command Description
ps List currently running processes (basic
view)
ps aux | head Show top processes with CPU, memory
usage
ps lax Show detailed info including PPID, priority,
nice value
jobs List background jobs
sleep <seconds> & Start a sleep process in the background
fg %<job_number> Bring background job to foreground
bg %<job_number> Resume stopped job in background
Ctrl+Z Send foreground job to background
(stopped)
kill <PID> Kill a process using its PID
killall <name> Kill all processes with a given name
pkill <pattern> Kill processes matching pattern
top Live system process monitor with stats
top → Shift+M Sort processes by memory usage
top → Shift+P Sort processes by CPU usage
top → K Kill a process from top interface
nice -n <value> <command> Start a process with given nice level
renice -n <value> -p <PID> Change priority of an existing process
Step-by-Step Lab Exercises
1. View Running Processes:
ps
ps aux | head
ps lax
2. Start a Background Process:
sleep 30 &
3. Use jobs, fg, bg:
jobs
fg %1
Ctrl+Z then bg %1
4. Filter Processes:
ps aux | grep sleep
5. Kill a Process:
kill <PID>
killall sleep
6. Use top Command:
top
→ Shift+M: sort by memory
→ Shift+P: sort by CPU
→ K to kill a process, Q to quit
7. Set Priority (root user):
nice -n -5 sleep 60 &
renice -n -10 -p <PID>
8. Priority Management (normal user):
nice -n 15 sleep 60 &
renice -n 18 -p <PID>
9. Invalid Priority as Normal User:
nice -n -5 sleep 60 # Permission denied