Built-in Module posix

posix

This module provides access to operating system functionality that is standardized by the C Standard and the POSIX standard (a thinly diguised interface). It is available in all Python versions except on the Macintosh; the MS-DOS version does not support certain functions. The descriptions below are very terse; refer to the corresponding manual entry for more information.

Errors are reported as exceptions; the usual exceptions are given for type errors, while errors reported by the system calls raise posix.error, described below.

Module posix defines the following data items:


\begin{datadesc}{environ}
A dictionary representing the string environment at th...
... your home directory, equivalent to
\code{getenv(''HOME'')}
in C.
\end{datadesc}


\begin{excdesc}{error}
This exception is raised when an POSIX function returns a...
...ing string, as would be printed by the C function
\code{perror()}.
\end{excdesc}

It defines the following functions:


\begin{funcdesc}{chdir}{path}
Change the current working directory to \var{path}.
\end{funcdesc}


\begin{funcdesc}{chmod}{path\, mode}
Change the mode of \var{path} to the numeric \var{mode}.
\end{funcdesc}


\begin{funcdesc}{close}{fd}
Close file descriptor \var{fd}.
\end{funcdesc}


\begin{funcdesc}{dup}{fd}
Return a duplicate of file descriptor \var{fd}.
\end{funcdesc}


\begin{funcdesc}{dup2}{fd\, fd2}
Duplicate file descriptor \var{fd} to \var{fd2}, closing the latter
first if necessary. Return \code{None}.
\end{funcdesc}


\begin{funcdesc}{execv}{path\, args}
Execute the executable \var{path} with argu...
...argument list may be a tuple or list of strings.
(Not on MS-DOS.)
\end{funcdesc}


\begin{funcdesc}{execve}{path\, args\, env}
Execute the executable \var{path} wi...
...must be a dictionary mapping strings to strings.
(Not on MS-DOS.)
\end{funcdesc}


\begin{funcdesc}{_exit}{n}
Exit to the system with status \var{n}, without calli...
...normally only be used in the child process
after a \code{fork()}.
\end{funcdesc}


\begin{funcdesc}{fdopen}{fd\, mode}
Return an open file object connected to the ...
...s the \var{mode} argument to the built-in
\code{open()} function.
\end{funcdesc}


\begin{funcdesc}{fork}{}
Fork a child process. Return 0 in the child, the child's process id
in the parent.
(Not on MS-DOS.)
\end{funcdesc}


\begin{funcdesc}{fstat}{fd}
Return status for file descriptor \var{fd}, like \code{stat()}.
\end{funcdesc}


\begin{funcdesc}{getcwd}{}
Return a string representing the current working directory.
\end{funcdesc}


\begin{funcdesc}{getegid}{}
Return the current process's effective group id.
(Not on MS-DOS.)
\end{funcdesc}


\begin{funcdesc}{geteuid}{}
Return the current process's effective user id.
(Not on MS-DOS.)
\end{funcdesc}


\begin{funcdesc}{getgid}{}
Return the current process's group id.
(Not on MS-DOS.)
\end{funcdesc}


\begin{funcdesc}{getpid}{}
Return the current process id.
(Not on MS-DOS.)
\end{funcdesc}


\begin{funcdesc}{getppid}{}
Return the parent's process id.
(Not on MS-DOS.)
\end{funcdesc}


\begin{funcdesc}{getuid}{}
Return the current process's user id.
(Not on MS-DOS.)
\end{funcdesc}


\begin{funcdesc}{kill}{pid\, sig}
Kill the process \var{pid} with signal \var{sig}.
(Not on MS-DOS.)
\end{funcdesc}


\begin{funcdesc}{link}{src\, dst}
Create a hard link pointing to \var{src} named \var{dst}.
(Not on MS-DOS.)
\end{funcdesc}


\begin{funcdesc}{listdir}{path}
Return a list containing the names of the entrie...
...
\code{'.'} and \code{'..'} if they are present in the directory.
\end{funcdesc}


\begin{funcdesc}{lseek}{fd\, pos\, how}
Set the current position of file descrip...
...he current
position; 2 to set it relative to the end of the file.
\end{funcdesc}


\begin{funcdesc}{lstat}{path}
Like \code{stat()}, but do not follow symbolic lin...
...
without symbolic links, this is identical to \code{posix.stat}.)
\end{funcdesc}


\begin{funcdesc}{mkdir}{path\, mode}
Create a directory named \var{path} with numeric mode \var{mode}.
\end{funcdesc}


\begin{funcdesc}{nice}{increment}
Add \var{incr} to the process' \lq\lq niceness''. Return the new niceness.
(Not on MS-DOS.)
\end{funcdesc}


\begin{funcdesc}{open}{file\, flags\, mode}
Open the file \var{file} and set var...
...\var{mode}.
Return the file descriptor for the newly opened file.
\end{funcdesc}


\begin{funcdesc}{pipe}{}
Create a pipe. Return a pair of file descriptors \code{...
...)}
usable for reading and writing, respectively.
(Not on MS-DOS.)
\end{funcdesc}


\begin{funcdesc}{popen}{command\, mode}
Open a pipe to or from \var{command}. Th...
... whether \var{mode} is \code{'r'} or \code{'w'}.
(Not on MS-DOS.)
\end{funcdesc}


\begin{funcdesc}{read}{fd\, n}
Read at most \var{n} bytes from file descriptor \var{fd}.
Return a string containing the bytes read.
\end{funcdesc}


\begin{funcdesc}{readlink}{path}
Return a string representing the path to which ...
...s without symbolic links, this always raises
\code{posix.error}.)
\end{funcdesc}


\begin{funcdesc}{rename}{src\, dst}
Rename the file or directory \var{src} to \var{dst}.
\end{funcdesc}


\begin{funcdesc}{rmdir}{path}
Remove the directory \var{path}.
\end{funcdesc}


\begin{funcdesc}{setgid}{gid}
Set the current process's group id.
(Not on MS-DOS.)
\end{funcdesc}


\begin{funcdesc}{setuid}{uid}
Set the current process's user id.
(Not on MS-DOS.)
\end{funcdesc}


\begin{funcdesc}{stat}{path}
Perform a {\em stat} system call on the given path....
...that are useful for extracting information from a stat structure.
\end{funcdesc}


\begin{funcdesc}{symlink}{src\, dst}
Create a symbolic link pointing to \var{src...
...s without symbolic links, this always raises
\code{posix.error}.)
\end{funcdesc}


\begin{funcdesc}{system}{command}
Execute the command (a string) in a subshell. ...
... status of the process as returned by Standard C
\code{system()}.
\end{funcdesc}


\begin{funcdesc}{times}{}
Return a 4-tuple of floating point numbers indicating ...
...der. See the \UNIX{}
manual page {\it times}(2). (Not on MS-DOS.)
\end{funcdesc}


\begin{funcdesc}{umask}{mask}
Set the current numeric umask and returns the previous umask.
(Not on MS-DOS.)
\end{funcdesc}


\begin{funcdesc}{uname}{}
Return a 5-tuple containing information identifying th...
...et.gethostname()}. (Not on MS-DOS, nor on older
\UNIX{} systems.)
\end{funcdesc}


\begin{funcdesc}{unlink}{path}
Unlink \var{path}.
\end{funcdesc}


\begin{funcdesc}{utime}{path\, \(atime\, mtime\)}
Set the access and modified ti...
... the given values.
(The second argument is a tuple of two items.)
\end{funcdesc}


\begin{funcdesc}{wait}{}
Wait for completion of a child process, and return a tu...
... exit status indication (encoded as by \UNIX{}).
(Not on MS-DOS.)
\end{funcdesc}


\begin{funcdesc}{waitpid}{pid\, options}
Wait for completion of a child process ...
...waitpid(), this always raises
\code{posix.error}. Not on MS-DOS.)
\end{funcdesc}


\begin{funcdesc}{write}{fd\, str}
Write the string \var{str} to file descriptor \var{fd}.
Return the number of bytes actually written.
\end{funcdesc}