Open In App

Python | os.sched_get_priority_max() method

Last Updated : 25 Jun, 2019
Improve
Improve
Like Article
Like
Save
Share
Report

OS module in Python provides functions for interacting with the operating system. OS comes under Python’s standard utility modules. This module provides a portable way of using operating system dependent functionality.

OS module contains some methods which provides an interface to the scheduler and used to control how a process is allocated CPU time by the operating system.
os.sched_get_priority_max() method in Python is used to get the maximum priority value for the specified scheduling policy.

Note: This method is only available on some UNIX platforms.

Syntax: os.sched_get_priority_max(policy)

Parameter:
policy The scheduling policy whose maximum priority value is required.
Below are the scheduling policy constants that can be used as policy parameter value:

  • os.SCHED_OTHER: It represents the default scheduling policy.
  • os.SCHED_BATCH: It represents the scheduling policy for CPU-intensive processes that tries to preserve interactivity on the rest of the computer.
  • os.SCHED_IDLE: It represents the scheduling policy for extremely low priority background tasks.
  • os.SCHED_SPORADIC: It represents the scheduling policy for sporadic server programs.
  • os.SCHED_FIFO: It represents First In First Out scheduling policy.
  • os.SCHED_RR: It represents round-robin scheduling policy.

Return Type: This method returns an integer value which represents the maximum priority value for the specified scheduling policy.

Code: Use of os.sched_get_priority_max() method




# 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)


Output:

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

References: https://docs.python.org/3/library/os.html#os.sched_get_priority_max



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads