1998-08-10 19:42:37 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								\section{\module{posix} ---
							 | 
						
					
						
							
								
									
										
										
										
											1999-03-02 16:37:17 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								         The most common \POSIX{} system calls}
							 | 
						
					
						
							
								
									
										
										
										
											1998-07-23 17:59:49 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											1999-03-02 16:37:17 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								\declaremodule{builtin}{posix}
							 | 
						
					
						
							
								
									
										
										
										
											1999-03-02 17:03:42 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  \platform{Unix}
							 | 
						
					
						
							
								
									
										
										
										
											2001-05-09 15:50:17 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								\modulesynopsis{The most common \POSIX\ system calls (normally used
							 | 
						
					
						
							
								
									
										
										
										
											1999-07-01 13:53:32 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                via module \refmodule{os}).}
							 | 
						
					
						
							
								
									
										
										
										
											1998-07-23 17:59:49 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											1994-01-02 01:22:07 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								This module provides access to operating system functionality that is
							 | 
						
					
						
							
								
									
										
										
										
											1999-02-01 20:23:02 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								standardized by the C Standard and the \POSIX{} standard (a thinly
							 | 
						
					
						
							
								
									
										
										
										
											1998-03-11 05:29:58 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								disguised \UNIX{} interface).
							 | 
						
					
						
							
								
									
										
										
										
											1995-03-17 16:07:09 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								\strong{Do not import this module directly.}  Instead, import the
							 | 
						
					
						
							
								
									
										
										
										
											1999-02-02 19:02:35 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								module \refmodule{os}, which provides a \emph{portable} version of this
							 | 
						
					
						
							
								
									
										
										
										
											2001-11-28 07:26:15 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								interface.  On \UNIX, the \refmodule{os} module provides a superset of
							 | 
						
					
						
							
								
									
										
										
										
											1998-03-11 05:29:58 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								the \module{posix} interface.  On non-\UNIX{} operating systems the
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								\module{posix} module is not available, but a subset is always
							 | 
						
					
						
							
								
									
										
										
										
											1999-04-21 18:33:47 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								available through the \refmodule{os} interface.  Once \refmodule{os} is
							 | 
						
					
						
							
								
									
										
										
										
											1998-03-11 05:29:58 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								imported, there is \emph{no} performance penalty in using it instead
							 | 
						
					
						
							
								
									
										
										
										
											1999-04-21 18:33:47 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								of \module{posix}.  In addition, \refmodule{os}\refstmodindex{os}
							 | 
						
					
						
							
								
									
										
										
										
											1999-01-11 18:36:23 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								provides some additional functionality, such as automatically calling
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								\function{putenv()} when an entry in \code{os.environ} is changed.
							 | 
						
					
						
							
								
									
										
										
										
											1995-03-17 16:07:09 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											1997-08-27 14:54:25 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								The descriptions below are very terse; refer to the corresponding
							 | 
						
					
						
							
								
									
										
										
										
											1998-02-09 20:27:12 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								\UNIX{} manual (or \POSIX{} documentation) entry for more information.
							 | 
						
					
						
							
								
									
										
										
										
											1997-08-27 14:54:25 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								Arguments called \var{path} refer to a pathname given as a string.
							 | 
						
					
						
							
								
									
										
										
										
											1994-01-02 01:22:07 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											1998-07-23 19:50:09 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								Errors are reported as exceptions; the usual exceptions are given for
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								type errors, while errors reported by the system calls raise
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								\exception{error} (a synonym for the standard exception
							 | 
						
					
						
							
								
									
										
										
										
											1999-01-11 18:36:23 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								\exception{OSError}), described below.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											1999-02-02 19:02:35 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											1999-01-11 18:36:23 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								\subsection{Large File Support \label{posix-large-files}}
							 | 
						
					
						
							
								
									
										
										
										
											1999-02-02 19:02:35 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								\sectionauthor{Steve Clift}{clift@mail.anacapa.net}
							 | 
						
					
						
							
								
									
										
										
										
											1999-01-11 18:36:23 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								\index{large files}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								\index{file!large files}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								Several operating systems (including AIX, HPUX, Irix and Solaris)
							 | 
						
					
						
							
								
									
										
										
										
											1999-02-01 20:23:02 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								provide support for files that are larger than 2 Gb from a C
							 | 
						
					
						
							
								
									
										
										
										
											1999-01-11 18:36:23 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								programming model where \ctype{int} and \ctype{long} are 32-bit
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								values. This is typically accomplished by defining the relevant size
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								and offset types as 64-bit values. Such files are sometimes referred
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								to as \dfn{large files}.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								Large file support is enabled in Python when the size of an
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								\ctype{off_t} is larger than a \ctype{long} and the \ctype{long long}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								type is available and is at least as large as an \ctype{off_t}. Python
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								longs are then used to represent file sizes, offsets and other values
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								that can exceed the range of a Python int. It may be necessary to
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								configure and compile Python with certain compiler flags to enable
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								this mode. For example, it is enabled by default with recent versions
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								of Irix, but with Solaris 2.6 and 2.7 you need to do something like:
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								\begin{verbatim}
							 | 
						
					
						
							
								
									
										
										
										
											1999-05-26 13:03:34 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								CFLAGS="`getconf LFS_CFLAGS`" OPT="-g -O2 $CFLAGS" \
							 | 
						
					
						
							
								
									
										
										
										
											2001-03-01 18:29:57 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        ./configure
							 | 
						
					
						
							
								
									
										
										
										
											1999-01-11 18:36:23 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								\end{verbatim} % $ <-- bow to font-lock
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2001-03-01 18:29:57 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								On large-file-capable Linux systems, this might work:
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								\begin{verbatim}
							 | 
						
					
						
							
								
									
										
										
										
											2001-06-22 16:01:20 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								CFLAGS='-D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64' OPT="-g -O2 $CFLAGS" \
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        ./configure
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								\end{verbatim} % $ <-- bow to font-lock
							 | 
						
					
						
							
								
									
										
										
										
											2001-03-01 18:29:57 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											1999-01-11 18:36:23 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											1999-02-02 19:02:35 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								\subsection{Module Contents \label{posix-contents}}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											1994-01-02 01:22:07 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											1999-02-01 20:23:02 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								Module \module{posix} defines the following data item:
							 | 
						
					
						
							
								
									
										
										
										
											1994-01-02 01:22:07 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								\begin{datadesc}{environ}
							 | 
						
					
						
							
								
									
										
										
										
											1999-02-01 20:23:02 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								A dictionary representing the string environment at the time the
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								interpreter was started. For example, \code{environ['HOME']} is the
							 | 
						
					
						
							
								
									
										
										
										
											1999-04-21 18:33:47 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								pathname of your home directory, equivalent to
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								\code{getenv("HOME")} in C.
							 | 
						
					
						
							
								
									
										
										
										
											1997-08-08 21:05:09 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											1995-03-17 16:07:09 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								Modifying this dictionary does not affect the string environment
							 | 
						
					
						
							
								
									
										
										
										
											1998-03-11 05:29:58 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								passed on by \function{execv()}, \function{popen()} or
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								\function{system()}; if you need to change the environment, pass
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								\code{environ} to \function{execve()} or add variable assignments and
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								export statements to the command string for \function{system()} or
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								\function{popen()}.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2001-10-20 04:24:09 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								\note{The \refmodule{os} module provides an alternate
							 | 
						
					
						
							
								
									
										
										
										
											1999-02-01 20:23:02 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								implementation of \code{environ} which updates the environment on
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								modification.  Note also that updating \code{os.environ} will render
							 | 
						
					
						
							
								
									
										
										
										
											2001-10-24 21:10:52 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								this dictionary obsolete.  Use of the \refmodule{os} module version of
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								this is recommended over direct access to the \module{posix} module.}
							 | 
						
					
						
							
								
									
										
										
										
											1994-01-02 01:22:07 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								\end{datadesc}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											1999-02-01 20:23:02 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								Additional contents of this module should only be accessed via the
							 | 
						
					
						
							
								
									
										
										
										
											1999-02-02 19:02:35 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								\refmodule{os} module; refer to the documentation for that module for
							 | 
						
					
						
							
								
									
										
										
										
											1999-02-01 20:23:02 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								further information.
							 |