Python os.sched_get_priority_min()
Python OS模块包含一些方法,这些方法为调度器提供一个接口,用于控制进程如何被操作系统分配CPU时间。
Python中的os.sched_get_priority_min()方法用于获取指定调度策略的最小优先级值。
注意:此方法仅在某些UNIX平台上可用。
语法:os.sched_get_priority_min(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_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