Python | os.sync() method
Last Updated :
14 Aug, 2021
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.sync() method in Python is used to force write of everything to disk. This method allows a process to flush all dirty buffers to disk.
Difference between os.sync(), os.fsync(fd) and os.fdatasync(fd) method –
os.sync() method force write of everything to disk where as os.fsync(fd) method force write of file associated with the specified file descriptor fd and os.fdatasync(fd) method is similar to os.fsync() method but it does not force update of file’s metadata.
Note: This method is only available on Unix platforms.
Syntax: os.sync()
Parameter: No parameter is required.
Return type: This method does not return any value.
Code: Use of os.sync() method
Python3
import os
path1 = 'file.txt'
path2 = 'file2.txt'
path3 = 'file3.txt'
fd1 = os. open (path1, os.O_RDWR)
fd2 = os. open (path2, os.O_RDWR)
fd3 = os. open (path3, os.O_RDWR)
str = b "GeeksforGeeks"
os.write(fd1, str )
os.write(fd2, str )
os.write(fd3, str )
os.sync()
print ( "Force write everything committed successfully" )
os.close(fd1)
os.close(fd2)
os.close(fd3)
|
Output:
Force write of everything committed successfully
Reference: https://docs.python.org/3/library/os.html#os.sync
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...