28.10.2021 Views

Python Tutorial ( PDFDrive )

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Parameters

• path -- This is the path for which owner id and group id need to be setup.

• uid -- This is Owner ID to be set for the file.

• gid -- This is Group ID to be set for the file.

Return Value

This method does not return any value.

Example

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

#!/usr/bin/python

import os, sys

# Assuming /tmp/foo.txt exists.

# To set owner ID 100 following has to be done.

os.chown("/tmp/foo.txt", 100, -1)

print "Changed ownership successfully!!"

Let us compile and run the above program, this will produce the following result:

Changed ownership successfully!!

os.chroot(path)

Description

The method chroot() changes the root directory of the current process to the given path.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/python

import os, sys

# To set the current root path to /tmp/user

TUTORIALS POINT

Simply Easy Learning

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!