Scenario
The server feels sluggish during routine work, and you suspect a mix of interactive shells and CPU-heavy commands are competing for resources. You need to manage job state (foreground versus background) and reduce the priority of a noisy workload so the system stays usable while it runs.
Job control keeps you productive in a live shell session. Priority control helps you reduce impact on shared systems without killing work that still needs to finish.
Objective
- Launch a long-running job in the background and confirm it is running.
- Bring a background job to the foreground and suspend it safely.
- Resume a suspended job in the background and confirm job state.
-
Start a CPU-heavy workload with reduced priority using
nice.
Concepts
- Job control is scoped to the current shell and tracks jobs started from that session.
- Foreground jobs are attached to your terminal; background jobs continue running while you keep working.
- Suspending a job stops it without terminating, so it can be resumed later.
- Nice values influence CPU scheduling: higher nice values generally reduce CPU priority for that process.
Walkthrough
sleep 60 &
Appending & starts the command in the
background and returns you to the prompt. This is useful
for work that does not require interactive input.
[1] 1234
jobs
jobs reports tasks the current shell is
tracking. This is job control scope, not a full system
process list.
[1]+ Running sleep 60 &
fg %1
fg attaches the job to your terminal again.
To pause it without killing it, press Ctrl+Z
to stop the job and return control to your shell.
sleep 60
[Ctrl+Z]
[1]+ Stopped sleep 60
bg %1
bg continues a stopped job but keeps it in the
background. This is a clean way to let work finish while
you keep using the terminal.
[1]+ sleep 60 &
yes generates endless output. Redirect to
/dev/null as shown, and treat this as a test
workload you should stop after confirming behavior.
nice -n 10 yes > /dev/null &
nice starts a process with an adjusted
scheduling priority. Higher nice values generally reduce
CPU priority so interactive tasks remain responsive.
[2] 1245
Common breakpoints
Job control only tracks processes started from the current shell. If the job was started in a different terminal or session, it will not appear here.
The job ID is shell-scoped. Re-run jobs and
use the correct job spec (for example %1).
Some programs handle signals differently, and some may ignore the terminal stop signal. Use the shell’s job list to confirm state and test with a simple workload first.
Nice affects CPU scheduling priority, not I/O or memory pressure. If the slowdown is from disk or memory, you need a different mitigation than nice alone.
Cleanup checklist
Stop any test workloads you started so they do not continue consuming CPU after you finish the lab.
jobs
kill %1
kill %2
jobs returns no active jobs, and the terminal
remains responsive with no leftover test processes running.
Reference
-
sleep 60 &: Runs a command in the background and returns control to the shell.&: backgrounds the command.
-
jobs: Lists jobs managed by the current shell session. -
fg %<job>: Brings a job to the foreground.-
%<job>: job specifier fromjobs(for example%1).
-
-
bg %<job>: Resumes a stopped job in the background.-
%<job>: job specifier fromjobs(for example%1).
-
-
nice -n <value> <command>: Starts a command with adjusted scheduling priority.-n <value>: sets the nice value.
-
yes > /dev/null: Generates continuous output redirected to null, commonly used as a simple CPU load test.> /dev/null: discards output.
-
kill %<job>: Terminates a job tracked by the current shell.-
%<job>: job specifier fromjobs(for example%2).
-