Linux Labs

Users, permissions, and processes / Stage 10 of 13

Observing processes

Not running Starting usually ~20 s
Leave the lesson

Step 2 of 7 · on a machine · 5 min

Processes you never started

About a hundred processes run without you. This step covers where they come from and how to find the ones you need by name.

You have already seen your terminal's processes in ps: the bash shell and ps itself, each with a number and an account. The rest of the machine's processes were started by systemd at boot, and after it by services and other accounts. A process number is called a PID: a process gets it at start, and once the process ends, another one may get the same number.

One program can run in several processes at once, each with its own PID. So a program name does not yet identify a process: there is more than one indexer on this machine.

pgrep with -l prints the PID and name of every process whose name contains the given word:

bash
pgrep -l indexer

On the machine from the first step it prints three lines: three processes of one program. pgrep does not tell you which of them keeps the CPU busy: top shows that, and ps prints the details of each process.

Check yourself 1 question

pgrep -l indexer printed three lines. You end the process with the number from the first line. What happens to the other two?

  • The program is shared, but the processes are independent. A signal sent by number reaches one process: pgrep -l indexer then prints two lines.

  • The program file sits on disk apart from its processes, and ending a process leaves it alone. ls -l /usr/local/bin/indexer shows the file still there.

  • A process gets its number at start, and a running process keeps it. pgrep -l indexer shows the same PIDs for the two that remain.

Processes of one program are independent: each has its own PID, memory, and state. Ending one touches neither the others nor the program file on disk.

Key points

  • The machine's processes are started by systemd, services, and other accounts; each has its own PID and an owner.
  • One program can run in several processes, and a freed PID later goes to another process.
  • pgrep -l word prints the PID and name of the processes with that word in their name.
Ubuntu 24.04
Loading…