[Previous] [Contents] [Next]

setpriority()

Set the program scheduling priority

Synopsis:

#include <sys/resource.h>

int setpriority( int which,
                 id_t who,
                 int priority );

Library:

libc

Description:

The setpriority() function sets the scheduling priority of a process, process group, or user.

Target processes are specified by the values of the which and who arguments. The which argument indicates how to interpret the who argument:

If which is: Then who is a:
PRIO_PROCESS Process ID
PRIO_PGRP Process group ID
PRIO_USER User ID

A 0 value for the who argument specifies the current process, process group, or user.

If more than one process is specified, setpriority() sets the priorities of all of the specified processes to the specified value.

The default priority is 0; negative priorities cause more favorable scheduling. While the range of valid priority values is [-20, 20], implementations may enforce more restrictive limits. If the value specified to setpriority() is less than the system's lowest supported priority value, the system's lowest supported value is used; if it is greater than the system's highest supported value, the system's highest supported value is used.

Only a process with appropriate privileges can raise its priority (that is, assign a lower numerical priority value).

Returns:

0
Success.
-1
An error occurred; errno is set.

Errors:

EACCES
A request was made to change the priority to a lower numeric value (that is, to a higher priority) and the current process doesn't have appropriate privileges.
EINVAL
The value of the which argument wasn't recognized, or the value of the who argument isn't a valid process ID, process group ID, or user ID.
EPERM
A process was located, but neither the real nor effective user ID of the executing process is the privileged user or match the effective user ID of the process whose priority is being changed.
ESRCH
No process could be located using the which and who values specified.

Classification:

Standard Unix

Safety:
Cancellation point No
Interrupt handler No
Signal handler Yes
Thread Yes

Caveats:

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

See also:

fork(), getpriority()

nice, renice in the Utilities reference


[Previous] [Contents] [Next]