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
相關用法
- 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_min() method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。