Python: OS Module

Source: Internet
Author: User

For an introduction to the OS module, see Python: OS module -- Introduction

OS module file and directory operations Python: OS module-file and directory operations

OS module Process Management Python: OS module-Process Management

 

The Python OS module provides process parameter settings, including the running environment and running permissions of processes.

Through the interfaces provided by the Python OS module, you can modify the environment variables, permission settings, user IDs, user group IDs, process IDs, and process group IDs of processes during execution, the modification and acquisition of the additional group ID and the session ID of the process are all necessary conditions for System Programming Using python.

The following is an introduction to the interfaces provided by these OS modules (Unix platforms only ):

 

 

Environment variables are related to the running behaviors of a process. environment variables control the running environment of the process. The Python OS module provides the ability to obtain and modify environment variables.

OS.Environ

A mapping object used to store environment variables and corresponding values. This mapping object is loaded when the OS module is imported. If the environment variable is modified afterwards, the mapping object is not reflected unless it is directly modified through OS. environ.

 

OS.Getenv (varname [, value])

If the environment variable is varname, this value is returned. Otherwise, the passed value is returned. If the value is not specified, None is returned.

 

OS.Putenv (varname, value)

The child process created by using repeated cv.

 

OS.Unsetenv (varname)

Delete an environment variable varname, which affects the running environment of the created sub-process.

Similarly, when the OS. if unsetenv () is supported, delete the OS directly. the environment variable in environ is converted to the unsetenv () call for the operation, but the direct call of unsetenv () is not to update the OS. so modify the OS. an Effective Method for environ is to directly modify the mapping object.

 

 

OS.Getegid ()

Returns the valid user group ID of the current process.

 

OS.Geteuid ()

Returns the valid user ID of the current process.

 

OS.Getuid ()

Returns the user ID of the current process.

 

OS.Getgid ()

Returns the ID of the user group of the current process.

 

OS.Getgroups ()

Returns the list of group IDs appended to the current process.

 

OS.Getresuid ()

Returns a tuple (ruid, euid, suid), indicating the actual user ID, valid user ID, and saved user ID of the current process.

 

OS.Getresgid ()

Returns a tuple (rgid, egid, sgid), indicating the actual user group ID of the current process, valid user group ID, and saved user group ID.

 

OS.Setegid (egid)

Set the valid user group ID of the current process

 

OS.Seteuid (euid)

Set the valid user ID of the current process

 

OS.Setgroups (groups)

Set the additional group ID related to the current process. The groups parameter must be a sequence type, and each parameter must be a group ID represented by an integer. This operation is only valid for Super Users.

 

OS.Setpgid (pid, pgrp)

Set the user group ID of the process. If the process ID is pid, the Process Group ID is pgrp.

 

OS.Setregid (rgid, egid)

Set valid user group ID and actual user group ID for the current process

 

OS.Setresgid (rgid, egid, sgid)

Set the actual group ID of the current process, valid group ID and saved user group ID.

 

OS.Setresuid (ruid, euid, suid)

Set the actual user ID of the current process, valid user ID, and saved user group ID.

 

OS.Setreuid (ruid, euid)

Set the actual user ID and valid user ID of the current process

 

 

OS.Getpgid (pid)

The ID of the process group whose process ID is pid is returned. If pid is set to 0, the ID of the Process Group of the currently called process is returned.

 

OS.Getpgrp ()

Returns the ID of the Process Group of the current process.

 

OS.Getpid ()

Returns the process ID of the current process.

 

OS.Getppid ()

Returns the ID of the parent process of the current process.

 

OS.Getsid (pid)

Returns the session ID of the process whose ID is pid.

 

OS.Setsid ()

Sets the session ID of the current process.

 

OS.Setuid (uid)

Set the user ID of the current process

 

 

OS.Ctermid ()

Return the control terminal of the current process

 

OS.Getlogin ()

Returns the username used to log on to the system.

 

OS.Strerror (code)

Returns the error message corresponding to the error code. If the error message is unknown, a ValueError exception is thrown.

 

OS.Umask (mask)

Sets the permission mask of the current process and returns the permission mask before the setting.

 

OS.Uname ()

Returns a 5-tuple that includes information about the current operating system. The 5-tuples include: (sysname, nodename, release, version, and machine ).

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.