Python os.sched_get_priority_max() - 用于获取指定调度策略的最大优先级值

Python os.sched_get_priority_max()

OS模块包含一些方法,这些方法为调度器提供一个接口,用于控制进程如何被操作系统分配CPU时间。

Python中的os.sched_get_priority_max()方法用于获取指定调度策略的最大优先级值

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

语法:os.sched_get_priority_max(policy)

参数:

policy需要选择优先级最高的调度策略。

下面是调度策略常量,可以用作策略参数值:

  • os.SCHED_OTHER:它表示默认的调度策略。
  • os.SCHED_BATCH:它表示cpu密集型进程的调度策略,这些进程试图保持计算机其余部分的交互性。
  • os.SCHED_IDLE:它表示非常低优先级后台任务的调度策略。
  • os. sched_散发性:它表示散发性服务器程序的调度策略。
  • os.SCHED_FIFO:它表示先进先出的调度策略。
  • os.SCHED_RR:它表示循环调度策略。

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

示例1

使用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

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程