Course / 03 Command line / Lesson 12 of 19

Processes

Estimated time: 15 min reading · 15 min activity

A long-running command can continue after the shell prompt returns. Before trying to stop it, identify the exact running instance that belongs to your activity. Its name alone is not enough: other work may use the same program.

A process is a running instance of a program. A foreground job occupies the shell's immediate interaction, while a background job allows more input while it runs. A PID is an operating-system process identifier. A jobspec such as %1 identifies a job in one particular shell.

Before you begin

Estimated time
15 min reading, 15 min activity. Setup and optional practice may take longer.
Where you work
Use Bash in your owned Ubuntu practice environment as an ordinary user. The supplied text files use UTF-8, a text encoding; where shown, LC_ALL=C requests consistent text ordering. Work only under your own new ~/yanosec-lab directory, never a host share or personal/system file. Refuse an existing exercise destination rather than overwriting it. No account, paid platform, or remote target is required. Optional extensions take about 10–15 minutes and are not part of the time above. A virtual machine is optional. You can also finish the reasoning from the printed evidence.
Without a lab
The page supplies the files, source and text records needed for the activity. Without a shell, follow the numbered steps on paper, label each result as predicted, and use the separate evidence supplied by the question. Running commands can wait until your lab is available. Reading works without JavaScript. Answer checking needs JavaScript and a secure context, such as HTTPS; saving a correct result also needs usable browser storage. Missing tools, managed or mobile hosts, or a deferred guest setup never require buying a service. Keep owned lab files for review; do not use broad deletion.

After this lesson you can:

  • Identify an owned running instance from its job and PID evidence.
  • Explain foreground, background and termination signals.
  • Stop or wait for only the harmless job created in the activity.

01Example

sleep waits without changing files. The & puts this wait in the background, and jobs -l lets the same shell identify it. The job number and PID below are deliberately unspecified because they vary. Natural completion is also a valid end.

Command:
sleep 60 &

Next command:
jobs -l

Predicted state:
One newly listed sleep job, if it has not finished already
Its PID and job number come from the current observation.

Signal only that confirmed owned job, or wait for natural completion.

02Numbers have scope and a lifetime

sleep 60 waits for about 60 seconds. Putting & after it starts that wait in the background. jobs -l displays this shell's jobs with associated process IDs; -l requests the longer information. Compare the list before and after creation to identify only your new wait.

A jobspec is local to the shell that created the job. Another terminal has a different job table. A PID is an operating-system identifier, but that number can later be reused after its process ends. Neither an old worksheet number nor an old observation is a safe current signal target.

A signal requests an action from a process. kill normally sends SIGTERM, the usual termination request. It does not delete the program's stored file. Some programs can handle or delay the request, so sending it and confirming completion are different steps.

wait asks this shell to wait for the named job. A termination can give a nonzero status, and a completed job may already have left the job table. Record what actually happened. Waiting for this harmless sleep to finish naturally is always an alternative to signaling it.

A temporary job identity must come from current owned-job evidence; natural completion avoids copying an old PID.Model. A teaching model drawn by hand. It shows the idea, not real tool output.

Read the full explanation below.

Playback is optional. Step through at your own pace.

Instruction being read

sleep 60 &

Owned job and observation fields

background sleep: may be running; PID unknown; job number unknown

predicted

Observed terminal output

not observed

unobserved

A background sleep may be running; it could finish before inspection.

Follow the explanation

  1. A background sleep may be running; it could finish before inspection.
  2. jobs -l would supply identity and observation time if the job has not already finished.
  3. Natural completion ends the modeled sleep without selecting a numeric target.
Read every state and value

1. A background sleep may be running; it could finish before inspection.

Current command
launch
Data in each location
Pane: Owned job and observation fields; Text: background sleep: may be running; PID unknown; job number unknown; Status: predicted · Pane: Observed terminal output; Text: not observed; Status: unobserved
Links
From: launch; To: Owned job and observation fields; Label: modeled launch

2. jobs -l would supply identity and observation time if the job has not already finished.

Current command
jobs -l
Data in each location
Pane: Owned job and observation fields; Text: read current owned-job number, PID and observation time; actual values unknown; Status: unknown · Pane: Observed terminal output; Text: not observed; Status: unobserved
Links
From: jobs -l; To: Owned job and observation fields; Label: current observation required

3. Natural completion ends the modeled sleep without selecting a numeric target.

Current command
wait
Data in each location
Pane: Owned job and observation fields; Text: modeled sleep naturally completed; previous identities are stale; Status: completed · Pane: Observed terminal output; Text: not observed; Status: unobserved
Links
From: wait; To: Owned job and observation fields; Label: natural completion
A temporary job identity must come from current owned-job evidence; natural completion avoids copying an old PID.

03Try a single owned wait

Keep the complete activity in one Bash terminal in the owned environment. It creates no files and requests no privileged access. If you cannot identify your new job with confidence, let it complete naturally rather than guessing a target.

For the paper route, use the worksheet's complete timeline: no new wait, then a newly listed wait, then completion or termination, then no running activity wait. Label the PID and job number as changing runtime details. Explain which event ends the process and which merely reports it.

Identify only the running job you created

A process is a running program instance. Its PID is an operating-system
identifier; a jobspec belongs to one shell. Compare jobs -l before and
after creating your harmless wait. The example %1 is usable only if
that new job is currently job 1. Otherwise use its current identifier,
or let the wait complete naturally. Never paste this sheet as a script.

The timeline is a prediction, not a running job.
Run in one Bash terminal in owned guest; sleep is harmless waiting.
sleep 60 &
jobs -l
Identify only that sleep job; use its current jobspec, e.g. %1 if it
is actually job 1. Example numbers are not a real target.
kill %1
wait %1
jobs -l
kill normally requests termination, not deletion of a stored file.
wait may return a nonzero termination status; jobs may already be empty.
If sleep finished naturally, do not reuse a stale PID or jobspec.
Fallback timeline: created sleep job -> listed -> terminated or completed.
Question fixed row: PID 731, command sleep; file suffix .txt is separate.
Which identifies this running instance for PID-directed kill? PID/extension

Download the owned-job lifecycle and question's separate case

  1. Run jobs -l first and note any pre-existing jobs privately; leave them alone. Start exactly one new sleep 60 & and immediately run jobs -l again.
  2. Identify the newly created sleep job and its current jobspec/PID from your observation. Expected: a new waiting instance if it has not already completed. Do not use the worksheet's fictional numbers.
  3. To end only this job while it is still listed, use kill with its actual jobspec, e.g. kill %1 only if the created job is currently job 1. Replace the example number with the observed job number. Alternatively wait for its 60-second natural completion.
  4. Use wait with that same valid jobspec if still present, then jobs -l. A termination-related nonzero status or an already-removed job entry can occur; record actual messages rather than inventing a fixed output. Expected: the owned wait ends; other jobs remain unaffected.
  5. Before closing, confirm your created wait is finished. If unsure which job is yours, wait naturally and do not signal a guess. There are no activity files to delete and no system process to restart.

04Optional challenge

Allow about ten extra minutes. A note records yesterday's PID, while a current jobs listing uses %2. Explain why the old number cannot identify a current process safely and why %2 also needs the correct shell context. No additional signals are needed.

05Fresh cases for the checks

Use these fictional cases for the checks below. They have different inputs from the worked examples. Read them here or make notes; no installation or external service is needed.

Process card A: fictional same-shell before and afterOwned fixture. An original file made for this course. Follow the activity's instructions in your own lab.

Terminal A, before: job 1, PID 2410, sleep 300, already running in background.
Action in terminal A: start exactly one new sleep 60 &.
Terminal A, immediately after:
  job 1, PID 2410, sleep 300, running
  job 2, PID 2448, sleep 60, running
Separate terminal B: job 2, PID 2519, sleep 60, already running before this activity.
The new activity wait has not finished. These are paper identities, not live targets.

Process card B: independent foreground and background casesOwned fixture. An original file made for this course. Follow the activity's instructions in your own lab.

Case F: in an otherwise idle shell, sleep 25 starts without & and is still running.
Case B: in another otherwise idle shell, sleep 25 & starts and is still running.
No job is stopped and no other command or event changes either shell.
Independent Case E: a background sleep has ended naturally; the shell observed completion.

Process card C: independent confirmed terminationOwned fixture. An original file made for this course. Follow the activity's instructions in your own lab.

Saved file: sleep, the program instructions. No file is deleted or modified.
Running before: PID 2804 sleep; PID 2809 sleep; PID 2831 editor.
An authorized SIGTERM request targets only PID 2804.
A later observation confirms PID 2804 ended. No other process ends.
This card supplies confirmation, rather than assuming every signal ends a process immediately.

Process card D: optional changed terminalOwned fixture. An original file made for this course. Follow the activity's instructions in your own lab.

The owned activity sleep is job 3, PID 3184 in terminal C.
You then switch to terminal D. Its job 3 is PID 3201, unrelated work.
No current observation from terminal C has been made since the switch.
The task remains ending or waiting for only the activity wait.

06Explain a bounded process action

Optional self-check: describe the evidence needed before and after requesting termination of one owned wait.

Check your explanation: compare creation-time and current same-shell job evidence; distinguish shell-local jobspecs from PIDs; allow natural completion; distinguish sending SIGTERM from confirming an end; account for unrelated instances and stored files.

07Common mistakes

If jobs is empty, you may be in another shell or the job may already have completed. Do not reuse a stale PID; natural completion satisfies this activity.

If %1 refers to a previous job, stop and inspect jobs -l. The example number is not permission to target that job; only your newly created sleep qualifies.

If termination is delayed, wait and record the actual state. Do not broaden to killall, pkill or a force signal; these tools are unnecessary for the controlled lifecycle.

References

  • Ubuntu 24.04 packaged manual: bash(1)

    Shell grammar, quoting, builtins, redirection and job control; use only the sections introduced in this lesson. Use the named command and option sections. This manual describes Ubuntu 24.04 packages; your installed version can differ. The lesson supplies the facts needed for its activity.

  • Ubuntu 24.04 packaged manual: kill(1)

    Use the named command and option sections. This manual describes Ubuntu 24.04 packages; your installed version can differ. The lesson supplies the facts needed for its activity.