Blame man2/getpriority.2

Packit 7cfc04
.\" Copyright (c) 1980, 1991 The Regents of the University of California.
Packit 7cfc04
.\" All rights reserved.
Packit 7cfc04
.\"
Packit 7cfc04
.\" %%%LICENSE_START(BSD_4_CLAUSE_UCB)
Packit 7cfc04
.\" Redistribution and use in source and binary forms, with or without
Packit 7cfc04
.\" modification, are permitted provided that the following conditions
Packit 7cfc04
.\" are met:
Packit 7cfc04
.\" 1. Redistributions of source code must retain the above copyright
Packit 7cfc04
.\"    notice, this list of conditions and the following disclaimer.
Packit 7cfc04
.\" 2. Redistributions in binary form must reproduce the above copyright
Packit 7cfc04
.\"    notice, this list of conditions and the following disclaimer in the
Packit 7cfc04
.\"    documentation and/or other materials provided with the distribution.
Packit 7cfc04
.\" 3. All advertising materials mentioning features or use of this software
Packit 7cfc04
.\"    must display the following acknowledgement:
Packit 7cfc04
.\"	This product includes software developed by the University of
Packit 7cfc04
.\"	California, Berkeley and its contributors.
Packit 7cfc04
.\" 4. Neither the name of the University nor the names of its contributors
Packit 7cfc04
.\"    may be used to endorse or promote products derived from this software
Packit 7cfc04
.\"    without specific prior written permission.
Packit 7cfc04
.\"
Packit 7cfc04
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
Packit 7cfc04
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Packit 7cfc04
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
Packit 7cfc04
.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
Packit 7cfc04
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Packit 7cfc04
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
Packit 7cfc04
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
Packit 7cfc04
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
Packit 7cfc04
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
Packit 7cfc04
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
Packit 7cfc04
.\" SUCH DAMAGE.
Packit 7cfc04
.\" %%%LICENSE_END
Packit 7cfc04
.\"
Packit 7cfc04
.\"     @(#)getpriority.2	6.9 (Berkeley) 3/10/91
Packit 7cfc04
.\"
Packit 7cfc04
.\" Modified 1993-07-24 by Rik Faith <faith@cs.unc.edu>
Packit 7cfc04
.\" Modified 1996-07-01 by Andries Brouwer <aeb@cwi.nl>
Packit 7cfc04
.\" Modified 1996-11-06 by Eric S. Raymond <esr@thyrsus.com>
Packit 7cfc04
.\" Modified 2001-10-21 by Michael Kerrisk <mtk.manpages@gmail.com>
Packit 7cfc04
.\"    Corrected statement under EPERM to clarify privileges required
Packit 7cfc04
.\" Modified 2002-06-21 by Michael Kerrisk <mtk.manpages@gmail.com>
Packit 7cfc04
.\"    Clarified meaning of 0 value for 'who' argument
Packit 7cfc04
.\" Modified 2004-05-27 by Michael Kerrisk <mtk.manpages@gmail.com>
Packit 7cfc04
.\"
Packit 7cfc04
.TH GETPRIORITY 2 2017-09-15 "Linux" "Linux Programmer's Manual"
Packit 7cfc04
.SH NAME
Packit 7cfc04
getpriority, setpriority \- get/set program scheduling priority
Packit 7cfc04
.SH SYNOPSIS
Packit 7cfc04
.B #include <sys/time.h>
Packit 7cfc04
.br
Packit 7cfc04
.B #include <sys/resource.h>
Packit 7cfc04
.PP
Packit 7cfc04
.BI "int getpriority(int " which ", id_t " who );
Packit 7cfc04
.br
Packit 7cfc04
.BI "int setpriority(int " which ", id_t " who ", int " prio );
Packit 7cfc04
.SH DESCRIPTION
Packit 7cfc04
The scheduling priority of the process, process group, or user, as
Packit 7cfc04
indicated by
Packit 7cfc04
.I which
Packit 7cfc04
and
Packit 7cfc04
.I who
Packit 7cfc04
is obtained with the
Packit 7cfc04
.BR getpriority ()
Packit 7cfc04
call and set with the
Packit 7cfc04
.BR setpriority ()
Packit 7cfc04
call.
Packit 7cfc04
The process attribute dealt with by these system calls is
Packit 7cfc04
the same attribute (also known as the "nice" value) that is dealt with by
Packit 7cfc04
.BR nice (2).
Packit 7cfc04
.PP
Packit 7cfc04
The value
Packit 7cfc04
.I which
Packit 7cfc04
is one of
Packit 7cfc04
.BR PRIO_PROCESS ,
Packit 7cfc04
.BR PRIO_PGRP ,
Packit 7cfc04
or
Packit 7cfc04
.BR PRIO_USER ,
Packit 7cfc04
and
Packit 7cfc04
.I who
Packit 7cfc04
is interpreted relative to
Packit 7cfc04
.I which
Packit 7cfc04
(a process identifier for
Packit 7cfc04
.BR PRIO_PROCESS ,
Packit 7cfc04
process group
Packit 7cfc04
identifier for
Packit 7cfc04
.BR PRIO_PGRP ,
Packit 7cfc04
and a user ID for
Packit 7cfc04
.BR PRIO_USER ).
Packit 7cfc04
A zero value for
Packit 7cfc04
.I who
Packit 7cfc04
denotes (respectively) the calling process, the process group of the
Packit 7cfc04
calling process, or the real user ID of the calling process.
Packit 7cfc04
.PP
Packit 7cfc04
The
Packit 7cfc04
.I prio
Packit 7cfc04
argument is a value in the range \-20 to 19 (but see NOTES below).
Packit 7cfc04
with \-20 being the highest priority and 19 being the lowest priority.
Packit 7cfc04
Attempts to set a priority outside this range
Packit 7cfc04
are silently clamped to the range.
Packit 7cfc04
The default priority is 0;
Packit 7cfc04
lower values give a process a higher scheduling priority.
Packit 7cfc04
.PP
Packit 7cfc04
The
Packit 7cfc04
.BR getpriority ()
Packit 7cfc04
call returns the highest priority (lowest numerical value)
Packit 7cfc04
enjoyed by any of the specified processes.
Packit 7cfc04
The
Packit 7cfc04
.BR setpriority ()
Packit 7cfc04
call sets the priorities of all of the specified processes
Packit 7cfc04
to the specified value.
Packit 7cfc04
.PP
Packit 7cfc04
Traditionally, only a privileged process could lower the nice value
Packit 7cfc04
(i.e., set a higher priority).
Packit 7cfc04
However, since Linux 2.6.12, an unprivileged process can decrease
Packit 7cfc04
the nice value of a target process that has a suitable
Packit 7cfc04
.BR RLIMIT_NICE
Packit 7cfc04
soft limit; see
Packit 7cfc04
.BR getrlimit (2)
Packit 7cfc04
for details.
Packit 7cfc04
.SH RETURN VALUE
Packit 7cfc04
On success,
Packit 7cfc04
.BR getpriority ()
Packit 7cfc04
returns the calling thread's nice value, which may be a negative number.
Packit 7cfc04
On error, it returns \-1 and sets
Packit 7cfc04
.I errno
Packit 7cfc04
to indicate the cause of the error.
Packit 7cfc04
Since a successful call to
Packit 7cfc04
.BR getpriority ()
Packit 7cfc04
can legitimately return the value \-1, it is necessary
Packit 7cfc04
to clear the external variable
Packit 7cfc04
.I errno
Packit 7cfc04
prior to the
Packit 7cfc04
call, then check it afterward to determine
Packit 7cfc04
if \-1 is an error or a legitimate value.
Packit 7cfc04
.PP
Packit 7cfc04
.BR setpriority ()
Packit 7cfc04
returns 0 on success.
Packit 7cfc04
On error, it returns \-1 and sets
Packit 7cfc04
.I errno
Packit 7cfc04
to indicate the cause of the error.
Packit 7cfc04
.SH ERRORS
Packit 7cfc04
.TP
Packit 7cfc04
.B EINVAL
Packit 7cfc04
.I which
Packit 7cfc04
was not one of
Packit 7cfc04
.BR PRIO_PROCESS ,
Packit 7cfc04
.BR PRIO_PGRP ,
Packit 7cfc04
or
Packit 7cfc04
.BR PRIO_USER .
Packit 7cfc04
.TP
Packit 7cfc04
.B ESRCH
Packit 7cfc04
No process was located using the
Packit 7cfc04
.I which
Packit 7cfc04
and
Packit 7cfc04
.I who
Packit 7cfc04
values specified.
Packit 7cfc04
.PP
Packit 7cfc04
In addition to the errors indicated above,
Packit 7cfc04
.BR setpriority ()
Packit 7cfc04
may fail if:
Packit 7cfc04
.TP
Packit 7cfc04
.B EACCES
Packit 7cfc04
The caller attempted to set a lower nice value
Packit 7cfc04
(i.e., a higher process priority), but did not
Packit 7cfc04
have the required privilege (on Linux: did not have the
Packit 7cfc04
.B CAP_SYS_NICE
Packit 7cfc04
capability).
Packit 7cfc04
.TP
Packit 7cfc04
.B EPERM
Packit 7cfc04
A process was located, but its effective user ID did not match
Packit 7cfc04
either the effective or the real user ID of the caller,
Packit 7cfc04
and was not privileged (on Linux: did not have the
Packit 7cfc04
.B CAP_SYS_NICE
Packit 7cfc04
capability).
Packit 7cfc04
But see NOTES below.
Packit 7cfc04
.SH CONFORMING TO
Packit 7cfc04
POSIX.1-2001, POSIX.1-2008,
Packit 7cfc04
SVr4, 4.4BSD (these interfaces first appeared in 4.2BSD).
Packit 7cfc04
.SH NOTES
Packit 7cfc04
For further details on the nice value, see
Packit 7cfc04
.BR sched (7).
Packit 7cfc04
.PP
Packit 7cfc04
.IR Note :
Packit 7cfc04
the addition of the "autogroup" feature in Linux 2.6.38 means that
Packit 7cfc04
the nice value no longer has its traditional effect in many circumstances.
Packit 7cfc04
For details, see
Packit 7cfc04
.BR sched (7).
Packit 7cfc04
.PP
Packit 7cfc04
A child created by
Packit 7cfc04
.BR fork (2)
Packit 7cfc04
inherits its parent's nice value.
Packit 7cfc04
The nice value is preserved across
Packit 7cfc04
.BR execve (2).
Packit 7cfc04
.PP
Packit 7cfc04
The details on the condition for
Packit 7cfc04
.B EPERM
Packit 7cfc04
depend on the system.
Packit 7cfc04
The above description is what POSIX.1-2001 says, and seems to be followed on
Packit 7cfc04
all System\ V-like systems.
Packit 7cfc04
Linux kernels before 2.6.12 required the real or
Packit 7cfc04
effective user ID of the caller to match
Packit 7cfc04
the real user of the process \fIwho\fP (instead of its effective user ID).
Packit 7cfc04
Linux 2.6.12 and later require
Packit 7cfc04
the effective user ID of the caller to match
Packit 7cfc04
the real or effective user ID of the process \fIwho\fP.
Packit 7cfc04
All BSD-like systems (SunOS 4.1.3, Ultrix 4.2,
Packit 7cfc04
4.3BSD, FreeBSD 4.3, OpenBSD-2.5, ...) behave in the same
Packit 7cfc04
manner as Linux 2.6.12 and later.
Packit 7cfc04
.PP
Packit 7cfc04
Including
Packit 7cfc04
.I <sys/time.h>
Packit 7cfc04
is not required these days, but increases portability.
Packit 7cfc04
(Indeed,
Packit 7cfc04
.I <sys/resource.h>
Packit 7cfc04
defines the
Packit 7cfc04
.I rusage
Packit 7cfc04
structure with fields of type
Packit 7cfc04
.I struct timeval
Packit 7cfc04
defined in
Packit 7cfc04
.IR <sys/time.h> .)
Packit 7cfc04
.\"
Packit 7cfc04
.SS C library/kernel differences
Packit 7cfc04
Within the kernel, nice values are actually represented
Packit 7cfc04
using the range 40..1
Packit 7cfc04
(since negative numbers are error codes) and these are the values
Packit 7cfc04
employed by the
Packit 7cfc04
.BR setpriority ()
Packit 7cfc04
and
Packit 7cfc04
.BR getpriority ()
Packit 7cfc04
system calls.
Packit 7cfc04
The glibc wrapper functions for these system calls handle the
Packit 7cfc04
translations between the user-land and kernel representations
Packit 7cfc04
of the nice value according to the formula
Packit 7cfc04
.IR "unice\ =\ 20\ \-\ knice" .
Packit 7cfc04
(Thus, the kernel's 40..1 range corresponds to the
Packit 7cfc04
range \-20..19 as seen by user space.)
Packit 7cfc04
.SH BUGS
Packit 7cfc04
According to POSIX, the nice value is a per-process setting.
Packit 7cfc04
However, under the current Linux/NPTL implementation of POSIX threads,
Packit 7cfc04
the nice value is a per-thread attribute:
Packit 7cfc04
different threads in the same process can have different nice values.
Packit 7cfc04
Portable applications should avoid relying on the Linux behavior,
Packit 7cfc04
which may be made standards conformant in the future.
Packit 7cfc04
.SH SEE ALSO
Packit 7cfc04
.BR nice (1),
Packit 7cfc04
.BR renice (1),
Packit 7cfc04
.BR fork (2),
Packit 7cfc04
.BR capabilities (7),
Packit 7cfc04
.BR sched (7)
Packit 7cfc04
.PP
Packit 7cfc04
.I Documentation/scheduler/sched-nice-design.txt
Packit 7cfc04
in the Linux kernel source tree (since Linux 2.6.23)
Packit 7cfc04
.SH COLOPHON
Packit 7cfc04
This page is part of release 4.15 of the Linux
Packit 7cfc04
.I man-pages
Packit 7cfc04
project.
Packit 7cfc04
A description of the project,
Packit 7cfc04
information about reporting bugs,
Packit 7cfc04
and the latest version of this page,
Packit 7cfc04
can be found at
Packit 7cfc04
\%https://www.kernel.org/doc/man\-pages/.