📜  Python| os.sched_get_priority_max() 方法

📅  最后修改于: 2022-05-13 01:55:45.110000             🧑  作者: Mango

Python| os.sched_get_priority_max() 方法

Python中的OS 模块提供了与操作系统交互的功能。操作系统属于 Python 的标准实用程序模块。该模块提供了一种使用操作系统相关功能的可移植方式。

OS 模块包含一些方法,这些方法为调度程序提供接口,并用于控制操作系统如何为进程分配 CPU 时间。
Python中的os.sched_get_priority_max()方法用于获取指定调度策略的最大优先级值。

注意:此方法仅在某些 UNIX 平台上可用。

代码:使用 os.sched_get_priority_max() 方法
# Python program to explain os.sched_get_priority_max() method  
  
# importing os module 
import os
  
  
print("Below are the maximum priority\
value for different scheduling policy")
  
# Get the maximum priority value for
# first In First Out scheduling policy
# os.SCHED_FIFO constant represents 
# first In First Out scheduling policy
priority_max = os.sched_get_priority_max(os.SCHED_FIFO)
print("First In First Out scheduling policy:", priority_max)
  
# Get the maximum priority value for
# round-robin scheduling policy
# os.SCHED_RR constant represents the
# round-robin scheduling policy
priority_max = os.sched_get_priority_max(os.SCHED_RR)
print("Round-robin scheduling policy:", priority_max)
  
  
# Get the maximum priority value for
# the default scheduling policy
# os.SCHED_OTHER constant represents the
# default scheduling policy.
priority_max = os.sched_get_priority_max(os.SCHED_OTHER)
print("Default scheduling policy.:", priority_max)
  
  
# Get the maximum priority value 
# for scheduling policy for extremely
# low priority background tasks
# os.SCHED_IDLE constant represents the
# scheduling policy for extremely low
# priority background tasks.
priority_max = os.sched_get_priority_max(os.SCHED_IDLE)
print("Scheduling policy for extremely\
 low priority background tasks:", priority_max)
  
  
# Get the maximum priority value 
# for scheduling policy for CPU-intensive
# processes that tries to preserve 
# interactivity on the rest of the computer.
# os.SCHED_BATCH represents the
# scheduling policy for CPU-intensive processes
# that tries to preserve interactivity
# on the rest of the computer
priority_max = os.sched_get_priority_max(os.SCHED_BATCH)
print("Scheduling policy for CPU-intensive processes:", priority_max)
输出:
Below are the maximum priority value for different scheduling policy
First In First Out scheduling policy: 99
Round-robin scheduling policy: 99
Default scheduling policy.: 0
Scheduling policy for extremely low priority background tasks: 0
Scheduling policy for CPU-intensive processes: 0

参考资料: https://docs。 Python.org/3/library/os.html#os.sched_get_priority_max