The Single UNIX ® Specification, Version 2
Copyright © 1997 The Open Group

 NAME

getpriority, setpriority - get or set the nice value

 SYNOPSIS



#include <sys/resource.h>

int getpriority(int which, id_t who);
int setpriority(int which, id_t who, int value);

 DESCRIPTION

The getpriority() function obtains the nice value of a process, process group or user. The setpriority() function sets the nice value of a process, process group or user to value + NZERO.

Target processes are specified by the values of the which and who arguments. The which argument may be one of the following values: PRIO_PROCESS, PRIO_PGRP or PRIO_USER, indicating that the who argument is to be interpreted as a process ID, a process group ID or an effective user ID, respectively. A 0 value for the who argument specifies the current process, process group or user.

The nice value set with setpriority() is applied to the process. If the process is multi-threaded, the nice value affects all system scope threads in the process.

If more than one process is specified, getpriority() returns value NZERO less than the lowest nice value pertaining to any of the specified processes, and setpriority() sets the nice values of all of the specified processes to value + NZERO.

The default nice value is NZERO; lower nice values cause more favourable scheduling. While the range of valid nice values is [0, NZERO*2 -1], implementations may enforce more restrictive limits. If value + NZERO is less than the system's lowest supported nice value, setpriority() sets the nice value to the lowest supported value; if value + NZERO is greater than the system's highest supported nice value, setpriority() sets the nice value to the highest supported value.

Only a process with appropriate privileges can lower its nice value.

Any processes or threads using SCHED_FIFO or SCHED_RR are unaffected by a call to setpriority(). This is not considered an error.

The effect of changing the nice value may vary depending on the process-scheduling algorithm in effect.

Because getpriority() can return the value -1 on successful completion, it is necessary to set errno to 0 prior to a call to getpriority(). If getpriority() returns the value -1, then errno can be checked to see if an error occurred or if the value is a legitimate nice value.

 RETURN VALUE

Upon successful completion, getpriority() returns an integer in the range from -NZERO to NZERO-1. Otherwise, -1 is returned and errno is set to indicate the error.

Upon successful completion, setpriority() returns 0. Otherwise, -1 is returned and errno is set to indicate the error.

 ERRORS

The getpriority() and setpriority() functions will fail if:
[ESRCH]
No process could be located using the which and who argument values specified.
[EINVAL]
The value of the which argument was not recognised, or the value of the who argument is not a valid process ID, process group ID or user ID.

In addition, setpriority() may fail if:

[EPERM]
A process was located, but neither the real nor effective user ID of the executing process match the effective user ID of the process whose nice value is being changed.
[EACCES]
A request was made to change the nice value to a lower numeric value and the current process does not have appropriate privileges.

 EXAMPLES

None.

 APPLICATION USAGE

The getpriority() and setpriority() functions work with an offset nice value (nice value minus NZERO). The nice value is in the range [0, 2*NZERO -1], while the return value for getpriority() and the third parameter for setpriority() are in the range [-NZERO, NZERO -1].

 FUTURE DIRECTIONS

None.

 SEE ALSO

nice(), sched_get_priority_max(), sched_setscheduler(), <sys/resource.h>.

UNIX ® is a registered Trademark of The Open Group.
Copyright © 1997 The Open Group
[ Main Index | XSH | XCU | XBD | XCURSES | XNS ]