← All lessons
Processes and scripts · Lesson 1 of 7

Processes

A running program is a process. Each one has a number, its process ID or PID, and a parent: the process that started it. When you run ls, the shell starts an ls process, waits for it to finish and shows the prompt again.

ps lists processes. On its own it shows only the ones in this terminal; ps aux shows everything on the machine, with who owns it and how much processor (%CPU) and memory (%MEM) it uses. Pipe it into grep to find one: ps aux | grep nginx.

top is a live view, sorted by what's busiest, refreshing every few seconds. Press q to leave. Many systems also have htop, a friendlier version.

$ pgrep -l firefox
4211 firefox
$ kill 4211

kill sends a process a signal. Despite the name, the default signal, TERM, politely asks the program to finish up and exit. If it ignores that, kill -9 (KILL) stops it at once, with no chance to save anything, so use it only after a normal kill fails. pkill firefox and killall firefox do it by name instead of by number.

You can only signal your own processes. Stopping someone else's, or a system service's, needs sudo.

Practice

What is a PID?

More info

Quick reference

ps, ps auxThis terminal's processes; all of them.
top, htopLive view. q quits.
pgrep -l nameFind PIDs by name.
kill PIDAsk a process to stop (TERM).
kill -9 PIDForce it to stop (KILL). Last resort.
pkill name, killall nameSignal by name.

The other Linux courses