Node:Traditional Scheduling Functions, Previous:Traditional Scheduling Intro, Up:Traditional Scheduling
This section describes how you can read and set the nice value of a
process. All these symbols are declared in sys/resource.h
.
The function and macro names are defined by POSIX, and refer to "priority," but the functions actually have to do with nice values, as the terms are used both in the manual and POSIX.
The range of valid nice values depends on the kernel, but typically it
runs from -20
to 20
. A lower nice value corresponds to
higher priority for the process. These constants describe the range of
priority values:
PRIO_MIN
PRIO_MAX
int getpriority (int class, int id) | Function |
Return the nice value of a set of processes; class and id
specify which ones (see below). If the processes specified do not all
have the same nice value, this returns the lowest value that any of them
has.
On success, the return value is
If the return value is |
int setpriority (int class, int id, int niceval) | Function |
Set the nice value of a set of processes to niceval; class
and id specify which ones (see below).
The return value is
|
The arguments class and id together specify a set of processes in which you are interested. These are the possible values of class:
PRIO_PROCESS
PRIO_PGRP
PRIO_USER
If the argument id is 0, it stands for the calling process, its process group, or its owner (real uid), according to class.
int nice (int increment) | Function |
Increment the nice value of the calling process by increment.
The return value is the new nice value on success, and -1 on
failure. In the case of failure, errno will be set to the
same values as for setpriority .
Here is an equivalent definition of int nice (int increment) { int result, old = getpriority (PRIO_PROCESS, 0); result = setpriority (PRIO_PROCESS, 0, old + increment); if (result != -1) return old + increment; else return -1; } |