Go to the first, previous, next, last section, table of contents.
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:
PRIO_MIN
PRIO_MAX
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.
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.
setpriority
.
Here is an equivalent definition for 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.