# Python program to explain os.chroot() methodimport os, sys
# Set current root path to /Geeks/gfg
os.chroot("/Geeks/gfg")print("root path successfully changed.")
Python
输出:
root path successfully changed.
Python
示例2
# Function to Change root directory of the process.defchange_root_directory(path):try:
os.chdir(path)
os.chroot(path)exceptExceptionas exc:
error =DaemonOSEnvironmentError("Unable to change root directory ({exc})".format(exc = exc))raise error
# main function
change_root_directory("/Geeks/gfg")