Section 14.8. Miscellaneous Operating System Interface


14.8. Miscellaneous Operating System Interface

In this chapter, we have seen various ways to interact with your operating system (OS) via the os module. Most of the functions we looked at dealt with either files or external process execution. There are a few more that allow for more specific actions for the current user and process, and we will look at them briefly here. Most of the functions described in Table 14.8 work on POSIX systems only, unless also denoted for Windows environment.

Table 14.8. Various os Module Attributes ( Also available for Win32)

os Module Attribute

Description

uname()

Obtains system information (hostname, operating system version, patch level, system architecture, etc.)

getuid()/setuid(uid)

Gets/sets the real user ID of the current process

getpid()/getppid()

Gets real process ID (PID) of current/parent process

getgid()/setgid(gid)

Gets/sets real group ID (GID) of current process

getsid()/setsid()

Gets session ID (SID) or create and return a new one

umask(mask)

Sets the current numeric umask while returning the previous one (mask is used for file permissions)

getenv(ev)/putenv(ev, value), environ

Gets/sets value of environment variable ev; the attribute os.environ is a dictionary representing all current environment variables

geteuid()/setegid()

Gets/sets effective user ID (UID) of current process

getegid()/setegid()

Gets/sets effective group ID (GID) of current process

getpgid(pid)/setpgid(pid, pgrp)

Gets/sets process GID process pid; for get, if pid is 0, the process GID of the current process is returned

getlogin()

Returns login of user running current process

times()

Returns tuple of various process times

strerror(code)

Returns error message corresponding to error code

getloadavg()[a]

Returns tuple of values representing the system load average during the past 1, 5, and 15 minutes


[a] New in Python 2.3.



Core Python Programming
Core Python Programming (2nd Edition)
ISBN: 0132269937
EAN: 2147483647
Year: 2004
Pages: 334
Authors: Wesley J Chun

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net