1.\" $NetBSD: getpriority.2,v 1.11 2002/02/08 01:28:17 ross Exp $ 2.\" 3.\" Copyright (c) 1980, 1991, 1993 4.\" The Regents of the University of California. All rights reserved. 5.\" 6.\" Redistribution and use in source and binary forms, with or without 7.\" modification, are permitted provided that the following conditions 8.\" are met: 9.\" 1. Redistributions of source code must retain the above copyright 10.\" notice, this list of conditions and the following disclaimer. 11.\" 2. Redistributions in binary form must reproduce the above copyright 12.\" notice, this list of conditions and the following disclaimer in the 13.\" documentation and/or other materials provided with the distribution. 14.\" 3. All advertising materials mentioning features or use of this software 15.\" must display the following acknowledgement: 16.\" This product includes software developed by the University of 17.\" California, Berkeley and its contributors. 18.\" 4. Neither the name of the University nor the names of its contributors 19.\" may be used to endorse or promote products derived from this software 20.\" without specific prior written permission. 21.\" 22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32.\" SUCH DAMAGE. 33.\" 34.\" @(#)getpriority.2 8.1 (Berkeley) 6/4/93 35.\" 36.Dd June 4, 1993 37.Dt GETPRIORITY 2 38.Os 39.Sh NAME 40.Nm getpriority , 41.Nm setpriority 42.Nd get/set program scheduling priority 43.Sh LIBRARY 44.Lb libc 45.Sh SYNOPSIS 46.Fd #include \*[Lt]sys/resource.h\*[Gt] 47.Ft int 48.Fn getpriority "int which" "int who" 49.Ft int 50.Fn setpriority "int which" "int who" "int prio" 51.Sh DESCRIPTION 52The scheduling 53priority of the process, process group, or user, as indicated by 54.Fa which 55and 56.Fa who 57is obtained with the 58.Fn getpriority 59call and set with the 60.Fn setpriority 61call. 62.Fa which 63is one of 64.Dv PRIO_PROCESS , 65.Dv PRIO_PGRP , 66or 67.Dv PRIO_USER , 68and 69.Fa who 70is interpreted relative to 71.Fa which 72(a process identifier for 73.Dv PRIO_PROCESS , 74process group 75identifier for 76.Dv PRIO_PGRP , 77and a user ID for 78.Dv PRIO_USER ) . 79A zero value of 80.Fa who 81denotes the current process, process group, or user. 82.Fa prio 83is a value in the range -20 to 20. The default priority is 0; 84lower priorities cause more favorable scheduling. A value of 19 or 20 85will schedule a process only when nothing at priority \*(Le 0 is runnable. 86.Pp 87The 88.Fn getpriority 89call returns the highest priority (lowest numerical value) 90enjoyed by any of the specified processes. The 91.Fn setpriority 92call sets the priorities of all of the specified processes 93to the specified value. Only the super-user may lower priorities. 94.Sh RETURN VALUES 95Since 96.Fn getpriority 97can legitimately return the value -1, it is necessary 98to clear the external variable 99.Va errno 100prior to the 101call, then check it afterward to determine 102if a -1 is an error or a legitimate value. 103The 104.Fn setpriority 105call returns 0 if there is no error, or 106-1 if there is. 107.Sh ERRORS 108.Fn getpriority 109and 110.Fn setpriority 111will fail if: 112.Bl -tag -width Er 113.It Bq Er ESRCH 114No process was located using the 115.Fa which 116and 117.Fa who 118values specified. 119.It Bq Er EINVAL 120.Fa which 121was not one of 122.Dv PRIO_PROCESS , 123.Dv PRIO_PGRP , 124or 125.Dv PRIO_USER . 126.El 127.Pp 128.Bl -tag -width Er 129In addition to the errors indicated above, 130.Fn setpriority 131will fail if: 132.It Bq Er EPERM 133A process was located, but neither its effective nor real user 134ID matched the effective user ID of the caller. 135.It Bq Er EACCES 136A non super-user attempted to lower a process priority. 137.El 138.Sh SEE ALSO 139.Xr nice 1 , 140.Xr fork 2 , 141.Xr renice 8 142.Sh HISTORY 143The 144.Fn getpriority 145function call appeared in 146.Bx 4.2 . 147