当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Python os.sched_get_priority_min()用法及代码示例


Python中的OS模块提供了与操作系统进行交互的函数。操作系统属于Python的标准实用程序模块。该模块提供了使用依赖于操作系统的函数的便携式方法。

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

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


用法: os.sched_get_priority_min(policy) 

参数:
policy需要最小优先级值的调度策略。
以下是可用作策略参数值的调度策略常量:

  • 操作系统SCHED_OTHER:它代表默认的调度策略。
  • 操作系统SCHED_BATCH:它代表CPU密集型进程的调度策略,该策略试图保留计算机其余部分的交互性。
  • 操作系统SCHED_IDLE:它表示优先级极低的后台任务的调度策略。
  • 操作系统SCHED_SPORADIC:它代表零星服务器程序的调度策略。
  • 操作系统SCHED_FIFO:表示先进先出调度策略。
  • os.SCHED_RR:表示round-robin调度策略。

返回类型:此方法返回一个整数值,该值表示指定的调度策略的最小优先级值。

代码:os.sched_get_priority_min()方法的使用
# Python program to explain os.sched_get_priority_min() method   
  
# importing os module  
import os 
  
print("Below are the minimum priority\ 
value for different scheduling policy")  
  
# Get the minimum priority value for 
# first In First Out scheduling policy 
# os.SCHED_FIFO constant represents  
# first In First Out scheduling policy 
priority_min = os.sched_get_priority_min(os.SCHED_FIFO) 
print("First In First Out scheduling policy:", priority_min) 
  
# Get the minimum priority value for 
# round-robin scheduling policy 
# os.SCHED_RR constant represents the 
# round-robin scheduling policy 
priority_min = os.sched_get_priority_min(os.SCHED_RR) 
print("Round-robin scheduling policy:", priority_min) 
  
  
# Get the minimum priority value for 
# the default scheduling policy 
# os.SCHED_OTHER constant represents the 
# default scheduling policy. 
priority_min = os.sched_get_priority_min(os.SCHED_OTHER) 
print("Default scheduling policy.:", priority_min) 
  
  
# Get the minimum 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_min = os.sched_get_priority_min(os.SCHED_IDLE) 
print("Scheduling policy for extremely\ 
low priority background tasks:", priority_min) 
  
  
# Get the minimum priority value  
# for scheduling policy for CPU-intensive 
# processes that tries to preserve  
# interactivity on the rest of the computer. 
# os.SCHED_BATCH constant represents the 
# scheduling policy CPU-intensive processes 
# that tries to preserve interactivity 
# on the rest of the computer. 
priority_min = os.sched_get_priority_min(os.SCHED_BATCH) 
print("Scheduling policy for CPU-intensive processes:", priority_min)
输出:
Below are the minimum priority value for different scheduling policy
First In First Out scheduling policy:1
Round-robin scheduling policy:1
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_min



相关用法


注:本文由纯净天空筛选整理自ihritik大神的英文原创作品 Python | os.sched_get_priority_min() method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。