blob: 071cf5673f17e4013a5c4645e0c1aa3ebc25e71e [file] [log] [blame]
Fred Drake3a0351c1998-04-04 07:23:21 +00001\section{Built-in Module \module{posix}}
Guido van Rossume47da0a1997-07-17 16:34:52 +00002\label{module-posix}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00003\bimodindex{posix}
4
5This module provides access to operating system functionality that is
Fred Drake75aae9a1998-03-11 05:29:58 +00006standardized by the \C{} Standard and the \POSIX{} standard (a thinly
7disguised \UNIX{} interface).
Guido van Rossum470be141995-03-17 16:07:09 +00008
9\strong{Do not import this module directly.} Instead, import the
Fred Drake75aae9a1998-03-11 05:29:58 +000010module \module{os}, which provides a \emph{portable} version of this
11interface. On \UNIX{}, the \module{os} module provides a superset of
12the \module{posix} interface. On non-\UNIX{} operating systems the
13\module{posix} module is not available, but a subset is always
14available through the \module{os} interface. Once \module{os} is
15imported, there is \emph{no} performance penalty in using it instead
16of \module{posix}. In addition, \module{os} provides some additional
17functionality, such as automatically calling \function{putenv()}
18when an entry in \code{os.environ} is changed.
Fred Drake62063941997-12-15 21:42:51 +000019\refstmodindex{os}
Guido van Rossum470be141995-03-17 16:07:09 +000020
Guido van Rossum282290f1997-08-27 14:54:25 +000021The descriptions below are very terse; refer to the corresponding
Fred Drake65b32f71998-02-09 20:27:12 +000022\UNIX{} manual (or \POSIX{} documentation) entry for more information.
Guido van Rossum282290f1997-08-27 14:54:25 +000023Arguments called \var{path} refer to a pathname given as a string.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000024
25Errors are reported as exceptions; the usual exceptions are given
26for type errors, while errors reported by the system calls raise
Fred Drake75aae9a1998-03-11 05:29:58 +000027\exception{error}, described below.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000028
Fred Drake75aae9a1998-03-11 05:29:58 +000029Module \module{posix} defines the following data items:
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000030
Fred Drake19479911998-02-13 06:58:54 +000031\setindexsubitem{(data in module posix)}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000032\begin{datadesc}{environ}
33A dictionary representing the string environment at the time
34the interpreter was started.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000035For example,
36\code{posix.environ['HOME']}
37is the pathname of your home directory, equivalent to
38\code{getenv("HOME")}
Fred Drake75aae9a1998-03-11 05:29:58 +000039in \C{}.
Guido van Rossum9c43c591997-08-08 21:05:09 +000040
Guido van Rossum470be141995-03-17 16:07:09 +000041Modifying this dictionary does not affect the string environment
Fred Drake75aae9a1998-03-11 05:29:58 +000042passed on by \function{execv()}, \function{popen()} or
43\function{system()}; if you need to change the environment, pass
44\code{environ} to \function{execve()} or add variable assignments and
45export statements to the command string for \function{system()} or
46\function{popen()}.
Guido van Rossum9c43c591997-08-08 21:05:09 +000047
Fred Drake75aae9a1998-03-11 05:29:58 +000048\emph{However:} If you are using this module via the \module{os}
49module (as you should -- see the introduction above), \code{environ}
50is a a mapping object that behaves almost like a dictionary but
51invokes \function{putenv()} automatically called whenever an item is
52changed.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000053\end{datadesc}
54
Fred Drake19479911998-02-13 06:58:54 +000055\setindexsubitem{(exception in module posix)}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000056\begin{excdesc}{error}
Fred Drake65b32f71998-02-09 20:27:12 +000057This exception is raised when a \POSIX{} function returns a
Fred Drake75aae9a1998-03-11 05:29:58 +000058\POSIX{}-related error (e.g., not for illegal argument types). The
59accompanying value is a pair containing the numeric error code from
60\cdata{errno} and the corresponding string, as would be printed by the
61\C{} function \cfunction{perror()}. See the module
62\module{errno}\refbimodindex{errno}, which contains names for the
63error codes defined by the underlying operating system.
64
65When exceptions are classes, this exception carries two attributes,
66\member{errno} and \member{strerror}. The first holds the value of
67the \C{} \cdata{errno} variable, and the latter holds the
68corresponding error message from \cfunction{strerror()}.
69
70When exceptions are strings, the string for the exception is
71\code{'os.error'}; this reflects the more portable access to the
72exception through the \module{os} module.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000073\end{excdesc}
74
Guido van Rossum4bbe9c01995-03-30 16:00:36 +000075It defines the following functions and constants:
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000076
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000077\begin{funcdesc}{chdir}{path}
78Change the current working directory to \var{path}.
79\end{funcdesc}
80
Fred Drakecce10901998-03-17 06:33:25 +000081\begin{funcdesc}{chmod}{path, mode}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000082Change the mode of \var{path} to the numeric \var{mode}.
83\end{funcdesc}
84
Fred Drakecce10901998-03-17 06:33:25 +000085\begin{funcdesc}{chown}{path, uid, gid}
Guido van Rossum31cce971995-01-04 19:17:34 +000086Change the owner and group id of \var{path} to the numeric \var{uid}
87and \var{gid}.
88(Not on MS-DOS.)
89\end{funcdesc}
90
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000091\begin{funcdesc}{close}{fd}
92Close file descriptor \var{fd}.
Guido van Rossum28379701995-01-12 12:38:22 +000093
94Note: this function is intended for low-level I/O and must be applied
Fred Drake75aae9a1998-03-11 05:29:58 +000095to a file descriptor as returned by \function{open()} or
96\function{pipe()}. To close a ``file object'' returned by the
97built-in function \function{open()} or by \function{popen()} or
98\function{fdopen()}, use its \method{close()} method.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000099\end{funcdesc}
100
101\begin{funcdesc}{dup}{fd}
102Return a duplicate of file descriptor \var{fd}.
103\end{funcdesc}
104
Fred Drakecce10901998-03-17 06:33:25 +0000105\begin{funcdesc}{dup2}{fd, fd2}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000106Duplicate file descriptor \var{fd} to \var{fd2}, closing the latter
Fred Drake75aae9a1998-03-11 05:29:58 +0000107first if necessary.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000108\end{funcdesc}
109
Fred Drakecce10901998-03-17 06:33:25 +0000110\begin{funcdesc}{execv}{path, args}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000111Execute the executable \var{path} with argument list \var{args},
112replacing the current process (i.e., the Python interpreter).
113The argument list may be a tuple or list of strings.
114(Not on MS-DOS.)
115\end{funcdesc}
116
Fred Drakecce10901998-03-17 06:33:25 +0000117\begin{funcdesc}{execve}{path, args, env}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000118Execute the executable \var{path} with argument list \var{args},
119and environment \var{env},
120replacing the current process (i.e., the Python interpreter).
121The argument list may be a tuple or list of strings.
122The environment must be a dictionary mapping strings to strings.
123(Not on MS-DOS.)
124\end{funcdesc}
125
126\begin{funcdesc}{_exit}{n}
127Exit to the system with status \var{n}, without calling cleanup
128handlers, flushing stdio buffers, etc.
129(Not on MS-DOS.)
130
131Note: the standard way to exit is \code{sys.exit(\var{n})}.
Fred Drake75aae9a1998-03-11 05:29:58 +0000132\function{_exit()} should normally only be used in the child process
133after a \function{fork()}.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000134\end{funcdesc}
135
Fred Drakecce10901998-03-17 06:33:25 +0000136\begin{funcdesc}{fdopen}{fd\optional{, mode\optional{, bufsize}}}
Guido van Rossum28379701995-01-12 12:38:22 +0000137Return an open file object connected to the file descriptor \var{fd}.
138The \var{mode} and \var{bufsize} arguments have the same meaning as
Fred Drake75aae9a1998-03-11 05:29:58 +0000139the corresponding arguments to the built-in \function{open()} function.
Guido van Rossumc5c67bc1994-02-15 15:59:23 +0000140\end{funcdesc}
141
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000142\begin{funcdesc}{fork}{}
Fred Drake75aae9a1998-03-11 05:29:58 +0000143Fork a child process. Return \code{0} in the child, the child's
144process id in the parent.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000145(Not on MS-DOS.)
146\end{funcdesc}
147
148\begin{funcdesc}{fstat}{fd}
Fred Drake75aae9a1998-03-11 05:29:58 +0000149Return status for file descriptor \var{fd}, like \function{stat()}.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000150\end{funcdesc}
151
Fred Drakecce10901998-03-17 06:33:25 +0000152\begin{funcdesc}{ftruncate}{fd, length}
Guido van Rossumf967bf61997-06-02 17:28:51 +0000153Truncate the file corresponding to file descriptor \var{fd},
154so that it is at most \var{length} bytes in size.
155\end{funcdesc}
156
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000157\begin{funcdesc}{getcwd}{}
158Return a string representing the current working directory.
159\end{funcdesc}
160
161\begin{funcdesc}{getegid}{}
Guido van Rossumeb0f0661997-12-30 20:38:16 +0000162Return the current process' effective group id.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000163(Not on MS-DOS.)
164\end{funcdesc}
165
166\begin{funcdesc}{geteuid}{}
Guido van Rossumeb0f0661997-12-30 20:38:16 +0000167Return the current process' effective user id.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000168(Not on MS-DOS.)
169\end{funcdesc}
170
171\begin{funcdesc}{getgid}{}
Guido van Rossumeb0f0661997-12-30 20:38:16 +0000172Return the current process' group id.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000173(Not on MS-DOS.)
174\end{funcdesc}
175
Guido van Rossum1e8b63e1996-06-26 19:22:46 +0000176\begin{funcdesc}{getpgrp}{}
177Return the current process group id.
178(Not on MS-DOS.)
179\end{funcdesc}
180
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000181\begin{funcdesc}{getpid}{}
182Return the current process id.
183(Not on MS-DOS.)
184\end{funcdesc}
185
186\begin{funcdesc}{getppid}{}
187Return the parent's process id.
188(Not on MS-DOS.)
189\end{funcdesc}
190
191\begin{funcdesc}{getuid}{}
Guido van Rossumeb0f0661997-12-30 20:38:16 +0000192Return the current process' user id.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000193(Not on MS-DOS.)
194\end{funcdesc}
195
Fred Drakecce10901998-03-17 06:33:25 +0000196\begin{funcdesc}{kill}{pid, sig}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000197Kill the process \var{pid} with signal \var{sig}.
198(Not on MS-DOS.)
199\end{funcdesc}
200
Fred Drakecce10901998-03-17 06:33:25 +0000201\begin{funcdesc}{link}{src, dst}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000202Create a hard link pointing to \var{src} named \var{dst}.
203(Not on MS-DOS.)
204\end{funcdesc}
205
206\begin{funcdesc}{listdir}{path}
207Return a list containing the names of the entries in the directory.
Guido van Rossum8c07bb41996-02-12 23:16:08 +0000208The list is in arbitrary order. It does not include the special
209entries \code{'.'} and \code{'..'} even if they are present in the
210directory.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000211\end{funcdesc}
212
Fred Drakecce10901998-03-17 06:33:25 +0000213\begin{funcdesc}{lseek}{fd, pos, how}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000214Set the current position of file descriptor \var{fd} to position
Fred Drake75aae9a1998-03-11 05:29:58 +0000215\var{pos}, modified by \var{how}: \code{0} to set the position
216relative to the beginning of the file; \code{1} to set it relative to
217the current position; \code{2} to set it relative to the end of the
218file.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000219\end{funcdesc}
220
221\begin{funcdesc}{lstat}{path}
Fred Drake75aae9a1998-03-11 05:29:58 +0000222Like \function{stat()}, but do not follow symbolic links. (On systems
223without symbolic links, this is identical to \function{stat()}.)
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000224\end{funcdesc}
225
Fred Drakecce10901998-03-17 06:33:25 +0000226\begin{funcdesc}{mkfifo}{path\optional{, mode}}
Fred Drake65b32f71998-02-09 20:27:12 +0000227Create a FIFO (a \POSIX{} named pipe) named \var{path} with numeric mode
Fred Drake75aae9a1998-03-11 05:29:58 +0000228\var{mode}. The default \var{mode} is \code{0666} (octal). The current
Guido van Rossum1e8b63e1996-06-26 19:22:46 +0000229umask value is first masked out from the mode.
230(Not on MS-DOS.)
231
232FIFOs are pipes that can be accessed like regular files. FIFOs exist
Fred Drake75aae9a1998-03-11 05:29:58 +0000233until they are deleted (for example with \function{os.unlink()}).
234Generally, FIFOs are used as rendezvous between ``client'' and
Guido van Rossum1e8b63e1996-06-26 19:22:46 +0000235``server'' type processes: the server opens the FIFO for reading, and
Fred Drake75aae9a1998-03-11 05:29:58 +0000236the client opens it for writing. Note that \function{mkfifo()}
237doesn't open the FIFO --- it just creates the rendezvous point.
Guido van Rossum1e8b63e1996-06-26 19:22:46 +0000238\end{funcdesc}
239
Fred Drakecce10901998-03-17 06:33:25 +0000240\begin{funcdesc}{mkdir}{path\optional{, mode}}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000241Create a directory named \var{path} with numeric mode \var{mode}.
Fred Drake75aae9a1998-03-11 05:29:58 +0000242The default \var{mode} is \code{0777} (octal). On some systems,
243\var{mode} is ignored. Where it is used, the current umask value is
244first masked out.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000245\end{funcdesc}
246
247\begin{funcdesc}{nice}{increment}
Fred Drake75aae9a1998-03-11 05:29:58 +0000248Add \var{increment} to the process' ``niceness''. Return the new
249niceness. (Not on MS-DOS.)
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000250\end{funcdesc}
251
Fred Drakecce10901998-03-17 06:33:25 +0000252\begin{funcdesc}{open}{file, flags\optional{, mode}}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000253Open the file \var{file} and set various flags according to
254\var{flags} and possibly its mode according to \var{mode}.
Fred Drake75aae9a1998-03-11 05:29:58 +0000255The default \var{mode} is \code{0777} (octal), and the current umask
256value is first masked out. Return the file descriptor for the newly
257opened file.
Guido van Rossum28379701995-01-12 12:38:22 +0000258
Fred Drake75aae9a1998-03-11 05:29:58 +0000259For a description of the flag and mode values, see the \UNIX{} or \C{}
260run-time documentation; flag constants (like \constant{O_RDONLY} and
261\constant{O_WRONLY}) are defined in this module too (see below).
Guido van Rossum9c43c591997-08-08 21:05:09 +0000262
Guido van Rossum28379701995-01-12 12:38:22 +0000263Note: this function is intended for low-level I/O. For normal usage,
Fred Drake75aae9a1998-03-11 05:29:58 +0000264use the built-in function \function{open()}, which returns a ``file
265object'' with \method{read()} and \method{write()} methods (and many
266more).
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000267\end{funcdesc}
268
269\begin{funcdesc}{pipe}{}
Fred Drake75aae9a1998-03-11 05:29:58 +0000270Create a pipe. Return a pair of file descriptors \code{(\var{r},
271\var{w})} usable for reading and writing, respectively.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000272(Not on MS-DOS.)
273\end{funcdesc}
274
Guido van Rossum38e50881996-07-21 02:21:49 +0000275\begin{funcdesc}{plock}{op}
276Lock program segments into memory. The value of \var{op}
277(defined in \code{<sys/lock.h>}) determines which segments are locked.
278(Not on MS-DOS.)
279\end{funcdesc}
280
Fred Drakecce10901998-03-17 06:33:25 +0000281\begin{funcdesc}{popen}{command\optional{, mode\optional{, bufsize}}}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000282Open a pipe to or from \var{command}. The return value is an open
283file object connected to the pipe, which can be read or written
Guido van Rossum28379701995-01-12 12:38:22 +0000284depending on whether \var{mode} is \code{'r'} (default) or \code{'w'}.
285The \var{bufsize} argument has the same meaning as the corresponding
Fred Drake75aae9a1998-03-11 05:29:58 +0000286argument to the built-in \function{open()} function. The exit status of
287the command (encoded in the format specified for \function{wait()}) is
288available as the return value of the \method{close()} method of the file
Guido van Rossum7e691de1997-05-09 02:22:59 +0000289object.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000290(Not on MS-DOS.)
291\end{funcdesc}
292
Fred Drakecce10901998-03-17 06:33:25 +0000293\begin{funcdesc}{putenv}{varname, value}
Fred Drake52405c81998-03-16 05:21:08 +0000294\index{environment variables!setting}
Fred Drake75aae9a1998-03-11 05:29:58 +0000295Set the environment variable named \var{varname} to the string
296\var{value}. Such changes to the environment affect subprocesses
297started with \function{os.system()}, \function{os.popen()} or
298\function{os.fork()} and \function{os.execv()}. (Not on all systems.)
Guido van Rossumf967bf61997-06-02 17:28:51 +0000299
Fred Drake75aae9a1998-03-11 05:29:58 +0000300When \function{putenv()} is
Guido van Rossumf967bf61997-06-02 17:28:51 +0000301supported, assignments to items in \code{os.environ} are automatically
Fred Drake75aae9a1998-03-11 05:29:58 +0000302translated into corresponding calls to \function{putenv()}; however,
303calls to \function{putenv()} don't update \code{os.environ}, so it is
Guido van Rossumf967bf61997-06-02 17:28:51 +0000304actually preferable to assign to items of \code{os.environ}.
305\end{funcdesc}
306
Guido van Rossum0bfd1461997-10-05 18:54:52 +0000307\begin{funcdesc}{strerror}{code}
308Return the error message corresponding to the error code in \var{code}.
309\end{funcdesc}
310
Fred Drakecce10901998-03-17 06:33:25 +0000311\begin{funcdesc}{read}{fd, n}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000312Read at most \var{n} bytes from file descriptor \var{fd}.
313Return a string containing the bytes read.
Guido van Rossum28379701995-01-12 12:38:22 +0000314
315Note: this function is intended for low-level I/O and must be applied
Fred Drake75aae9a1998-03-11 05:29:58 +0000316to a file descriptor as returned by \function{open()} or
317\function{pipe()}. To read a ``file object'' returned by the
318built-in function \function{open()} or by \function{popen()} or
319\function{fdopen()}, or \code{sys.stdin}, use its
320\method{read()} or \method{readline()} methods.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000321\end{funcdesc}
322
323\begin{funcdesc}{readlink}{path}
324Return a string representing the path to which the symbolic link
325points. (On systems without symbolic links, this always raises
Fred Drake75aae9a1998-03-11 05:29:58 +0000326\exception{error}.)
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000327\end{funcdesc}
328
Guido van Rossum8c07bb41996-02-12 23:16:08 +0000329\begin{funcdesc}{remove}{path}
Fred Drake75aae9a1998-03-11 05:29:58 +0000330Remove the file \var{path}. See \function{rmdir()} below to remove a
331directory. This is identical to the \function{unlink()} function
332documented below.
Guido van Rossum8c07bb41996-02-12 23:16:08 +0000333\end{funcdesc}
334
Fred Drakecce10901998-03-17 06:33:25 +0000335\begin{funcdesc}{rename}{src, dst}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000336Rename the file or directory \var{src} to \var{dst}.
337\end{funcdesc}
338
339\begin{funcdesc}{rmdir}{path}
340Remove the directory \var{path}.
341\end{funcdesc}
342
343\begin{funcdesc}{setgid}{gid}
Guido van Rossumeb0f0661997-12-30 20:38:16 +0000344Set the current process' group id.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000345(Not on MS-DOS.)
346\end{funcdesc}
347
Guido van Rossum1e8b63e1996-06-26 19:22:46 +0000348\begin{funcdesc}{setpgrp}{}
Fred Drake75aae9a1998-03-11 05:29:58 +0000349Calls the system call \cfunction{setpgrp()} or \cfunction{setpgrp(0,
3500)} depending on which version is implemented (if any). See the
351\UNIX{} manual for the semantics.
Guido van Rossum1e8b63e1996-06-26 19:22:46 +0000352(Not on MS-DOS.)
353\end{funcdesc}
354
Fred Drakecce10901998-03-17 06:33:25 +0000355\begin{funcdesc}{setpgid}{pid, pgrp}
Fred Drake75aae9a1998-03-11 05:29:58 +0000356Calls the system call \cfunction{setpgid()}. See the \UNIX{} manual
357for the semantics.
Guido van Rossum1e8b63e1996-06-26 19:22:46 +0000358(Not on MS-DOS.)
359\end{funcdesc}
360
361\begin{funcdesc}{setsid}{}
Fred Drake75aae9a1998-03-11 05:29:58 +0000362Calls the system call \cfunction{setsid()}. See the \UNIX{} manual
363for the semantics.
Guido van Rossum1e8b63e1996-06-26 19:22:46 +0000364(Not on MS-DOS.)
365\end{funcdesc}
366
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000367\begin{funcdesc}{setuid}{uid}
Guido van Rossumeb0f0661997-12-30 20:38:16 +0000368Set the current process' user id.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000369(Not on MS-DOS.)
370\end{funcdesc}
371
372\begin{funcdesc}{stat}{path}
Fred Drake75aae9a1998-03-11 05:29:58 +0000373Perform a \cfunction{stat()} system call on the given path. The
374return value is a tuple of at least 10 integers giving the most
375important (and portable) members of the \emph{stat} structure, in the
376order
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000377\code{st_mode},
378\code{st_ino},
379\code{st_dev},
380\code{st_nlink},
381\code{st_uid},
382\code{st_gid},
383\code{st_size},
384\code{st_atime},
385\code{st_mtime},
386\code{st_ctime}.
387More items may be added at the end by some implementations.
388(On MS-DOS, some items are filled with dummy values.)
389
Fred Drake75aae9a1998-03-11 05:29:58 +0000390Note: The standard module \module{stat}\refstmodindex{stat} defines
391functions and constants that are useful for extracting information
392from a stat structure.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000393\end{funcdesc}
394
Fred Drakecce10901998-03-17 06:33:25 +0000395\begin{funcdesc}{symlink}{src, dst}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000396Create a symbolic link pointing to \var{src} named \var{dst}. (On
Fred Drake75aae9a1998-03-11 05:29:58 +0000397systems without symbolic links, this always raises \exception{error}.)
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000398\end{funcdesc}
399
400\begin{funcdesc}{system}{command}
401Execute the command (a string) in a subshell. This is implemented by
Fred Drake75aae9a1998-03-11 05:29:58 +0000402calling the Standard \C{} function \cfunction{system()}, and has the
403same limitations. Changes to \code{posix.environ}, \code{sys.stdin}
404etc.\ are not reflected in the environment of the executed command.
405The return value is the exit status of the process encoded in the
406format specified for \function{wait()}.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000407\end{funcdesc}
408
Guido van Rossum1e8b63e1996-06-26 19:22:46 +0000409\begin{funcdesc}{tcgetpgrp}{fd}
410Return the process group associated with the terminal given by
Fred Drake75aae9a1998-03-11 05:29:58 +0000411\var{fd} (an open file descriptor as returned by \function{open()}).
Guido van Rossum1e8b63e1996-06-26 19:22:46 +0000412(Not on MS-DOS.)
413\end{funcdesc}
414
Fred Drakecce10901998-03-17 06:33:25 +0000415\begin{funcdesc}{tcsetpgrp}{fd, pg}
Guido van Rossum1e8b63e1996-06-26 19:22:46 +0000416Set the process group associated with the terminal given by
Fred Drake75aae9a1998-03-11 05:29:58 +0000417\var{fd} (an open file descriptor as returned by \function{open()})
Guido van Rossum1e8b63e1996-06-26 19:22:46 +0000418to \var{pg}.
419(Not on MS-DOS.)
420\end{funcdesc}
421
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000422\begin{funcdesc}{times}{}
Guido van Rossum1e150611995-09-13 17:36:35 +0000423Return a 5-tuple of floating point numbers indicating accumulated (CPU
424or other)
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000425times, in seconds. The items are: user time, system time, children's
Guido van Rossum1e150611995-09-13 17:36:35 +0000426user time, children's system time, and elapsed real time since a fixed
427point in the past, in that order. See the \UNIX{}
Fred Drake75aae9a1998-03-11 05:29:58 +0000428manual page \manpage{times}{2}. (Not on MS-DOS.)
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000429\end{funcdesc}
430
431\begin{funcdesc}{umask}{mask}
432Set the current numeric umask and returns the previous umask.
433(Not on MS-DOS.)
434\end{funcdesc}
435
436\begin{funcdesc}{uname}{}
437Return a 5-tuple containing information identifying the current
438operating system. The tuple contains 5 strings:
Fred Drake75aae9a1998-03-11 05:29:58 +0000439\code{(\var{sysname}, \var{nodename}, \var{release}, \var{version},
440\var{machine})}. Some systems truncate the nodename to 8
Guido van Rossum6bb1adc1995-03-13 10:03:32 +0000441characters or to the leading component; a better way to get the
Fred Drake75aae9a1998-03-11 05:29:58 +0000442hostname is \function{socket.gethostname()}%
Fred Drake371ecc01998-03-12 06:44:58 +0000443\withsubitem{(in module socket)}{\ttindex{gethostname()}}
Fred Drake75aae9a1998-03-11 05:29:58 +0000444or even
445\code{socket.gethostbyaddr(socket.gethostname())}%
Fred Drake371ecc01998-03-12 06:44:58 +0000446\withsubitem{(in module socket)}{\ttindex{gethostbyaddr()}}.
Guido van Rossumeb0f0661997-12-30 20:38:16 +0000447(Not on MS-DOS, nor on older \UNIX{} systems.)
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000448\end{funcdesc}
449
450\begin{funcdesc}{unlink}{path}
Guido van Rossum8c07bb41996-02-12 23:16:08 +0000451Remove the file \var{path}. This is the same function as \code{remove};
452the \code{unlink} name is its traditional \UNIX{} name.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000453\end{funcdesc}
454
Fred Drakecce10901998-03-17 06:33:25 +0000455\begin{funcdesc}{utime}{path, {\rm (}atime, mtime{\rm )}}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000456Set the access and modified time of the file to the given values.
457(The second argument is a tuple of two items.)
458\end{funcdesc}
459
460\begin{funcdesc}{wait}{}
461Wait for completion of a child process, and return a tuple containing
Guido van Rossum7e691de1997-05-09 02:22:59 +0000462its pid and exit status indication: a 16-bit number, whose low byte is
463the signal number that killed the process, and whose high byte is the
464exit status (if the signal number is zero); the high bit of the low
465byte is set if a core file was produced. (Not on MS-DOS.)
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000466\end{funcdesc}
467
Fred Drakecce10901998-03-17 06:33:25 +0000468\begin{funcdesc}{waitpid}{pid, options}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000469Wait for completion of a child process given by proces id, and return
Guido van Rossum7e691de1997-05-09 02:22:59 +0000470a tuple containing its pid and exit status indication (encoded as for
Fred Drake75aae9a1998-03-11 05:29:58 +0000471\function{wait()}). The semantics of the call are affected by the
472value of the integer \var{options}, which should be \code{0} for
473normal operation. (If the system does not support
474\function{waitpid()}, this always raises \exception{error}. Not on
475MS-DOS.)
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000476\end{funcdesc}
477
Fred Drakecce10901998-03-17 06:33:25 +0000478\begin{funcdesc}{write}{fd, str}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000479Write the string \var{str} to file descriptor \var{fd}.
480Return the number of bytes actually written.
Guido van Rossum28379701995-01-12 12:38:22 +0000481
482Note: this function is intended for low-level I/O and must be applied
Fred Drake75aae9a1998-03-11 05:29:58 +0000483to a file descriptor as returned by \function{open()} or
484\function{pipe()}. To write a ``file object'' returned by the
485built-in function \function{open()} or by \function{popen()} or
486\function{fdopen()}, or \code{sys.stdout} or \code{sys.stderr}, use
487its \method{write()} method.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000488\end{funcdesc}
Guido van Rossum4bbe9c01995-03-30 16:00:36 +0000489
490\begin{datadesc}{WNOHANG}
Fred Drake75aae9a1998-03-11 05:29:58 +0000491The option for \function{waitpid()} to avoid hanging if no child
492process status is available immediately.
Guido van Rossum4bbe9c01995-03-30 16:00:36 +0000493\end{datadesc}
Barry Warsawe5a43a41996-12-19 23:50:34 +0000494
495
496\begin{datadesc}{O_RDONLY}
Fred Drake86b5dce1998-02-13 21:55:21 +0000497\dataline{O_WRONLY}
498\dataline{O_RDWR}
499\dataline{O_NDELAY}
500\dataline{O_NONBLOCK}
501\dataline{O_APPEND}
502\dataline{O_DSYNC}
503\dataline{O_RSYNC}
504\dataline{O_SYNC}
505\dataline{O_NOCTTY}
506\dataline{O_CREAT}
507\dataline{O_EXCL}
508\dataline{O_TRUNC}
Fred Drake75aae9a1998-03-11 05:29:58 +0000509Options for the \code{flag} argument to the \function{open()} function.
Barry Warsawe5a43a41996-12-19 23:50:34 +0000510These can be bit-wise OR'd together.
511\end{datadesc}