Scheduling priority and limits
Quick answer
Niceness affects scheduling preference for ordinary time-sharing tasks; resource limits constrain particular resources. Neither is a guaranteed CPU quota.
Prepare the practice environment
Use an ordinary user in an authorized disposable Linux VM. From the extracted package root run python3 lab-fixtures/processes/setup.py, enter its printed path and check pwd. Run each executable example in a fresh Bash process with LC_ALL=C and set -o pipefail. Do not use sudo. For interactive examples use a fresh interactive Bash and enter one command at a time. Signal only the just-started bounded child, never an arbitrary PID. Wait for completion before discarding the private workspace. Skip absent tools.
How it works
For normal Linux scheduling, niceness ranges from -20 to 19, with larger values generally meaning lower scheduling preference. nice -n N command adds an adjustment to inherited niceness; renice changes an existing target, typically setting an absolute value on util-linux. Increasing scheduling preference usually requires privilege or an applicable resource allowance; do not request it in this lab. ulimit is a shell builtin; soft limits are enforced and hard limits constrain permitted soft increases. Units depend on the option; -n counts open file descriptors. Child processes inherit resource limits. A cgroup CPU quota is a different mechanism, covered later. top periodically samples process information; htop is an optional interactive viewer. CPU percentages and states vary by sample and system.
A larger nice value generally lowers scheduling preference for normal time-sharing tasks, but the percentage of CPU time depends on other runnable work and scheduling policy. The example compares a child with its inherited baseline rather than assuming a fixed initial value or a guaranteed difference of five. A descriptor soft limit constrains the descriptor numbers that can be opened; it is not a CPU or memory allocation. Reading limits and sampling top provide evidence about current conditions, not a benchmark or proof of a bottleneck. Compare repeated observations before proposing a tuning change.
Try the examples
base=$(nice)child=$(nice -n 5 nice)if (( child >= base )); then printf 'preference not increased\n'; else exit 1; fiNo absolute starting value is assumed. The child adjustment can saturate at 19.
Expected stdout:
preference not increasedsoft=$(ulimit -Sn)hard=$(ulimit -Hn)printf '%s\n' "$soft" "$hard" | awk '/^(unlimited|[0-9]+)$/ {n++} END {if(n==2) print "limits available"; else exit 1}'Read both limits and validate their format; values vary. Use ulimit -Sn and ulimit -Hn alone to see them. No setting is changed.
Expected stdout:
limits availabletop -b -n 1 -p "$$" > sample.txtgrep -E 'PID.*COMMAND' sample.txt >/dev/null && printf 'sample captured\n'Batch mode produces one snapshot; -p scopes the task display to the current shell.
Expected stdout:
sample capturedCommon mistakes
Do not assume nice 19 means 19% CPU, or lower hard limits in your interactive shell. Do not renice unrelated processes. Avoid interpreting one top sample as a benchmark.
Practice
Compare nice in your shell and a child with adjustment +5, read soft and hard descriptor limits, and capture one top sample for your shell. Explain why none guarantees a fixed CPU percentage.
Related references
Study: nice, renice, ulimit, top, htop. These are reference names, not deployed links.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Scheduling priority and limits — Knowledge Check
Apply process lifecycle and job-control concepts to a bounded child-process lab.
What does a larger nice value usually mean?
What does nice -n 5 do?
What does ulimit -n describe?
What does top show?