Every program you run on Unix becomes a process. The kernel keeps track of all of them โ who owns them, how much memory they are using, how long they have been running. When something goes wrong, the first thing you do is look at the process list.
Viewing processes with ps
ps stands for "process status." Run without options it only shows processes attached to your current terminal. To see everything, use ps aux โ a, u, and x mean "all users," "detailed format," and "include processes without a terminal."
$ ps aux
USER PID %CPU %MEM VSZ RSS TT STAT STARTED TIME COMMAND
alice 1234 0.5 2.3 423456 23456 ?? S 10:15AM 0:02.32 nginx
root 1235 0.0 0.1 123456 1234 ?? Ss 10:15AM 0:00.01 nginx
alice 5678 1.2 8.1 1023456 89123 ?? R 10:20AM 0:15.42 node server.js
The PID column is the process ID โ unique number for each running process. The COMMAND column shows what is running. %CPU and %MEM tell you how much of each resource it is consuming.
Try it Yourself โInteractive monitoring with top
top shows a live, updating view of processes sorted by CPU usage. It refreshes every few seconds. Hit q to quit. If you have htop installed, it is even nicer โ color-coded and scrollable.
$ top
top - 10:25:01 up 3 days, 2:15, 2 users, load average: 0.45, 0.32, 0.20
Tasks: 123 total, 1 running, 122 sleeping
%Cpu(s): 8.2 us, 2.1 sy, 89.7 id
KiB Mem : 8123456 total, 2345678 free
Try it Yourself โ
Killing processes with kill
When a process freezes or consumes too much, you can terminate it with kill. You need to know the PID. kill PID sends SIGTERM (signal 15) โ a polite request to shut down. Most processes comply.
$ kill 5678
If a process refuses to die, use kill -9 PID to send SIGKILL. It cannot be ignored. Think of it as the difference between asking someone to leave and throwing them out.
$ kill -9 5678
Be careful with kill -9. The process gets no chance to clean up, which can corrupt files or leave things in a bad state. Use the regular kill first.