Start a long-running job in the background, inspect it with
jobs, bring it to the foreground, suspend it, then
resume it in the background. Terminate the job cleanly with
kill after you confirm the correct PID.
You are multitasking in a terminal while running a long command in the background. You need to list active jobs, move the job into the foreground when you need focus, suspend it, resume it in the background, then terminate it once the work is no longer needed.
Job control is how you stay productive in a shell. It lets you manage long-running tasks without opening extra terminals or losing track of what is running where.
kill.&
).
SIGTSTP).
fg and bg move a job between
terminal-attached and background execution.
%1) is not the same as a PID.
Use a PID when sending signals with kill.
sleep 1000 &
Appending
&
runs the command as a background job and immediately returns
control to your prompt. The shell prints the job number and
the PID it launched.
[1] 1843
jobs
jobs
shows active jobs for the current shell session. Capture the
job spec (%1) and the state (running or stopped).
[1]+ Running sleep 1000 &
fg %1
# OR (only job)
fg
Foregrounding the job attaches it to your terminal. Suspend it with Ctrl+Z to stop the process without killing it, which keeps it tracked by the shell.
sleep 1000
^Z
[1]+ Stopped sleep 1000
bg %1
# OR (only job)
bg
bg
continues a stopped job in the background. Use
jobs
again to confirm it returns to a running state.
[1]+ sleep 1000 &
ps -p 1843
kill 1843
Job numbers and PIDs are different identifiers. Use
ps -p
to confirm the PID is still present, then send
SIGTERM
with
kill
(default behavior) to request clean termination.
[1]+ Terminated sleep 1000
jobs
only tracks jobs started in the current shell session. If
the process was started elsewhere, use process tooling
(ps, pgrep) instead of job control.
The job spec is wrong or the job already exited. Re-run
jobs
to confirm the job number, and use the % prefix
(%1) when targeting a specific job.
You signaled a PID without verifying it. Always validate the
PID first with
ps -p 1843
, especially when multiple similar processes exist.
Ctrl+Z only affects the foreground process group attached to
your terminal. If the job is still in the background, bring
it to the foreground with
fg
first.
This lab changes runtime state only. Cleanup is confirming the background job is gone and the shell has no remaining tracked jobs.
jobs
ps -p 1843
jobs
returns no active jobs, and
ps -p
shows no such PID.
sleep 1000 &
: Runs a command in the background and returns the prompt.
&
: Starts the process as a background job.
jobs
: Lists jobs managed by the current shell session.
fg %1
: Brings a job into the foreground (attaches it to the TTY).
%1
: Refers to job 1 as shown in jobs output.
bg %1
: Resumes a stopped job in the background.
ps -p 1843
: Checks whether PID 1843 still exists.
-p
: Restricts output to the specified PID.
kill 1843
: Sends SIGTERM by default to request clean
termination for PID 1843.