Linux Processes: ps, top and kill

Every running program is a process with its own number, called a PID. ps and top show what is running and how much it is using, and kill stops a process that is stuck.

Seeing what is running

ps aux
Lists every process, with its user, PID, CPU and memory use.
ps aux --sort=-%mem | head
Shows the processes using the most memory.
ps aux --sort=-%cpu | head
Shows the processes using the most CPU.
pgrep -a bash
Finds processes by name and shows their PIDs.

Watching live with top

top
Shows running processes, updating every few seconds. If it's installed, htop is easier to read and use.
KeyWhat it does
PSort by CPU use
MSort by memory use
kKill a process (asks for the PID)
1Show each CPU core
qQuit

Stopping a process

kill 1234
Asks process 1234 to close. Most programs tidy up and exit.
kill -9 1234
Forces process 1234 to stop immediately. Use this only if a normal kill doesn't work, as unsaved work is lost.
pkill firefox
Stops every process named firefox.

Be careful who you stop. Killing system processes can crash your computer. Check the name and PID with ps or pgrep first.

Quick reference

OptionMeaning
ps auxList all processes
pgrep -a nameFind a process by name
top / htopWatch processes live
kill PIDAsk a process to close
kill -9 PIDForce a process to stop
pkill nameStop processes by name