[Previous] [Contents] [Next]

getpriority()

Get the program scheduling priority

Synopsis:

#include <sys/resource.h>

int getpriority( int which,
                 id_t who );

Library:

libc

Description:

The getpriority() function obtains the current 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, getpriority() returns the highest priority (lowest numerical value) pertaining to any of the specified processes.

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.

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

Returns:

An integer in the range from -20 to 20, or -1 if an error occurred (errno is set).

Errors:

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.
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:

Because getpriority() can return the value -1 on successful completion, you should set errno to 0 before calling getpriority(). If getpriority() returns -1, check errno to see if an error occurred or if the value is a legitimate priority.

See also:

fork(), setpriority()

nice, renice in the Utilities reference


[Previous] [Contents] [Next]