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.fstat() method in Python is used to get the status of a file descriptor.
A file descriptor is small integer value that corresponds to a file that has been opened by the current process.
A File descriptor indicates a resource and act as handle to perform various lower level I/O operations like read, write, send etc.
For Example: Standard input is usually file descriptor with value 0, standard output is usually file descriptor with value 1 and standard error is usually file descriptor with value 2.
Further files opened by the current process will get the value 3, 4, 5 an so on.
os.fstat() method is equivalent to
fd: A file descriptor.
Return Type: This method returns a stat_result object of class os which represents the status of the given file descriptor.
The returned ‘stat_result’ object is a tuple which has following named attributes:
- st_mode: It represents file type and file mode bits (permissions).
- st_ino: It represents the inode number on Unix and the file index on Windows platform.
- st_dev: It represents the identifier of the device on which this file resides.
- st_nlink: It represents the number of hard links.
- st_uid: It represents the user identifier of the file owner.
- st_gid: It represents the group identifier of the file owner.
- st_size: It represents the size of the file in bytes.
- st_atime: It represents the time of most recent access. It is expressed in seconds.
- st_mtime: It represents the time of most recent content modification. It is expressed in seconds.
- st_ctime: It represents the time of most recent metadata change on Unix and creation time on Windows. It is expressed in seconds.
- st_atime_ns: It is same as st_atime but the time is expressed in nanoseconds as an integer.
- st_mtime_ns: It is same as st_mtime but the time is expressed in nanoseconds as an integer.
- st_ctime_ns: It is same as st_ctime but the time is expressed in nanoseconds as an integer.
- st_blocks: It represents the number of 512-byte blocks allocated for file.
- st_rdev: It represents the type of device, if an inode device.
- st_flags: It represents the user defined flags for file.
Note: Some attributes are platform dependent and are subject to availability.
Code: Use of os.fstat() method to get the status of a file descriptor
os.stat_result(st_mode=33188, st_ino=801111, st_dev=2056, st_nlink=1, st_uid=1000, st_gid=1000, st_size=6550, st_atime=1560377051, st_mtime=1560377051, st_ctime=1560377051)
- class method vs static method in Python
- Python | set() method
- Python | os.dup() method
- Python | next() method
- Python | os.rename() method
- Python | cmath.log() method
- Python | PyTorch tan() method
- Python | os.getcwdb() method
- Python | sympy RGS method
- Python | os.sendfile() method
- Python | os.fdatasync() method
- Python | sys.getswitchinterval() method
- Python | os.getgroups() method
- Python | os.sync() method
- Python | os.pipe2() method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.