Understanding the Linux Kernel by Daniel Pierre Bovet & Marco Cesati

Understanding the Linux Kernel by Daniel Pierre Bovet & Marco Cesati

Author:Daniel Pierre Bovet & Marco Cesati [Bovet, Daniel Pierre & Cesati, Marco]
Language: fra
Format: epub
Tags: Informatique
ISBN: 9780596002138
Google: 9yIEji1UheIC
Publisher: O'Reilly
Published: 2002-07-14T22:00:00+00:00


I l@ve RuBoard

11.3 System Calls Related to Scheduling

Several system calls have been introduced to allow processes to change their priorities and scheduling policies. As a general rule, users are always allowed to lower the priorities of their processes. However, if they want to modify the priorities of processes belonging to some other user or if they want to increase the priorities of their own processes, they must have superuser privileges.

11.3.1 The nice( ) System Call

The nice( )[8] system call allows processes to change their base priority. The integer value contained in the increment parameter is used to modify the nice field of the process descriptor. The nice Unix command, which allows users to run programs with modified scheduling priority, is based on this system call.

[8] Since this system call is usually invoked to lower the priority

of a process, users who invoke it for their processes are "nice" to

other users.

The sys_nice( ) service routine handles the nice( ) system call. Although the

increment parameter may have any value, absolute values larger than 40 are trimmed down to 40. Traditionally, negative values correspond to requests for priority increments and require superuser privileges, while positive ones correspond to requests for priority decrements. In the case of a negative increment, the function invokes the capable( ) function to verify whether the process has a CAP_SYS_NICE capability. We discuss that function, together with the notion of capability, in Chapter 20. If the user turns out to have

the capability required to change priorities, sys_nice( ) adds the value of increment to the nice field of current. If necessary, the value of this field is trimmed down so it won't be less than - 20 or greater than + 19.

The nice( ) system call is maintained for backward compatibility only; it has been replaced by the setpriority( ) system call described next.

11.3.2 The getpriority( ) and setpriority( ) System Calls

The nice( ) system call affects only the process that invokes it. Two other system calls, denoted as getpriority( ) and setpriority( ), act on the base priorities of all

processes in a given group. getpriority( ) returns 20 minus the lowest nice field value among all processes in a given group—that is, the highest priority among that processes; setpriority( ) sets the base priority of all processes in a given group to a given value.

The kernel implements these system calls by means of the sys_getpriority( ) and

sys_setpriority( ) service routines. Both of them act essentially on the same group of parameters:

which

The value that identifies the group of processes; it can assume one of the following: PRIO_PROCESS

Selects the processes according to their process ID (pid field of the process descriptor).

PRIO_PGRP

Selects the processes according to their group ID (pgrp field of the process descriptor).

PRIO_USER

Selects the processes according to their user ID (uid field of the process descriptor).

who

The value of the pid, pgrp, or uid field (depending on the value of which) to be used for selecting the processes. If who is 0, its value is set to that of the

corresponding field of the current process.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.