2004-11-03 13:51:07 +00:00
|
|
|
.\" Copyright (c) 1980, 1991 The Regents of the University of California.
|
|
|
|
.\" All rights reserved.
|
|
|
|
.\"
|
|
|
|
.\" Redistribution and use in source and binary forms, with or without
|
|
|
|
.\" modification, are permitted provided that the following conditions
|
|
|
|
.\" are met:
|
|
|
|
.\" 1. Redistributions of source code must retain the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer.
|
|
|
|
.\" 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer in the
|
|
|
|
.\" documentation and/or other materials provided with the distribution.
|
|
|
|
.\" 3. All advertising materials mentioning features or use of this software
|
|
|
|
.\" must display the following acknowledgement:
|
|
|
|
.\" This product includes software developed by the University of
|
|
|
|
.\" California, Berkeley and its contributors.
|
|
|
|
.\" 4. Neither the name of the University nor the names of its contributors
|
|
|
|
.\" may be used to endorse or promote products derived from this software
|
|
|
|
.\" without specific prior written permission.
|
|
|
|
.\"
|
|
|
|
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
.\" SUCH DAMAGE.
|
|
|
|
.\"
|
|
|
|
.\" @(#)getpriority.2 6.9 (Berkeley) 3/10/91
|
|
|
|
.\"
|
|
|
|
.\" Modified 1993-07-24 by Rik Faith <faith@cs.unc.edu>
|
|
|
|
.\" Modified 1996-07-01 by Andries Brouwer <aeb@cwi.nl>
|
|
|
|
.\" Modified 1996-11-06 by Eric S. Raymond <esr@thyrsus.com>
|
2007-09-20 06:52:22 +00:00
|
|
|
.\" Modified 2001-10-21 by Michael Kerrisk <mtk.manpages@gmail.com>
|
2004-11-03 13:51:07 +00:00
|
|
|
.\" Corrected statement under EPERM to clarify privileges required
|
2007-09-20 06:52:22 +00:00
|
|
|
.\" Modified 2002-06-21 by Michael Kerrisk <mtk.manpages@gmail.com>
|
2004-11-03 13:51:07 +00:00
|
|
|
.\" Clarified meaning of 0 value for 'who' argument
|
2007-09-20 06:52:22 +00:00
|
|
|
.\" Modified 2004-05-27 by Michael Kerrisk <mtk.manpages@gmail.com>
|
2004-11-03 13:51:07 +00:00
|
|
|
.\"
|
2008-10-09 08:19:08 +00:00
|
|
|
.\" FIXME Oct 2008: Denys Vlasenko is working on a PRIO_THREAD feature that
|
|
|
|
.\" is likely to get included in mainline; this will need to be documented.
|
|
|
|
.\"
|
2008-05-29 08:02:43 +00:00
|
|
|
.TH GETPRIORITY 2 2008-05-29 "Linux" "Linux Programmer's Manual"
|
2004-11-03 13:51:07 +00:00
|
|
|
.SH NAME
|
|
|
|
getpriority, setpriority \- get/set program scheduling priority
|
|
|
|
.SH SYNOPSIS
|
|
|
|
.B #include <sys/time.h>
|
|
|
|
.br
|
|
|
|
.B #include <sys/resource.h>
|
|
|
|
.sp
|
|
|
|
.BI "int getpriority(int " which ", int " who );
|
|
|
|
.br
|
|
|
|
.BI "int setpriority(int " which ", int " who ", int " prio );
|
|
|
|
.SH DESCRIPTION
|
|
|
|
The scheduling priority of the process, process group, or user, as
|
|
|
|
indicated by
|
|
|
|
.I which
|
|
|
|
and
|
|
|
|
.I who
|
|
|
|
is obtained with the
|
2005-10-19 06:54:38 +00:00
|
|
|
.BR getpriority ()
|
2004-11-03 13:51:07 +00:00
|
|
|
call and set with the
|
2005-10-19 06:54:38 +00:00
|
|
|
.BR setpriority ()
|
2004-11-03 13:51:07 +00:00
|
|
|
call.
|
|
|
|
|
|
|
|
The value
|
|
|
|
.I which
|
|
|
|
is one of
|
|
|
|
.BR PRIO_PROCESS ,
|
|
|
|
.BR PRIO_PGRP ,
|
|
|
|
or
|
|
|
|
.BR PRIO_USER ,
|
2007-04-12 22:42:49 +00:00
|
|
|
and
|
2004-11-03 13:51:07 +00:00
|
|
|
.I who
|
2007-04-12 22:42:49 +00:00
|
|
|
is interpreted relative to
|
2004-11-03 13:51:07 +00:00
|
|
|
.I which
|
|
|
|
(a process identifier for
|
|
|
|
.BR PRIO_PROCESS ,
|
|
|
|
process group
|
|
|
|
identifier for
|
|
|
|
.BR PRIO_PGRP ,
|
|
|
|
and a user ID for
|
|
|
|
.BR PRIO_USER ).
|
|
|
|
A zero value for
|
|
|
|
.I who
|
|
|
|
denotes (respectively) the calling process, the process group of the
|
|
|
|
calling process, or the real user ID of the calling process.
|
|
|
|
.I Prio
|
2005-06-23 13:33:14 +00:00
|
|
|
is a value in the range \-20 to 19 (but see the Notes below).
|
2004-11-03 13:51:07 +00:00
|
|
|
The default priority is 0;
|
|
|
|
lower priorities cause more favorable scheduling.
|
|
|
|
|
|
|
|
The
|
2005-10-19 06:54:38 +00:00
|
|
|
.BR getpriority ()
|
2004-11-03 13:51:07 +00:00
|
|
|
call returns the highest priority (lowest numerical value)
|
2007-04-12 22:42:49 +00:00
|
|
|
enjoyed by any of the specified processes.
|
|
|
|
The
|
2005-10-19 06:54:38 +00:00
|
|
|
.BR setpriority ()
|
2004-11-03 13:51:07 +00:00
|
|
|
call sets the priorities of all of the specified processes
|
2007-04-12 22:42:49 +00:00
|
|
|
to the specified value.
|
|
|
|
Only the superuser may lower priorities.
|
2004-11-03 13:51:07 +00:00
|
|
|
.SH "RETURN VALUE"
|
|
|
|
Since
|
2005-10-19 06:54:38 +00:00
|
|
|
.BR getpriority ()
|
2004-11-03 13:51:07 +00:00
|
|
|
can legitimately return the value \-1, it is necessary
|
|
|
|
to clear the external variable
|
|
|
|
.I errno
|
|
|
|
prior to the
|
Changes.old, clone.2, execve.2, fcntl.2, futex.2, getitimer.2, getpriority.2, mmap.2, mount.2, mprotect.2, sched_setscheduler.2, select_tut.2, setuid.2, sigaltstack.2, vfork.2, div.3, fenv.3, fmod.3, memchr.3, pthread_attr_setstackaddr.3, pthread_attr_setstacksize.3, pthread_getattr_np.3, queue.3, scanf.3, trunc.3, st.4, proc.5, services.5, utmp.5, bootparam.7, capabilities.7, feature_test_macros.7, futex.7, glob.7, man.7, netlink.7, unicode.7: Switch to American usage: "-wards" ==> "-ward"
American English uses "afterward" in preference to "afterwards",
and so on
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2010-09-26 05:34:47 +00:00
|
|
|
call, then check it afterward to determine
|
2008-07-12 11:01:09 +00:00
|
|
|
if \-1 is an error or a legitimate value.
|
2004-11-03 13:51:07 +00:00
|
|
|
The
|
2005-10-19 06:54:38 +00:00
|
|
|
.BR setpriority ()
|
2004-11-03 13:51:07 +00:00
|
|
|
call returns 0 if there is no error, or
|
|
|
|
\-1 if there is.
|
|
|
|
.SH ERRORS
|
|
|
|
.TP
|
|
|
|
.B EINVAL
|
|
|
|
.I which
|
|
|
|
was not one of
|
|
|
|
.BR PRIO_PROCESS ,
|
|
|
|
.BR PRIO_PGRP ,
|
|
|
|
or
|
|
|
|
.BR PRIO_USER .
|
|
|
|
.TP
|
|
|
|
.B ESRCH
|
2007-04-12 22:42:49 +00:00
|
|
|
No process was located using the
|
2004-11-03 13:51:07 +00:00
|
|
|
.I which
|
|
|
|
and
|
|
|
|
.I who
|
|
|
|
values specified.
|
|
|
|
.PP
|
|
|
|
In addition to the errors indicated above,
|
2005-10-19 06:54:38 +00:00
|
|
|
.BR setpriority ()
|
2004-11-03 13:51:07 +00:00
|
|
|
may fail if:
|
|
|
|
.TP
|
|
|
|
.B EACCES
|
2005-07-28 13:21:39 +00:00
|
|
|
The caller attempted to lower a process priority, but did not
|
|
|
|
have the required privilege (on Linux: did not have the
|
|
|
|
.B CAP_SYS_NICE
|
|
|
|
capability).
|
2005-09-19 14:57:58 +00:00
|
|
|
Since Linux 2.6.12, this error only occurs if the caller attempts
|
2007-04-12 22:42:49 +00:00
|
|
|
to set a process priority outside the range of the
|
2005-09-19 14:57:58 +00:00
|
|
|
.B RLIMIT_NICE
|
2005-09-20 17:45:12 +00:00
|
|
|
soft resource limit of the target process; see
|
2005-09-19 14:57:58 +00:00
|
|
|
.BR getrlimit (2)
|
|
|
|
for details.
|
2007-08-27 07:56:52 +00:00
|
|
|
.TP
|
|
|
|
.B EPERM
|
|
|
|
A process was located, but its effective user ID did not match
|
|
|
|
either the effective or the real user ID of the caller,
|
|
|
|
and was not privileged (on Linux: did not have the
|
|
|
|
.B CAP_SYS_NICE
|
|
|
|
capability).
|
|
|
|
But see NOTES below.
|
2007-05-18 16:06:42 +00:00
|
|
|
.SH "CONFORMING TO"
|
|
|
|
SVr4, 4.4BSD (these function calls first appeared in 4.2BSD),
|
|
|
|
POSIX.1-2001.
|
2004-11-03 13:51:07 +00:00
|
|
|
.SH NOTES
|
2006-07-22 14:10:33 +00:00
|
|
|
A child created by
|
|
|
|
.BR fork (2)
|
|
|
|
inherits its parent's nice value.
|
2007-04-12 22:42:49 +00:00
|
|
|
The nice value is preserved across
|
|
|
|
.BR execve (2).
|
2006-07-22 14:10:33 +00:00
|
|
|
|
2008-03-05 15:22:42 +00:00
|
|
|
The degree to which their relative nice value affects the scheduling of
|
intro.1, time.1, accept.2, bind.2, connect.2, execve.2, flock.2, getdents.2, getpriority.2, getuid.2, intro.2, ioctl.2, mincore.2, mknod.2, personality.2, ptrace.2, read.2, recv.2, select_tut.2, send.2, sendfile.2, shmctl.2, sigaction.2, signal.2, stat.2, times.2, truncate.2, umask.2, wait.2, MB_CUR_MAX.3, MB_LEN_MAX.3, argz_add.3, btowc.3, clearenv.3, clock.3, cmsg.3, end.3, endian.3, errno.3, exit.3, fgetwc.3, fgetws.3, fopen.3, fputwc.3, fputws.3, fseek.3, fwide.3, getfsent.3, getgrnam.3, gethostid.3, getipnodebyname.3, getmntent.3, getpwnam.3, getwchar.3, grantpt.3, iconv.3, iconv_close.3, iconv_open.3, insque.3, intro.3, iswalnum.3, iswalpha.3, iswblank.3, iswcntrl.3, iswctype.3, iswdigit.3, iswgraph.3, iswlower.3, iswprint.3, iswpunct.3, iswspace.3, iswupper.3, iswxdigit.3, malloc.3, mblen.3, mbrlen.3, mbrtowc.3, mbsinit.3, mbsnrtowcs.3, mbsrtowcs.3, mbstowcs.3, mbtowc.3, mkstemp.3, mktemp.3, nl_langinfo.3, openpty.3, posix_openpt.3, printf.3, ptsname.3, putwchar.3, qecvt.3, rcmd.3, readdir.3, rexec.3, rpc.3, setnetgrent.3, shm_open.3, sigpause.3, stdin.3, stpcpy.3, strftime.3, strptime.3, syslog.3, towctrans.3, towlower.3, towupper.3, ttyslot.3, ungetwc.3, unlocked_stdio.3, wcpcpy.3, wcpncpy.3, wcrtomb.3, wcscasecmp.3, wcscat.3, wcschr.3, wcscmp.3, wcscpy.3, wcscspn.3, wcsdup.3, wcslen.3, wcsncasecmp.3, wcsncat.3, wcsncmp.3, wcsncpy.3, wcsnlen.3, wcsnrtombs.3, wcspbrk.3, wcsrchr.3, wcsrtombs.3, wcsspn.3, wcsstr.3, wcstok.3, wcstombs.3, wcswidth.3, wctob.3, wctomb.3, wctrans.3, wctype.3, wcwidth.3, wmemchr.3, wmemcmp.3, wmemcpy.3, wmemmove.3, wmemset.3, wprintf.3, console_ioctl.4, pts.4, elf.5, filesystems.5, hosts.5, proc.5, ttytype.5, boot.7, capabilities.7, credentials.7, epoll.7, glob.7, koi8-r.7, path_resolution.7, pty.7, signal.7, suffixes.7, time.7, unicode.7, unix.7, uri.7, utf-8.7: global fix: s/Unix/UNIX/
The man pages were rather inconsistent in the use of "Unix"
versus "UNIX". Let's go with the trademark usage.
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2010-10-12 04:45:38 +00:00
|
|
|
processes varies across UNIX systems, and,
|
2008-03-05 15:22:42 +00:00
|
|
|
on Linux, across kernel versions.
|
|
|
|
Starting with kernel 2.6.23, Linux adopted an algorithm that causes
|
|
|
|
relative differences in nice values to have a much stronger effect.
|
|
|
|
This causes very low nice values (+19) to truly provide little CPU
|
|
|
|
to a process whenever there is any other
|
|
|
|
higher priority load on the system,
|
|
|
|
and makes high nice values (\-20) deliver most of the CPU to applications
|
|
|
|
that require it (e.g., some audio applications).
|
|
|
|
|
2007-06-22 17:16:20 +00:00
|
|
|
The details on the condition for
|
2007-09-20 16:26:31 +00:00
|
|
|
.B EPERM
|
2007-06-22 17:16:20 +00:00
|
|
|
depend on the system.
|
2006-08-03 13:57:17 +00:00
|
|
|
The above description is what POSIX.1-2001 says, and seems to be followed on
|
2006-01-13 09:44:53 +00:00
|
|
|
all System V-like systems.
|
2007-04-12 22:42:49 +00:00
|
|
|
Linux kernels before 2.6.12 required the real or
|
2005-09-20 17:45:12 +00:00
|
|
|
effective user ID of the caller to match
|
2004-11-03 13:51:07 +00:00
|
|
|
the real user of the process \fIwho\fP (instead of its effective user ID).
|
2005-09-20 17:45:12 +00:00
|
|
|
Linux 2.6.12 and later require
|
2004-11-03 13:51:07 +00:00
|
|
|
the effective user ID of the caller to match
|
|
|
|
the real or effective user ID of the process \fIwho\fP.
|
2005-09-20 17:45:12 +00:00
|
|
|
All BSD-like systems (SunOS 4.1.3, Ultrix 4.2,
|
2007-04-12 22:42:49 +00:00
|
|
|
4.3BSD, FreeBSD 4.3, OpenBSD-2.5, ...) behave in the same
|
2008-07-09 19:38:19 +00:00
|
|
|
manner as Linux 2.6.12 and later.
|
2004-11-03 13:51:07 +00:00
|
|
|
.LP
|
|
|
|
The actual priority range varies between kernel versions.
|
2005-07-28 13:21:39 +00:00
|
|
|
Linux before 1.3.36 had \-infinity..15.
|
2005-07-28 14:29:14 +00:00
|
|
|
Since kernel 1.3.43 Linux has the range \-20..19.
|
2005-07-28 13:21:39 +00:00
|
|
|
Within the kernel, nice values are actually represented
|
|
|
|
using the corresponding range 40..1
|
|
|
|
(since negative numbers are error codes) and these are the values
|
|
|
|
employed by the
|
2005-10-19 06:54:38 +00:00
|
|
|
.BR setpriority ()
|
2005-07-28 13:21:39 +00:00
|
|
|
and
|
2005-10-19 06:54:38 +00:00
|
|
|
.BR getpriority ()
|
2005-07-28 13:21:39 +00:00
|
|
|
system calls.
|
|
|
|
The glibc wrapper functions for these system calls handle the
|
|
|
|
translations between the user-land and kernel representations
|
|
|
|
of the nice value according to the formula
|
|
|
|
.IR "unice\ =\ 20\ \-\ knice" .
|
2004-11-03 13:51:07 +00:00
|
|
|
.LP
|
2005-06-23 13:36:09 +00:00
|
|
|
On some systems, the range of nice values is \-20..20.
|
|
|
|
.LP
|
2004-11-03 13:51:07 +00:00
|
|
|
Including
|
|
|
|
.I <sys/time.h>
|
|
|
|
is not required these days, but increases portability.
|
|
|
|
(Indeed,
|
|
|
|
.I <sys/resource.h>
|
|
|
|
defines the
|
|
|
|
.I rusage
|
|
|
|
structure with fields of type
|
|
|
|
.I struct timeval
|
|
|
|
defined in
|
|
|
|
.IR <sys/time.h> .)
|
|
|
|
.SH "SEE ALSO"
|
|
|
|
.BR nice (1),
|
|
|
|
.BR fork (2),
|
|
|
|
.BR capabilities (7),
|
2010-06-13 09:12:42 +00:00
|
|
|
.BR renice (1)
|
2008-03-05 15:22:42 +00:00
|
|
|
.sp
|
|
|
|
.I Documentation/scheduler/sched-nice-design.txt
|
2008-05-07 13:33:52 +00:00
|
|
|
in the kernel source tree (since Linux 2.6.23).
|