Influencing Process Scheduling
Objectives:
After completing this section, you should be able to prioritize or de-prioritize specific processes using the nice and renice commands.
Linux Process Scheduling and Multitasking:
Modern computer systems, regardless of their specifications, often need to handle more processes than there are processing units available. Linux and other operating systems manage this through time-slicing or multitasking, where the process scheduler rapidly switches between processes on a single core, creating the illusion of simultaneous execution.
Relative Priorities:
Processes have varying levels of importance, and Linux provides different scheduling policies to accommodate this. The default policy, SCHED_OTHER or SCHED_NORMAL, assigns each process a 'nice' value, ranging from -20 (highest priority) to 19 (lowest priority). Lower nice values indicate higher priority, while higher values indicate lower priority. Processes with higher nice values receive less CPU time when resources are scarce.
Setting Nice Levels and Permissions:
Only the root user can decrease a process's nice level, as reducing the priority of a CPU-intensive process could affect the performance of other processes. Unprivileged users can increase their own process nice levels but cannot decrease them or modify others' nice levels.
Reporting Nice Levels:
Tools like top and ps display nice levels. Top shows the nice value and scheduled priority in its interface, while ps can list processes along with their nice levels and scheduling classes.
Starting Processes with Different Nice Levels:
New processes inherit their parent's nice level by default. Users can use the nice command to start processes with specific nice levels, defaulting to 10 if not specified. Unprivileged users can only increase nice levels up to 19, while root can decrease them to -20.
Changing the Nice Level of an Existing Process:
The renice command allows users to alter the nice level of an existing process. Only root can decrease nice levels, while both root and unprivileged users can increase them. Additionally, top provides an interactive interface to change nice levels.
Understanding and utilizing these commands enable users to influence the scheduling priorities of processes in a Linux system effectively.
Top comments (0)