Skip to content

Processes and identifiers

Module
Processes and System Information
Difficulty
Easy
Updated
Tested on
Ubuntu 24.04.5 LTS (lab container), GNU Bash 5.2.21
On this page

You start the same command twice. A process listing shows its name twice, so the name alone cannot tell you which instance you are looking at. You need an identifier for each running instance and a way to trace who started it.

By the end, you can read a small process listing, distinguish a program from its running instances, and connect two children to their parent shell.

Finish Practice: Installing Software. Use your B04 lab directory and an interactive Bash terminal. This lesson creates no files. It starts two harmless waiting commands and ends by stopping only those commands.

These recordings come from a lab container, an isolated Linux environment sharing the Docker Desktop VM’s kernel. It has very few processes. PID 1 is the lab’s Python capture process, not systemd. Your Ubuntu VM has a different process list. Your PIDs, parent PIDs, and process order will differ; compare relationships rather than copying the recorded numbers.

A program is executable instructions stored on disk. A process is a running instance, with its own identity and execution state. An instance can be waiting rather than actively using the CPU. Your interactive Bash shell is itself a process.

Print the shell’s identifier, then start two waits:

Terminal window
printf 'Shell PID: %s\n' "$$"
sleep 300 &
first=$!
sleep 300 &
second=$!

$$ expands to this Bash shell’s process ID. The PID is the numeric identifier of a process. sleep 300 waits for 300 seconds without doing useful computation.

The & at the end starts the command and gives the prompt back at once; B13.4 explains this in full. For this lesson, it lets both waits remain alive while you inspect them. Bash prints a bracketed job number and a PID after each launch. Those are different identifiers; use the PID when comparing process listings.

$! expands to the PID of the most recently started background command. Save it immediately in a variable, as in B08.3, before starting another command in the background. The variables let the reset target your own two instances without hard-coding someone else’s PIDs.

Terminal window
ps -o pid,ppid,comm

ps reports a snapshot. Without selection options, this invocation normally selects processes with your effective user ID on the same terminal. It is not a complete inventory of the system. -o chooses the output fields:

Field What to read
PID This process’s identifier
PPID Its parent’s process identifier
COMMAND from comm Its executable name, without the full arguments

The parent PID, or PPID, identifies the process’s parent. In this example Bash launches both waits. Each sleep has a different PID but the same PPID. The shared parent is Bash; the sleeps are siblings, not parents of one another.

Predict first: will two instances of sleep have the same PID because they use the same executable?

Run it, then compare with your guess

No. In this capture, Bash is PID 11 and the sleeps are PIDs 19 and 20. Both sleeps have PPID 11. The listing also includes ps itself, PID 21 with PPID 11, because Bash started it to take the snapshot.

Two sleep processes share one parent shell In the captured snapshot, Bash PID 11 starts sleep PIDs 19 and 20. Both children have parent PID 11. Your PIDs will differ. bash: PID 11 Starts both children sleep: PID 19 PPID 11 sleep: PID 20 PPID 11
Two sleep processes share one parent shell In the captured snapshot, Bash PID 11 starts sleep PIDs 19 and 20. Both children have parent PID 11. Your PIDs will differ. bash: PID 11 Starts both children sleep: PID 19 PPID 11 sleep: PID 20 PPID 11
The captured Bash PID 11 starts sleep PIDs 19 and 20; both children have PPID 11. Your PIDs will differ.

The diagram selects the two waiting children from the snapshot; it leaves out the short-lived inspection command. It does not represent a whole machine’s process tree. On the captured listing, Bash’s own PPID is 1 because of how this lab starts the shell. Do not infer that every shell has parent PID 1.

Select the instances rather than their name

Section titled “Select the instances rather than their name”
Terminal window
ps -p "$first","$second" -o pid,ppid,comm

-p selects the comma-separated PIDs you supply. Quoted variable expansions insert the identifiers saved by your shell. This listing excludes the shell and inspection command, leaving the two instances you requested.

Names describe programs; identifiers select instances. A name such as sleep can occur on several lines. Conversely, a PID is meaningful only while identifying that process: after an instance ends, the system can reuse its number. Recheck a process before acting on an old identifier. Never substitute the diagram’s numbers into a signal command.

Two instances with one parent
learner@rootvolt:~/lab$ printf 'Shell PID: %s\n' "$$"Shell PID: 11learner@rootvolt:~/lab$ sleep 300 &[1] 19learner@rootvolt:~/lab$ first=$!learner@rootvolt:~/lab$ sleep 300 &[2] 20learner@rootvolt:~/lab$ second=$!learner@rootvolt:~/lab$ ps -o pid,ppid,comm    PID    PPID COMMAND
     11       1 bash
     19      11 sleep
     20      11 sleep
     21      11 pslearner@rootvolt:~/lab$ ps -p "$first","$second" -o pid,ppid,comm    PID    PPID COMMAND
     19      11 sleep
     20      11 sleeplearner@rootvolt:~/lab$ kill "$first" "$second"learner@rootvolt:~/lab$ wait "$first" "$second"[1]-  Terminated              sleep 300
[2]+  Terminated              sleep 300learner@rootvolt:~/lab$ ps -p "$first","$second" -o pid,ppid,comm    PID    PPID COMMANDlearner@rootvolt:~/lab$ unset first secondlearner@rootvolt:~/lab$ 

Step-by-step replay of a verified session · Recorded on Ubuntu 24.04.5 LTS, GNU Bash 5.2.21. Two real sleep instances share Bash's PID as their parent; the final commands stop and verify removal of only those instances.
Steps (29)
  1. Type printf 'Shell PID: %s\n' "$$"
  2. Press Enter
  3. Output: Shell PID: 11
  4. Type sleep 300 &
  5. Press Enter
  6. Output: [1] 19
  7. Type first=$!
  8. Press Enter
  9. Type sleep 300 &
  10. Press Enter
  11. Output: [2] 20
  12. Type second=$!
  13. Press Enter
  14. Type ps -o pid,ppid,comm
  15. Press Enter
  16. Output: PID PPID COMMAND 11 1 bash 19 11 sleep 20 11 sleep 21 11 ps
  17. Type ps -p "$first","$second" -o pid,ppid,comm
  18. Press Enter
  19. Output: PID PPID COMMAND 19 11 sleep 20 11 sleep
  20. Type kill "$first" "$second"
  21. Press Enter
  22. Type wait "$first" "$second"
  23. Press Enter
  24. Output: [1]- Terminated sleep 300 [2]+ Terminated sleep 300
  25. Type ps -p "$first","$second" -o pid,ppid,comm
  26. Press Enter
  27. Output: PID PPID COMMAND
  28. Type unset first second
  29. Press Enter
Terminal window
kill "$first" "$second"
wait "$first" "$second"
ps -p "$first","$second" -o pid,ppid,comm
unset first second

Here kill requests termination of your two waits. B13.3 explains the signal it sends. Bash’s wait waits for these background children to finish and collects their completion status. It is not another delay added to the workload. The capture reports Terminated job notices during wait, with status 143. Bash decides when to print job notices.

The final ps prints only its header and returns status 1 because neither selected process remains. An empty selection is expected after this reset. unset removes the two shell variables. No files need removal.

Reading PPID as another name for PID. Look down the PID column to find the parent identified by PPID. Several children can share that PPID.

Assuming a waiting process has ended. The sleeps produce no ordinary output while waiting, but they still appear in the snapshot. Silence does not establish completion.

Expecting ps to keep updating. Its output describes one observation. Run it again for another snapshot; the following lesson introduces an updating view.

Goal: Without starting more commands, explain which of the two recorded sleeps started the other, and why ps appears with the same parent as both. Then identify which column would let you select just one sleep for a later inspection.

Hint

Follow PPID to the parent’s PID rather than treating adjacent rows as a chain.

Solution

Neither sleep started the other. Both have Bash’s PID as their PPID. Bash also started ps, so it shares that parent. Use one sleep’s PID with ps -p to select that instance. The program name does not distinguish the two.

  • A program can have several running instances, each with a separate PID.
  • PPID connects a child to its parent; siblings can share one parent.
  • ps -o chooses fields and ps -p selects identifiers.
  • Process identifiers vary and can be reused after processes end.

Next, Inspecting activity and resources separates CPU activity, memory, and filesystem usage.