Change language

Python | os.major () method

os.major() in Python is used to extract the major device number from the specified raw device number (usually the value of the st_dev attribute or st_rdev of the object & # 39; os.stat_result & # 39; returned by os.stat () ). ,

In Linux everything is file-based, some are regular files and some — special files. Special files can be found in the / dev directory. These special files are called device files. Character and block devices are the most common type of device file. These device files are represented by the Linux kernel as a pair of numbers (major device number and minor device number). 
The major device number indicates which driver is used to access the hardware. Each driver on the system has a unique major number, and all device files with the same major device number are controlled by the same driver. 
Whereas the sub device number is used by the driver to distinguish between the different hardware it controls. The minor device number tells the kernel the special characteristics of the device being accessed.

Syntax: os.major (device)

device : An integer value representing the raw device number

Return Type: This method returns an integer value which represents the device major number.

Code: using the os method .major () to extract the major device number from the raw device number.

# Python program to explain the os.major () method

# import of the os module

import os

# Receives ь raw device number
# file

device = os.stat ( "file.txt" ) .st_dev

# Print raw device number

print ( "Raw device number:" , device)

# Retrieve main number device
# from the above raw device number

major = os.major (device)

# Print main device number

print ( "Device major number:" , major)


 Raw device number: 2056 Device major number: 8 



Learn programming in R: courses


Best Python online courses for 2022


Best laptop for Fortnite


Best laptop for Excel


Best laptop for Solidworks


Best laptop for Roblox


Best computer for crypto mining


Best laptop for Sims 4


Latest questions


psycopg2: insert multiple rows with one query

12 answers


How to convert Nonetype to int or string?

12 answers


How to specify multiple return types using type-hints

12 answers


Javascript Error: IPython is not defined in JupyterLab

12 answers



Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method