Python – os.chroot() method
Last Updated :
07 Jan, 2022
os.chroot() method in Python is used to change the root directory of the current process to path.
Syntax: os.chroot(path)
Parameters:
path: path to be set as root for the current process.
Returns: does not return any value.
Code #1:
Python3
import os, sys
os.chroot(" / Geeks / gfg")
print ("root path successfully changed.")
|
Output:
root path successfully changed.
Code #2:
Python3
def change_root_directory(path):
try :
os.chdir(path)
os.chroot(path)
except Exception as exc:
error = DaemonOSEnvironmentError("Unable to change root directory ({exc})". format (exc = exc))
raise error
change_root_directory(" / Geeks / gfg")
|
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...