Go to the previous, next section.
When several processes try to run, their respective priorities determine what share of the CPU each process gets. This section describes how you can read and set the priority of a process. All these functions and macros are declared in `sys/resource.h'.
The range of valid priority values depends on the operating system, but
typically it runs from -20 to 20. A lower priority value
means the process runs more often. These constants describe the range of
priority values:
Function: int getpriority (int class, int id)
Read the priority of a class of processes; class and id specify which ones (see below).
The return value is the priority value on success, and -1 on
failure. The following errno error condition are possible for
this function:
ESRCH
EINVAL
When the return value is -1, it could indicate failure, or it
could be the priority 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.
Function: int setpriority (int class, int id, int priority)
Read the priority of a class of processes; class and id specify which ones (see below).
The return value is 0 on success and -1 on failure. The
following errno error condition are defined for this function:
ESRCH
EINVAL
EPERM
EACCES
The arguments class and id together specify a set of processes you are interested in. These are the possible values for class:
PRIO_PROCESS
PRIO_PGRP
PRIO_USER
If the argument id is 0, it stands for the current process, current process group, or the current user, according to class.
Function: int nice (int increment)
Increment the priority of the current process by increment. The return value is not meaningful.
Here is an equivalent definition for nice:
int
nice (int increment)
{
int old = getpriority (PRIO_PROCESS, 0);
setpriority (PRIO_PROCESS, 0, old + increment);
}
Go to the previous, next section.