blob: 834b9343a47eea62f0a6367afada576255d65cf2 [file] [log] [blame]
Fred Drake295da241998-08-10 19:42:37 +00001\section{\module{posix} ---
2 The most common \POSIX{} system calls.}
Fred Drakeb91e9341998-07-23 17:59:49 +00003\declaremodule{builtin}{posix}
4
Fred Drakebb3b0021999-01-11 18:36:23 +00005\modulesynopsis{The most common \POSIX{} system calls (normally used
6via module \module{os}).}
Fred Drakeb91e9341998-07-23 17:59:49 +00007
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00008
9This module provides access to operating system functionality that is
Fred Drake75aae9a1998-03-11 05:29:58 +000010standardized by the \C{} Standard and the \POSIX{} standard (a thinly
11disguised \UNIX{} interface).
Guido van Rossum470be141995-03-17 16:07:09 +000012
13\strong{Do not import this module directly.} Instead, import the
Fred Drake75aae9a1998-03-11 05:29:58 +000014module \module{os}, which provides a \emph{portable} version of this
15interface. On \UNIX{}, the \module{os} module provides a superset of
16the \module{posix} interface. On non-\UNIX{} operating systems the
17\module{posix} module is not available, but a subset is always
18available through the \module{os} interface. Once \module{os} is
19imported, there is \emph{no} performance penalty in using it instead
Fred Drakebb3b0021999-01-11 18:36:23 +000020of \module{posix}. In addition, \module{os}\refstmodindex{os}
21provides some additional functionality, such as automatically calling
22\function{putenv()} when an entry in \code{os.environ} is changed.
Guido van Rossum470be141995-03-17 16:07:09 +000023
Guido van Rossum282290f1997-08-27 14:54:25 +000024The descriptions below are very terse; refer to the corresponding
Fred Drake65b32f71998-02-09 20:27:12 +000025\UNIX{} manual (or \POSIX{} documentation) entry for more information.
Guido van Rossum282290f1997-08-27 14:54:25 +000026Arguments called \var{path} refer to a pathname given as a string.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000027
Barry Warsaweef2cd11998-07-23 19:50:09 +000028Errors are reported as exceptions; the usual exceptions are given for
29type errors, while errors reported by the system calls raise
30\exception{error} (a synonym for the standard exception
Fred Drakebb3b0021999-01-11 18:36:23 +000031\exception{OSError}), described below.
32
33\subsection{Large File Support \label{posix-large-files}}
34\index{large files}
35\index{file!large files}
36
37\sectionauthor{Steve Clift}{clift@mail.anacapa.net}
38
39Several operating systems (including AIX, HPUX, Irix and Solaris)
40provide support for files that are larger than 2 Gb from a \C{}
41programming model where \ctype{int} and \ctype{long} are 32-bit
42values. This is typically accomplished by defining the relevant size
43and offset types as 64-bit values. Such files are sometimes referred
44to as \dfn{large files}.
45
46Large file support is enabled in Python when the size of an
47\ctype{off_t} is larger than a \ctype{long} and the \ctype{long long}
48type is available and is at least as large as an \ctype{off_t}. Python
49longs are then used to represent file sizes, offsets and other values
50that can exceed the range of a Python int. It may be necessary to
51configure and compile Python with certain compiler flags to enable
52this mode. For example, it is enabled by default with recent versions
53of Irix, but with Solaris 2.6 and 2.7 you need to do something like:
54
55\begin{verbatim}
56CFLAGS="-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64" OPT="-g -O2 $CFLAGS" \
57 configure
58\end{verbatim} % $ <-- bow to font-lock
59
60
61\subsection{\module{posix} Module Contents \label{posix-contents}}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000062
Fred Drake75aae9a1998-03-11 05:29:58 +000063Module \module{posix} defines the following data items:
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000064
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000065\begin{datadesc}{environ}
Guido van Rossum04101961998-10-24 20:16:56 +000066A dictionary or dictionary look-alike representing the string
Fred Drakebb3b0021999-01-11 18:36:23 +000067environment at the time the interpreter was started. For example,
68\code{posix.environ['HOME']} is the pathname of your home directory,
69equivalent to \code{getenv("HOME")} in \C{}.
Guido van Rossum9c43c591997-08-08 21:05:09 +000070
Guido van Rossum470be141995-03-17 16:07:09 +000071Modifying this dictionary does not affect the string environment
Fred Drake75aae9a1998-03-11 05:29:58 +000072passed on by \function{execv()}, \function{popen()} or
73\function{system()}; if you need to change the environment, pass
74\code{environ} to \function{execve()} or add variable assignments and
75export statements to the command string for \function{system()} or
76\function{popen()}.
Guido van Rossum9c43c591997-08-08 21:05:09 +000077
Fred Drake75aae9a1998-03-11 05:29:58 +000078\emph{However:} If you are using this module via the \module{os}
79module (as you should -- see the introduction above), \code{environ}
80is a a mapping object that behaves almost like a dictionary but
Fred Drakec024c991998-10-28 18:19:16 +000081invokes \function{putenv()} automatically whenever an item is changed.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000082\end{datadesc}
83
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000084\begin{excdesc}{error}
Fred Drake65b32f71998-02-09 20:27:12 +000085This exception is raised when a \POSIX{} function returns a
Fred Drake75aae9a1998-03-11 05:29:58 +000086\POSIX{}-related error (e.g., not for illegal argument types). The
87accompanying value is a pair containing the numeric error code from
88\cdata{errno} and the corresponding string, as would be printed by the
89\C{} function \cfunction{perror()}. See the module
90\module{errno}\refbimodindex{errno}, which contains names for the
91error codes defined by the underlying operating system.
92
93When exceptions are classes, this exception carries two attributes,
94\member{errno} and \member{strerror}. The first holds the value of
95the \C{} \cdata{errno} variable, and the latter holds the
Barry Warsaweef2cd11998-07-23 19:50:09 +000096corresponding error message from \cfunction{strerror()}. For
97exceptions that involve a file system path (e.g. \code{chdir} or
98\code{unlink}), the exception instance will contain a third attribute
99\member{filename} which is the file name passed to the
100function.
Fred Drake75aae9a1998-03-11 05:29:58 +0000101
102When exceptions are strings, the string for the exception is
Barry Warsaweef2cd11998-07-23 19:50:09 +0000103\code{'OSError'}.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000104\end{excdesc}
105
Fred Drakebb3b0021999-01-11 18:36:23 +0000106It defines the following functions and constants when the operating
107system provides them directly or provides the means to emulate them:
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000108
Guido van Rossum74429ea1999-01-06 23:03:43 +0000109\begin{funcdesc}{access}{path, mode}
110Check read/write/execute permissions for this process or extance of file
111\var{path}. Return \code{1} if access is granted, \code{0} if not.
112See the \UNIX{} manual for the semantics.
113\end{funcdesc}
114
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000115\begin{funcdesc}{chdir}{path}
116Change the current working directory to \var{path}.
117\end{funcdesc}
118
Fred Drakecce10901998-03-17 06:33:25 +0000119\begin{funcdesc}{chmod}{path, mode}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000120Change the mode of \var{path} to the numeric \var{mode}.
121\end{funcdesc}
122
Fred Drakecce10901998-03-17 06:33:25 +0000123\begin{funcdesc}{chown}{path, uid, gid}
Guido van Rossum31cce971995-01-04 19:17:34 +0000124Change the owner and group id of \var{path} to the numeric \var{uid}
125and \var{gid}.
126(Not on MS-DOS.)
127\end{funcdesc}
128
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000129\begin{funcdesc}{close}{fd}
130Close file descriptor \var{fd}.
Guido van Rossum28379701995-01-12 12:38:22 +0000131
132Note: this function is intended for low-level I/O and must be applied
Fred Drake75aae9a1998-03-11 05:29:58 +0000133to a file descriptor as returned by \function{open()} or
134\function{pipe()}. To close a ``file object'' returned by the
135built-in function \function{open()} or by \function{popen()} or
136\function{fdopen()}, use its \method{close()} method.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000137\end{funcdesc}
138
139\begin{funcdesc}{dup}{fd}
140Return a duplicate of file descriptor \var{fd}.
141\end{funcdesc}
142
Fred Drakecce10901998-03-17 06:33:25 +0000143\begin{funcdesc}{dup2}{fd, fd2}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000144Duplicate file descriptor \var{fd} to \var{fd2}, closing the latter
Fred Drake75aae9a1998-03-11 05:29:58 +0000145first if necessary.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000146\end{funcdesc}
147
Fred Drakecce10901998-03-17 06:33:25 +0000148\begin{funcdesc}{execv}{path, args}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000149Execute the executable \var{path} with argument list \var{args},
150replacing the current process (i.e., the Python interpreter).
151The argument list may be a tuple or list of strings.
152(Not on MS-DOS.)
153\end{funcdesc}
154
Fred Drakecce10901998-03-17 06:33:25 +0000155\begin{funcdesc}{execve}{path, args, env}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000156Execute the executable \var{path} with argument list \var{args},
157and environment \var{env},
158replacing the current process (i.e., the Python interpreter).
159The argument list may be a tuple or list of strings.
160The environment must be a dictionary mapping strings to strings.
161(Not on MS-DOS.)
162\end{funcdesc}
163
164\begin{funcdesc}{_exit}{n}
165Exit to the system with status \var{n}, without calling cleanup
166handlers, flushing stdio buffers, etc.
167(Not on MS-DOS.)
168
169Note: the standard way to exit is \code{sys.exit(\var{n})}.
Fred Drake75aae9a1998-03-11 05:29:58 +0000170\function{_exit()} should normally only be used in the child process
171after a \function{fork()}.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000172\end{funcdesc}
173
Fred Drakecce10901998-03-17 06:33:25 +0000174\begin{funcdesc}{fdopen}{fd\optional{, mode\optional{, bufsize}}}
Guido van Rossum28379701995-01-12 12:38:22 +0000175Return an open file object connected to the file descriptor \var{fd}.
176The \var{mode} and \var{bufsize} arguments have the same meaning as
Fred Drake75aae9a1998-03-11 05:29:58 +0000177the corresponding arguments to the built-in \function{open()} function.
Guido van Rossumc5c67bc1994-02-15 15:59:23 +0000178\end{funcdesc}
179
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000180\begin{funcdesc}{fork}{}
Fred Drake75aae9a1998-03-11 05:29:58 +0000181Fork a child process. Return \code{0} in the child, the child's
182process id in the parent.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000183(Not on MS-DOS.)
184\end{funcdesc}
185
186\begin{funcdesc}{fstat}{fd}
Fred Drake75aae9a1998-03-11 05:29:58 +0000187Return status for file descriptor \var{fd}, like \function{stat()}.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000188\end{funcdesc}
189
Fred Drakebb3b0021999-01-11 18:36:23 +0000190\begin{funcdesc}{fstatvfs}{fd}
191Return information about the filesystem containing the file associated
192with file descriptor \var{fd}, like \function{statvfs()}.
193\end{funcdesc}
194
Fred Drakecce10901998-03-17 06:33:25 +0000195\begin{funcdesc}{ftruncate}{fd, length}
Guido van Rossumf967bf61997-06-02 17:28:51 +0000196Truncate the file corresponding to file descriptor \var{fd},
197so that it is at most \var{length} bytes in size.
198\end{funcdesc}
199
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000200\begin{funcdesc}{getcwd}{}
201Return a string representing the current working directory.
202\end{funcdesc}
203
204\begin{funcdesc}{getegid}{}
Guido van Rossumeb0f0661997-12-30 20:38:16 +0000205Return the current process' effective group id.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000206(Not on MS-DOS.)
207\end{funcdesc}
208
209\begin{funcdesc}{geteuid}{}
Guido van Rossumeb0f0661997-12-30 20:38:16 +0000210Return the current process' effective user id.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000211(Not on MS-DOS.)
212\end{funcdesc}
213
214\begin{funcdesc}{getgid}{}
Guido van Rossumeb0f0661997-12-30 20:38:16 +0000215Return the current process' group id.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000216(Not on MS-DOS.)
217\end{funcdesc}
218
Guido van Rossum1e8b63e1996-06-26 19:22:46 +0000219\begin{funcdesc}{getpgrp}{}
Fred Drake3b02ddf1998-12-21 18:52:53 +0000220\index{process!group}
Guido van Rossum1e8b63e1996-06-26 19:22:46 +0000221Return the current process group id.
222(Not on MS-DOS.)
223\end{funcdesc}
224
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000225\begin{funcdesc}{getpid}{}
Fred Drake3b02ddf1998-12-21 18:52:53 +0000226\index{process!id}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000227Return the current process id.
228(Not on MS-DOS.)
229\end{funcdesc}
230
231\begin{funcdesc}{getppid}{}
Fred Drake3b02ddf1998-12-21 18:52:53 +0000232\index{process!id of parent}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000233Return the parent's process id.
234(Not on MS-DOS.)
235\end{funcdesc}
236
237\begin{funcdesc}{getuid}{}
Fred Drake3b02ddf1998-12-21 18:52:53 +0000238\index{user id}
Guido van Rossumeb0f0661997-12-30 20:38:16 +0000239Return the current process' user id.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000240(Not on MS-DOS.)
241\end{funcdesc}
242
Fred Drakecce10901998-03-17 06:33:25 +0000243\begin{funcdesc}{kill}{pid, sig}
Fred Drake3b02ddf1998-12-21 18:52:53 +0000244\index{process!killing}
245\index{process!signalling}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000246Kill the process \var{pid} with signal \var{sig}.
247(Not on MS-DOS.)
248\end{funcdesc}
249
Fred Drakecce10901998-03-17 06:33:25 +0000250\begin{funcdesc}{link}{src, dst}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000251Create a hard link pointing to \var{src} named \var{dst}.
252(Not on MS-DOS.)
253\end{funcdesc}
254
255\begin{funcdesc}{listdir}{path}
256Return a list containing the names of the entries in the directory.
Guido van Rossum8c07bb41996-02-12 23:16:08 +0000257The list is in arbitrary order. It does not include the special
258entries \code{'.'} and \code{'..'} even if they are present in the
259directory.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000260\end{funcdesc}
261
Fred Drakecce10901998-03-17 06:33:25 +0000262\begin{funcdesc}{lseek}{fd, pos, how}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000263Set the current position of file descriptor \var{fd} to position
Fred Drake75aae9a1998-03-11 05:29:58 +0000264\var{pos}, modified by \var{how}: \code{0} to set the position
265relative to the beginning of the file; \code{1} to set it relative to
266the current position; \code{2} to set it relative to the end of the
267file.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000268\end{funcdesc}
269
270\begin{funcdesc}{lstat}{path}
Fred Drake75aae9a1998-03-11 05:29:58 +0000271Like \function{stat()}, but do not follow symbolic links. (On systems
272without symbolic links, this is identical to \function{stat()}.)
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000273\end{funcdesc}
274
Fred Drakecce10901998-03-17 06:33:25 +0000275\begin{funcdesc}{mkfifo}{path\optional{, mode}}
Fred Drake65b32f71998-02-09 20:27:12 +0000276Create a FIFO (a \POSIX{} named pipe) named \var{path} with numeric mode
Fred Drake75aae9a1998-03-11 05:29:58 +0000277\var{mode}. The default \var{mode} is \code{0666} (octal). The current
Guido van Rossum1e8b63e1996-06-26 19:22:46 +0000278umask value is first masked out from the mode.
279(Not on MS-DOS.)
280
281FIFOs are pipes that can be accessed like regular files. FIFOs exist
Fred Drake75aae9a1998-03-11 05:29:58 +0000282until they are deleted (for example with \function{os.unlink()}).
283Generally, FIFOs are used as rendezvous between ``client'' and
Guido van Rossum1e8b63e1996-06-26 19:22:46 +0000284``server'' type processes: the server opens the FIFO for reading, and
Fred Drake75aae9a1998-03-11 05:29:58 +0000285the client opens it for writing. Note that \function{mkfifo()}
286doesn't open the FIFO --- it just creates the rendezvous point.
Guido van Rossum1e8b63e1996-06-26 19:22:46 +0000287\end{funcdesc}
288
Fred Drakecce10901998-03-17 06:33:25 +0000289\begin{funcdesc}{mkdir}{path\optional{, mode}}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000290Create a directory named \var{path} with numeric mode \var{mode}.
Fred Drake75aae9a1998-03-11 05:29:58 +0000291The default \var{mode} is \code{0777} (octal). On some systems,
292\var{mode} is ignored. Where it is used, the current umask value is
293first masked out.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000294\end{funcdesc}
295
296\begin{funcdesc}{nice}{increment}
Fred Drake75aae9a1998-03-11 05:29:58 +0000297Add \var{increment} to the process' ``niceness''. Return the new
298niceness. (Not on MS-DOS.)
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000299\end{funcdesc}
300
Fred Drakecce10901998-03-17 06:33:25 +0000301\begin{funcdesc}{open}{file, flags\optional{, mode}}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000302Open the file \var{file} and set various flags according to
303\var{flags} and possibly its mode according to \var{mode}.
Fred Drake75aae9a1998-03-11 05:29:58 +0000304The default \var{mode} is \code{0777} (octal), and the current umask
305value is first masked out. Return the file descriptor for the newly
306opened file.
Guido van Rossum28379701995-01-12 12:38:22 +0000307
Fred Drake75aae9a1998-03-11 05:29:58 +0000308For a description of the flag and mode values, see the \UNIX{} or \C{}
309run-time documentation; flag constants (like \constant{O_RDONLY} and
310\constant{O_WRONLY}) are defined in this module too (see below).
Guido van Rossum9c43c591997-08-08 21:05:09 +0000311
Guido van Rossum28379701995-01-12 12:38:22 +0000312Note: this function is intended for low-level I/O. For normal usage,
Fred Drake75aae9a1998-03-11 05:29:58 +0000313use the built-in function \function{open()}, which returns a ``file
314object'' with \method{read()} and \method{write()} methods (and many
315more).
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000316\end{funcdesc}
317
318\begin{funcdesc}{pipe}{}
Fred Drake75aae9a1998-03-11 05:29:58 +0000319Create a pipe. Return a pair of file descriptors \code{(\var{r},
320\var{w})} usable for reading and writing, respectively.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000321(Not on MS-DOS.)
322\end{funcdesc}
323
Guido van Rossum38e50881996-07-21 02:21:49 +0000324\begin{funcdesc}{plock}{op}
325Lock program segments into memory. The value of \var{op}
326(defined in \code{<sys/lock.h>}) determines which segments are locked.
327(Not on MS-DOS.)
328\end{funcdesc}
329
Fred Drakecce10901998-03-17 06:33:25 +0000330\begin{funcdesc}{popen}{command\optional{, mode\optional{, bufsize}}}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000331Open a pipe to or from \var{command}. The return value is an open
332file object connected to the pipe, which can be read or written
Guido van Rossum28379701995-01-12 12:38:22 +0000333depending on whether \var{mode} is \code{'r'} (default) or \code{'w'}.
334The \var{bufsize} argument has the same meaning as the corresponding
Fred Drake75aae9a1998-03-11 05:29:58 +0000335argument to the built-in \function{open()} function. The exit status of
336the command (encoded in the format specified for \function{wait()}) is
337available as the return value of the \method{close()} method of the file
Guido van Rossumf35b8841998-10-15 13:28:29 +0000338object, except that when the exit status is zero (termination without
339errors), \code{None} is returned.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000340(Not on MS-DOS.)
341\end{funcdesc}
342
Fred Drakecce10901998-03-17 06:33:25 +0000343\begin{funcdesc}{putenv}{varname, value}
Fred Drake52405c81998-03-16 05:21:08 +0000344\index{environment variables!setting}
Fred Drake75aae9a1998-03-11 05:29:58 +0000345Set the environment variable named \var{varname} to the string
346\var{value}. Such changes to the environment affect subprocesses
347started with \function{os.system()}, \function{os.popen()} or
348\function{os.fork()} and \function{os.execv()}. (Not on all systems.)
Guido van Rossumf967bf61997-06-02 17:28:51 +0000349
Fred Drake75aae9a1998-03-11 05:29:58 +0000350When \function{putenv()} is
Guido van Rossumf967bf61997-06-02 17:28:51 +0000351supported, assignments to items in \code{os.environ} are automatically
Fred Drake75aae9a1998-03-11 05:29:58 +0000352translated into corresponding calls to \function{putenv()}; however,
353calls to \function{putenv()} don't update \code{os.environ}, so it is
Guido van Rossumf967bf61997-06-02 17:28:51 +0000354actually preferable to assign to items of \code{os.environ}.
355\end{funcdesc}
356
Guido van Rossum0bfd1461997-10-05 18:54:52 +0000357\begin{funcdesc}{strerror}{code}
358Return the error message corresponding to the error code in \var{code}.
359\end{funcdesc}
360
Guido van Rossum74429ea1999-01-06 23:03:43 +0000361\begin{funcdesc}{ttyname}{fd}
362Return a string which specifies the terminal device associated with
363file-descriptor \var{fd}. If \var{fd} is not associated with a terminal
364device, an exception is raised.
365\end{funcdesc}
366
Fred Drakecce10901998-03-17 06:33:25 +0000367\begin{funcdesc}{read}{fd, n}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000368Read at most \var{n} bytes from file descriptor \var{fd}.
369Return a string containing the bytes read.
Guido van Rossum28379701995-01-12 12:38:22 +0000370
371Note: this function is intended for low-level I/O and must be applied
Fred Drake75aae9a1998-03-11 05:29:58 +0000372to a file descriptor as returned by \function{open()} or
373\function{pipe()}. To read a ``file object'' returned by the
374built-in function \function{open()} or by \function{popen()} or
375\function{fdopen()}, or \code{sys.stdin}, use its
376\method{read()} or \method{readline()} methods.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000377\end{funcdesc}
378
379\begin{funcdesc}{readlink}{path}
380Return a string representing the path to which the symbolic link
381points. (On systems without symbolic links, this always raises
Fred Drake75aae9a1998-03-11 05:29:58 +0000382\exception{error}.)
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000383\end{funcdesc}
384
Guido van Rossum8c07bb41996-02-12 23:16:08 +0000385\begin{funcdesc}{remove}{path}
Fred Drake75aae9a1998-03-11 05:29:58 +0000386Remove the file \var{path}. See \function{rmdir()} below to remove a
387directory. This is identical to the \function{unlink()} function
388documented below.
Guido van Rossum8c07bb41996-02-12 23:16:08 +0000389\end{funcdesc}
390
Fred Drakecce10901998-03-17 06:33:25 +0000391\begin{funcdesc}{rename}{src, dst}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000392Rename the file or directory \var{src} to \var{dst}.
393\end{funcdesc}
394
395\begin{funcdesc}{rmdir}{path}
396Remove the directory \var{path}.
397\end{funcdesc}
398
399\begin{funcdesc}{setgid}{gid}
Guido van Rossumeb0f0661997-12-30 20:38:16 +0000400Set the current process' group id.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000401(Not on MS-DOS.)
402\end{funcdesc}
403
Guido van Rossum1e8b63e1996-06-26 19:22:46 +0000404\begin{funcdesc}{setpgrp}{}
Fred Drake75aae9a1998-03-11 05:29:58 +0000405Calls the system call \cfunction{setpgrp()} or \cfunction{setpgrp(0,
4060)} depending on which version is implemented (if any). See the
407\UNIX{} manual for the semantics.
Guido van Rossum1e8b63e1996-06-26 19:22:46 +0000408(Not on MS-DOS.)
409\end{funcdesc}
410
Fred Drakecce10901998-03-17 06:33:25 +0000411\begin{funcdesc}{setpgid}{pid, pgrp}
Fred Drake75aae9a1998-03-11 05:29:58 +0000412Calls the system call \cfunction{setpgid()}. See the \UNIX{} manual
413for the semantics.
Guido van Rossum1e8b63e1996-06-26 19:22:46 +0000414(Not on MS-DOS.)
415\end{funcdesc}
416
417\begin{funcdesc}{setsid}{}
Fred Drake75aae9a1998-03-11 05:29:58 +0000418Calls the system call \cfunction{setsid()}. See the \UNIX{} manual
419for the semantics.
Guido van Rossum1e8b63e1996-06-26 19:22:46 +0000420(Not on MS-DOS.)
421\end{funcdesc}
422
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000423\begin{funcdesc}{setuid}{uid}
Guido van Rossumeb0f0661997-12-30 20:38:16 +0000424Set the current process' user id.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000425(Not on MS-DOS.)
426\end{funcdesc}
427
428\begin{funcdesc}{stat}{path}
Fred Drake75aae9a1998-03-11 05:29:58 +0000429Perform a \cfunction{stat()} system call on the given path. The
430return value is a tuple of at least 10 integers giving the most
431important (and portable) members of the \emph{stat} structure, in the
432order
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000433\code{st_mode},
434\code{st_ino},
435\code{st_dev},
436\code{st_nlink},
437\code{st_uid},
438\code{st_gid},
439\code{st_size},
440\code{st_atime},
441\code{st_mtime},
442\code{st_ctime}.
443More items may be added at the end by some implementations.
444(On MS-DOS, some items are filled with dummy values.)
445
Fred Drake75aae9a1998-03-11 05:29:58 +0000446Note: The standard module \module{stat}\refstmodindex{stat} defines
447functions and constants that are useful for extracting information
Fred Drakebb3b0021999-01-11 18:36:23 +0000448from a \ctype{stat} structure.
449\end{funcdesc}
450
451\begin{funcdesc}{statvfs}{path}
452Perform a \cfunction{statvfs()} system call on the given path. The
453return value is a tuple of 11 integers giving the most common
454members of the \ctype{statvfs} structure, in the order
455\code{f_bsize},
456\code{f_frsize},
457\code{f_blocks},
458\code{f_bfree},
459\code{f_bavail},
460\code{f_files},
461\code{f_ffree},
462\code{f_favail},
463\code{f_fsid},
464\code{f_flag},
465\code{f_namemax}.
466
467Note: The standard module \module{statvfs}\refstmodindex{statvfs}
468defines constants that are useful for extracting information
469from a \ctype{statvfs} structure.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000470\end{funcdesc}
471
Fred Drakecce10901998-03-17 06:33:25 +0000472\begin{funcdesc}{symlink}{src, dst}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000473Create a symbolic link pointing to \var{src} named \var{dst}. (On
Fred Drake75aae9a1998-03-11 05:29:58 +0000474systems without symbolic links, this always raises \exception{error}.)
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000475\end{funcdesc}
476
477\begin{funcdesc}{system}{command}
478Execute the command (a string) in a subshell. This is implemented by
Fred Drake75aae9a1998-03-11 05:29:58 +0000479calling the Standard \C{} function \cfunction{system()}, and has the
480same limitations. Changes to \code{posix.environ}, \code{sys.stdin}
481etc.\ are not reflected in the environment of the executed command.
482The return value is the exit status of the process encoded in the
483format specified for \function{wait()}.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000484\end{funcdesc}
485
Guido van Rossum1e8b63e1996-06-26 19:22:46 +0000486\begin{funcdesc}{tcgetpgrp}{fd}
487Return the process group associated with the terminal given by
Fred Drake75aae9a1998-03-11 05:29:58 +0000488\var{fd} (an open file descriptor as returned by \function{open()}).
Guido van Rossum1e8b63e1996-06-26 19:22:46 +0000489(Not on MS-DOS.)
490\end{funcdesc}
491
Fred Drakecce10901998-03-17 06:33:25 +0000492\begin{funcdesc}{tcsetpgrp}{fd, pg}
Guido van Rossum1e8b63e1996-06-26 19:22:46 +0000493Set the process group associated with the terminal given by
Fred Drake75aae9a1998-03-11 05:29:58 +0000494\var{fd} (an open file descriptor as returned by \function{open()})
Guido van Rossum1e8b63e1996-06-26 19:22:46 +0000495to \var{pg}.
496(Not on MS-DOS.)
497\end{funcdesc}
498
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000499\begin{funcdesc}{times}{}
Guido van Rossum1e150611995-09-13 17:36:35 +0000500Return a 5-tuple of floating point numbers indicating accumulated (CPU
501or other)
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000502times, in seconds. The items are: user time, system time, children's
Guido van Rossum1e150611995-09-13 17:36:35 +0000503user time, children's system time, and elapsed real time since a fixed
504point in the past, in that order. See the \UNIX{}
Fred Drake75aae9a1998-03-11 05:29:58 +0000505manual page \manpage{times}{2}. (Not on MS-DOS.)
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000506\end{funcdesc}
507
508\begin{funcdesc}{umask}{mask}
509Set the current numeric umask and returns the previous umask.
510(Not on MS-DOS.)
511\end{funcdesc}
512
513\begin{funcdesc}{uname}{}
514Return a 5-tuple containing information identifying the current
515operating system. The tuple contains 5 strings:
Fred Drake75aae9a1998-03-11 05:29:58 +0000516\code{(\var{sysname}, \var{nodename}, \var{release}, \var{version},
517\var{machine})}. Some systems truncate the nodename to 8
Guido van Rossum6bb1adc1995-03-13 10:03:32 +0000518characters or to the leading component; a better way to get the
Fred Drake75aae9a1998-03-11 05:29:58 +0000519hostname is \function{socket.gethostname()}%
Fred Drake371ecc01998-03-12 06:44:58 +0000520\withsubitem{(in module socket)}{\ttindex{gethostname()}}
Fred Drake75aae9a1998-03-11 05:29:58 +0000521or even
522\code{socket.gethostbyaddr(socket.gethostname())}%
Fred Drake371ecc01998-03-12 06:44:58 +0000523\withsubitem{(in module socket)}{\ttindex{gethostbyaddr()}}.
Guido van Rossumeb0f0661997-12-30 20:38:16 +0000524(Not on MS-DOS, nor on older \UNIX{} systems.)
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000525\end{funcdesc}
526
527\begin{funcdesc}{unlink}{path}
Guido van Rossum8c07bb41996-02-12 23:16:08 +0000528Remove the file \var{path}. This is the same function as \code{remove};
529the \code{unlink} name is its traditional \UNIX{} name.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000530\end{funcdesc}
531
Fred Drakecaa33791998-11-30 21:53:47 +0000532\begin{funcdesc}{utime}{path, (atime, mtime)}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000533Set the access and modified time of the file to the given values.
534(The second argument is a tuple of two items.)
535\end{funcdesc}
536
537\begin{funcdesc}{wait}{}
538Wait for completion of a child process, and return a tuple containing
Guido van Rossum7e691de1997-05-09 02:22:59 +0000539its pid and exit status indication: a 16-bit number, whose low byte is
540the signal number that killed the process, and whose high byte is the
541exit status (if the signal number is zero); the high bit of the low
542byte is set if a core file was produced. (Not on MS-DOS.)
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000543\end{funcdesc}
544
Fred Drakecce10901998-03-17 06:33:25 +0000545\begin{funcdesc}{waitpid}{pid, options}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000546Wait for completion of a child process given by proces id, and return
Guido van Rossum7e691de1997-05-09 02:22:59 +0000547a tuple containing its pid and exit status indication (encoded as for
Fred Drake75aae9a1998-03-11 05:29:58 +0000548\function{wait()}). The semantics of the call are affected by the
549value of the integer \var{options}, which should be \code{0} for
550normal operation. (If the system does not support
551\function{waitpid()}, this always raises \exception{error}. Not on
552MS-DOS.)
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000553\end{funcdesc}
554
Fred Drakecce10901998-03-17 06:33:25 +0000555\begin{funcdesc}{write}{fd, str}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000556Write the string \var{str} to file descriptor \var{fd}.
557Return the number of bytes actually written.
Guido van Rossum28379701995-01-12 12:38:22 +0000558
559Note: this function is intended for low-level I/O and must be applied
Fred Drake75aae9a1998-03-11 05:29:58 +0000560to a file descriptor as returned by \function{open()} or
561\function{pipe()}. To write a ``file object'' returned by the
562built-in function \function{open()} or by \function{popen()} or
563\function{fdopen()}, or \code{sys.stdout} or \code{sys.stderr}, use
564its \method{write()} method.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000565\end{funcdesc}
Guido van Rossum4bbe9c01995-03-30 16:00:36 +0000566
567\begin{datadesc}{WNOHANG}
Fred Drake75aae9a1998-03-11 05:29:58 +0000568The option for \function{waitpid()} to avoid hanging if no child
569process status is available immediately.
Guido van Rossum4bbe9c01995-03-30 16:00:36 +0000570\end{datadesc}
Barry Warsawe5a43a41996-12-19 23:50:34 +0000571
572
573\begin{datadesc}{O_RDONLY}
Fred Drake86b5dce1998-02-13 21:55:21 +0000574\dataline{O_WRONLY}
575\dataline{O_RDWR}
576\dataline{O_NDELAY}
577\dataline{O_NONBLOCK}
578\dataline{O_APPEND}
579\dataline{O_DSYNC}
580\dataline{O_RSYNC}
581\dataline{O_SYNC}
582\dataline{O_NOCTTY}
583\dataline{O_CREAT}
584\dataline{O_EXCL}
585\dataline{O_TRUNC}
Fred Drake75aae9a1998-03-11 05:29:58 +0000586Options for the \code{flag} argument to the \function{open()} function.
Barry Warsawe5a43a41996-12-19 23:50:34 +0000587These can be bit-wise OR'd together.
588\end{datadesc}