Python 3.3+Linux · macOSosfunction
os.getpriority
os — signals and priority
Return the scheduling priority (nice) of a process/group/user. Availability: Unix.
Syntax
os.getpriority(...)
The first argument selects whose priority you want: PRIO_PROCESS, PRIO_PGRP or PRIO_USER; zero as the second argument means the current process, group or user. Values range from -20 (highest priority) to 19 (lowest). Unlike nice, it can read another process's priority.
Examples
import os
print(os.getpriority(os.PRIO_PROCESS, 0)) # → ? nice текущего процесса, обычно 0
print(os.getpriority(os.PRIO_PROCESS, os.getpid())) # → ? то же значение: who=0 означает «текущий процесс»
os.setpriority(os.PRIO_PROCESS, 0, 10) # → ? приоритет понижен; следующий getpriority вернёт 10
print(os.getpriority(os.PRIO_PGRP, 0)) # → ? наименьшее (самое приоритетное) nice во всей группе процессов
os.getpriority(os.PRIO_PROCESS, 999999) # → ProcessLookupError: процесса с таким PID нет
See also
Common errors
Open in the full glossarydocs.python.orgReport an inaccuracy