Python中的OS模塊提供了與操作係統進行交互的函數。操作係統屬於Python的標準實用程序模塊。該模塊提供了使用依賴於操作係統的函數的便攜式方法。
操作係統模塊包含一些方法,這些方法為調度程序提供接口,並用於控製操作係統如何為進程分配CPU時間。
os.sched_get_priority_max()
Python中的方法用於獲取指定調度策略的最大優先級值。
注意:此方法僅在某些UNIX平台上可用。
用法: os.sched_get_priority_max(policy)
參數:
policy需要最大優先級值的調度策略。
以下是可用作策略參數值的調度策略常量:
- 操作係統SCHED_OTHER:它代表默認的調度策略。
- 操作係統SCHED_BATCH:它代表CPU密集型進程的調度策略,該策略試圖保留計算機其餘部分的交互性。
- 操作係統SCHED_IDLE:它表示優先級極低的後台任務的調度策略。
- 操作係統SCHED_SPORADIC:它代表零星服務器程序的調度策略。
- 操作係統SCHED_FIFO:表示先進先出調度策略。
- os.SCHED_RR:表示round-robin調度策略。
返回類型:此方法返回一個整數值,該整數值表示指定的調度策略的最大優先級值。
代碼: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
相關用法
- Python next()用法及代碼示例
- Python os.dup()用法及代碼示例
- Python set()用法及代碼示例
- Python Decimal max()用法及代碼示例
- Python PIL ImageOps.fit()用法及代碼示例
- Python os.rmdir()用法及代碼示例
- Python sympy.det()用法及代碼示例
- Python Decimal min()用法及代碼示例
- Python os.readlink()用法及代碼示例
- Python os.writev()用法及代碼示例
- Python os.readv()用法及代碼示例
- Python PIL RankFilter()用法及代碼示例
- Python os.rename()用法及代碼示例
- Python os.sendfile()用法及代碼示例
注:本文由純淨天空篩選整理自ihritik大神的英文原創作品 Python | os.sched_get_priority_max() method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。