1.\" $NetBSD: getpriority.2,v 1.8 1999/12/02 21:42:37 kleink 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 <sys/time.h> 47.Fd #include <sys/resource.h> 48.Ft int 49.Fn getpriority "int which" "int who" 50.Ft int 51.Fn setpriority "int which" "int who" "int prio" 52.Sh DESCRIPTION 53The scheduling 54priority of the process, process group, or user, as indicated by 55.Fa which 56and 57.Fa who 58is obtained with the 59.Fn getpriority 60call and set with the 61.Fn setpriority 62call. 63.Fa which 64is one of 65.Dv PRIO_PROCESS , 66.Dv PRIO_PGRP , 67or 68.Dv PRIO_USER , 69and 70.Fa who 71is interpreted relative to 72.Fa which 73(a process identifier for 74.Dv PRIO_PROCESS , 75process group 76identifier for 77.Dv PRIO_PGRP , 78and a user ID for 79.Dv PRIO_USER ) . 80A zero value of 81.Fa who 82denotes the current process, process group, or user. 83.Fa prio 84is a value in the range -20 to 20. The default priority is 0; 85lower priorities cause more favorable scheduling. A value of 19 or 20 86will schedule a process only when nothing at priority \*(Le 0 is runnable. 87.Pp 88The 89.Fn getpriority 90call returns the highest priority (lowest numerical value) 91enjoyed by any of the specified processes. The 92.Fn setpriority 93call sets the priorities of all of the specified processes 94to the specified value. Only the super-user may lower priorities. 95.Sh RETURN VALUES 96Since 97.Fn getpriority 98can legitimately return the value -1, it is necessary 99to clear the external variable 100.Va errno 101prior to the 102call, then check it afterward to determine 103if a -1 is an error or a legitimate value. 104The 105.Fn setpriority 106call returns 0 if there is no error, or 107-1 if there is. 108.Sh ERRORS 109.Fn getpriority 110and 111.Fn setpriority 112will fail if: 113.Bl -tag -width Er 114.It Bq Er ESRCH 115No process was located using the 116.Fa which 117and 118.Fa who 119values specified. 120.It Bq Er EINVAL 121.Fa which 122was not one of 123.Dv PRIO_PROCESS , 124.Dv PRIO_PGRP , 125or 126.Dv PRIO_USER . 127.El 128.Pp 129.Bl -tag -width Er 130In addition to the errors indicated above, 131.Fn setpriority 132will fail if: 133.It Bq Er EPERM 134A process was located, but neither its effective nor real user 135ID matched the effective user ID of the caller. 136.It Bq Er EACCES 137A non super-user attempted to lower a process priority. 138.El 139.Sh SEE ALSO 140.Xr nice 1 , 141.Xr fork 2 , 142.Xr renice 8 143.Sh HISTORY 144The 145.Fn getpriority 146function call appeared in 147.Bx 4.2 . 148