IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
14.1.1 Process Parameters


14.1.1 Process Parameters

These functions and data items provide information and operate on the current process and user.

environ
A mapping object representing the string environment. For example, environ['HOME'] is the pathname of your home directory (on some platforms), and is equivalent to getenv("HOME") in C.

This mapping is captured the first time the os module is imported, typically during Python startup as part of processing site.py. Changes to the environment made after this time are not reflected in os.environ, except for changes made by modifying os.environ directly.

If the platform supports the putenv() function, this mapping may be used to modify the environment as well as query the environment. putenv() will be called automatically when the mapping is modified. Note: Calling putenv() directly does not change os.environ, so it's better to modify os.environ. Note: On some platforms, including FreeBSD and Mac OS X, setting environ may cause memory leaks. Refer to the system documentation for putenv().

If putenv() is not provided, a modified copy of this mapping may be passed to the appropriate process-creation functions to cause child processes to use a modified environment.

If the platform supports the unsetenv() function, you can delete items in this mapping to unset environment variables. unsetenv() will be called automatically when an item is deleted from os.environ.

chdir( path)
fchdir( fd)
getcwd( )
These functions are described in ``Files and Directories'' (section 14.1.4).

ctermid( )
Return the filename corresponding to the controlling terminal of the process. Availability: Unix.

getegid( )
Return the effective group id of the current process. This corresponds to the `set id' bit on the file being executed in the current process. Availability: Unix.

geteuid( )
Return the current process' effective user id. Availability: Unix.

getgid( )
Return the real group id of the current process. Availability: Unix.

getgroups( )
Return list of supplemental group ids associated with the current process. Availability: Unix.

getlogin( )
Return the name of the user logged in on the controlling terminal of the process. For most purposes, it is more useful to use the environment variable LOGNAME to find out who the user is, or pwd.getpwuid(os.getuid())[0] to get the login name of the currently effective user ID. Availability: Unix.

getpgid( pid)
Return the process group id of the process with process id pid. If pid is 0, the process group id of the current process is returned. Availability: Unix. New in version 2.3.

getpgrp( )
Return the id of the current process group. Availability: Unix.

getpid( )
Return the current process id. Availability: Unix, Windows.

getppid( )
Return the parent's process id. Availability: Unix.

getuid( )
Return the current process' user id. Availability: Unix.

getenv( varname[, value])
Return the value of the environment variable varname if it exists, or value if it doesn't. value defaults to None. Availability: most flavors of Unix, Windows.

putenv( varname, value)
Set the environment variable named varname to the string value. Such changes to the environment affect subprocesses started with os.system(), popen() or fork() and execv(). Availability: most flavors of Unix, Windows.

Note: On some platforms, including FreeBSD and Mac OS X, setting environ may cause memory leaks. Refer to the system documentation for putenv.

When putenv() is supported, assignments to items in os.environ are automatically translated into corresponding calls to putenv(); however, calls to putenv() don't update os.environ, so it is actually preferable to assign to items of os.environ.

setegid( egid)
Set the current process's effective group id. Availability: Unix.

seteuid( euid)
Set the current process's effective user id. Availability: Unix.

setgid( gid)
Set the current process' group id. Availability: Unix.

setgroups( groups)
Set the list of supplemental group ids associated with the current process to groups. groups must be a sequence, and each element must be an integer identifying a group. This operation is typical available only to the superuser. Availability: Unix. New in version 2.2.

setpgrp( )
Calls the system call setpgrp() or setpgrp(0, 0) depending on which version is implemented (if any). See the Unix manual for the semantics. Availability: Unix.

setpgid( pid, pgrp)
Calls the system call setpgid() to set the process group id of the process with id pid to the process group with id pgrp. See the Unix manual for the semantics. Availability: Unix.

setreuid( ruid, euid)
Set the current process's real and effective user ids. Availability: Unix.

setregid( rgid, egid)
Set the current process's real and effective group ids. Availability: Unix.

getsid( pid)
Calls the system call getsid(). See the Unix manual for the semantics. Availability: Unix. New in version 2.4.

setsid( )
Calls the system call setsid(). See the Unix manual for the semantics. Availability: Unix.

setuid( uid)
Set the current process' user id. Availability: Unix.

strerror( code)
Return the error message corresponding to the error code in code. Availability: Unix, Windows.

umask( mask)
Set the current numeric umask and returns the previous umask. Availability: Unix, Windows.

uname( )
Return a 5-tuple containing information identifying the current operating system. The tuple contains 5 strings: (sysname, nodename, release, version, machine). Some systems truncate the nodename to 8 characters or to the leading component; a better way to get the hostname is socket.gethostname() or even socket.gethostbyaddr(socket.gethostname()). Availability: recent flavors of Unix.

unsetenv( varname)
Unset (delete) the environment variable named varname. Such changes to the environment affect subprocesses started with os.system(), popen() or fork() and execv(). Availability: most flavors of Unix, Windows.

When unsetenv() is supported, deletion of items in os.environ is automatically translated into a corresponding call to unsetenv(); however, calls to unsetenv() don't update os.environ, so it is actually preferable to delete items of os.environ.

See About this document... for information on suggesting changes.