Open In App

Python - os.chroot() method

Last Updated : 07 Jan, 2022
Comments
Improve
Suggest changes
Like Article
Like
Report

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
# Python program to explain os.chroot() method

import os, sys

# Set current root path to /Geeks/gfg
os.chroot("/Geeks/gfg")
print ("root path successfully changed.")

Output: 
 

root path successfully changed.


  
Code #2:
 

Python3
# Function to Change root directory of the process.
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 

# main function
change_root_directory("/Geeks/gfg")

Next Article
Article Tags :
Practice Tags :

Similar Reads

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy