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
On success, the return value is 0
. Otherwise, it is -1
and ERRNO
is set accordingly. The errno
values specific
to this function are:
ESRCH
EINVAL
If the return value is -1
, it could indicate failure, or it could
be the nice value. The only way to make certain is to set errno =
0
before calling getpriority
, then use errno != 0
afterward as the criterion for failure.
The return value is the nice value on success, and -1
on
failure. The following errno
error condition are possible for
this function:
ESRCH
EINVAL
EPERM
CAP_SYS_NICE
permission.
EACCES
CAP_SYS_NICE
permission.
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.
setpriority
.
Here is an equivalent definition of nice
:
int nice (int increment) { int old = getpriority (PRIO_PROCESS, 0); return setpriority (PRIO_PROCESS, 0, old + increment); }
Go to the first, previous, next, last section, table of contents.