getpriority(2) System Calls Manual getpriority(2) getpriority, setpriority - / LIBRARY Standard C library (libc, -lc) #include int getpriority(int which, id_t who); int setpriority(int which, id_t who, int prio); getpriority() (scheduling priority) , , which who, setpriority() . ( <>), nice(2). which : PRIO_PROCESS, PRIO_PGRP PRIO_USER, who which ( , PRIO_PROCESS; , PRIO_PGRP; , PRIO_USER). who () , . prio -- -20 19 ( ), -20 , 19 -- . . 0; . getpriority() ( ) . setpriority() . , (. ., ). Linux 2.6.12 , RLIMIT_NICE; getrlimit(2). On success, getpriority() returns the calling thread's nice value, which may be a negative number. On error, it returns -1 and sets errno to indicate the error. Since a successful call to getpriority() can legitimately return the value -1, it is necessary to clear errno prior to the call, then check errno afterward to determine if -1 is an error or a legitimate value. setpriority() returns 0 on success. On failure, it returns -1 and sets errno to indicate the error. EACCES ( ), ( Linux: CAP_SYS_NICE). EINVAL which PRIO_PROCESS, PRIO_PGRP PRIO_USER. EPERM , ( ) ( Linux: CAP_SYS_NICE). . ESRCH , which who. POSIX.1-2008. POSIX.1-2001, SVr4, 4.4BSD (these interfaces first appeared in 4.2BSD). sched(7). : <> Linux 2.6.38 , . sched(7). , fork(2), nice . execve(2) nice . The details on the condition for EPERM depend on the system. The above description is what POSIX.1-2001 says, and seems to be followed on all System V-like systems. Linux kernels before Linux 2.6.12 required the real or effective user ID of the caller to match the real user of the process who (instead of its effective user ID). Linux 2.6.12 and later require the effective user ID of the caller to match the real or effective user ID of the process who. All BSD-like systems (SunOS 4.1.3, Ultrix 4.2, 4.3BSD, FreeBSD 4.3, OpenBSD-2.5, ...) behave in the same manner as Linux 2.6.12 and later. C The getpriority system call returns nice values translated to the range 40..1, since a negative return value would be interpreted as an error. The glibc wrapper function for getpriority() translates the value back according to the formula unice = 20 - knice (thus, the 40..1 range returned by the kernel corresponds to the range -20..19 as seen by user space). POSIX, nice -- . Linux/NPTL POSIX nice -- : nice. Linux, . . nice(1), renice(1), fork(2), capabilities(7), sched(7) Documentation/scheduler/sched-nice-design.txt Linux ( Linux 2.6.23) Azamat Hackimov , Dmitry Bolkhovskikh , Vladislav , Yuri Kozlov ; GNU 3 , . . , , . Linux man-pages 6.06 31 2023 . getpriority(2)