Standards / Extensions | C or C++ | Dependencies |
---|---|---|
XPG4 |
both |
#define _XOPEN_SOURCE
#include <unistd.h>
int nice(int increment);
nice() adds the value of increment to the nice value of the calling process. A process's nice value is a nonnegative number for which a more positive value results in a lower CPU priority.
A maximum nice value of 2*{NZERO}-1 and a minimum value of zero are imposed by the system. Requests for values above or below these limits result in the nice value being set to the corresponding limit. Only a process with appropriate privileges can lower the nice value.
The changing of a process's nice value has the equivalent effect on a process's scheduling priority value, since they both represent the process's relative CPU priority. For example, increasing one's nice value to its maximum value of (2*NZERO)-1 has the equivalent effect of setting one's scheduling priority value to its maximum value (19), and will be reflected on the nice(), getpriority(), and setpriority() functions.
If successful, nice() return the new nice value minus (NZERO).
Because nice() can return the value -1 on successful completion, it is necessary to set the external variable errno to 0 before a call to nice(). If nice() returns -1, then errno can be checked to see if an error occurred or if the value is a legitimate nice value.