Python 3 - os.chroot() Method


Description

The method chroot() changes the root directory of the current process to the given path. Available on Unix like systems only. To use this method, you would need super user privilege.

Syntax

Following is the syntax for chroot() method −

os.chroot(path)

Parameters

path − This is the path which would be set as root for the current process.

Return Value

This method does not return any value.

Example

The following example shows the usage of chroot() method.

#!/usr/bin/python3
import os, sys

# To set the current root path to /tmp/user
os.chroot("/tmp/usr")

print ("Changed root path successfully!!")

Result

When we run the above program, it produces the following result −

Changed root path successfully!!
python_files_io.htm
Advertisements