Linux's default scheduler gives each runnable task a CPU share proportional to a weight derived from its nice value (−20 … 19). Some weights: nice −5 → 3121, nice 0 → 1024, nice 5 → 335, nice 10 → 110.
- Predict: two CPU-bound processes share one core, one with nice 0 and one with nice 5. What percentage of the core should each get? Repeat for nice 0 vs. nice 10.
- Measure: on Linux, pin both to core 0 and run them:
Recordtaskset -c 0 nice -n 0 yes > /dev/null & taskset -c 0 nice -n 5 yes > /dev/null & top -d 2 # watch %CPU for the two 'yes' processes%CPU,NIandPRfor both. Then kill them and repeat with nice 10. - Compare prediction and measurement. Why is the measurement not exactly the prediction?
- What would happen without
taskseton a machine with several idle cores? Try it. - Explain how this relates to this chapter's fair-share and lottery ideas, and why a cloud provider would want weights per container rather than per process.