blob: 101938da9ad3246ac8327e9422385b7aa1a3e879 [file] [log] [blame]
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00001\section{Built-in Module \sectcode{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
Fred Drake19479911998-02-13 06:58:54 +000077\setindexsubitem{(in module posix)}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000078\begin{funcdesc}{chdir}{path}
79Change the current working directory to \var{path}.
80\end{funcdesc}
81
Fred Drakecce10901998-03-17 06:33:25 +000082\begin{funcdesc}{chmod}{path, mode}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000083Change the mode of \var{path} to the numeric \var{mode}.
84\end{funcdesc}
85
Fred Drakecce10901998-03-17 06:33:25 +000086\begin{funcdesc}{chown}{path, uid, gid}
Guido van Rossum31cce971995-01-04 19:17:34 +000087Change the owner and group id of \var{path} to the numeric \var{uid}
88and \var{gid}.
89(Not on MS-DOS.)
90\end{funcdesc}
91
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000092\begin{funcdesc}{close}{fd}
93Close file descriptor \var{fd}.
Guido van Rossum28379701995-01-12 12:38:22 +000094
95Note: this function is intended for low-level I/O and must be applied
Fred Drake75aae9a1998-03-11 05:29:58 +000096to a file descriptor as returned by \function{open()} or
97\function{pipe()}. To close a ``file object'' returned by the
98built-in function \function{open()} or by \function{popen()} or
99\function{fdopen()}, use its \method{close()} method.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000100\end{funcdesc}
101
102\begin{funcdesc}{dup}{fd}
103Return a duplicate of file descriptor \var{fd}.
104\end{funcdesc}
105
Fred Drakecce10901998-03-17 06:33:25 +0000106\begin{funcdesc}{dup2}{fd, fd2}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000107Duplicate file descriptor \var{fd} to \var{fd2}, closing the latter
Fred Drake75aae9a1998-03-11 05:29:58 +0000108first if necessary.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000109\end{funcdesc}
110
Fred Drakecce10901998-03-17 06:33:25 +0000111\begin{funcdesc}{execv}{path, args}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000112Execute the executable \var{path} with argument list \var{args},
113replacing the current process (i.e., the Python interpreter).
114The argument list may be a tuple or list of strings.
115(Not on MS-DOS.)
116\end{funcdesc}
117
Fred Drakecce10901998-03-17 06:33:25 +0000118\begin{funcdesc}{execve}{path, args, env}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000119Execute the executable \var{path} with argument list \var{args},
120and environment \var{env},
121replacing the current process (i.e., the Python interpreter).
122The argument list may be a tuple or list of strings.
123The environment must be a dictionary mapping strings to strings.
124(Not on MS-DOS.)
125\end{funcdesc}
126
127\begin{funcdesc}{_exit}{n}
128Exit to the system with status \var{n}, without calling cleanup
129handlers, flushing stdio buffers, etc.
130(Not on MS-DOS.)
131
132Note: the standard way to exit is \code{sys.exit(\var{n})}.
Fred Drake75aae9a1998-03-11 05:29:58 +0000133\function{_exit()} should normally only be used in the child process
134after a \function{fork()}.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000135\end{funcdesc}
136
Fred Drakecce10901998-03-17 06:33:25 +0000137\begin{funcdesc}{fdopen}{fd\optional{, mode\optional{, bufsize}}}
Guido van Rossum28379701995-01-12 12:38:22 +0000138Return an open file object connected to the file descriptor \var{fd}.
139The \var{mode} and \var{bufsize} arguments have the same meaning as
Fred Drake75aae9a1998-03-11 05:29:58 +0000140the corresponding arguments to the built-in \function{open()} function.
Guido van Rossumc5c67bc1994-02-15 15:59:23 +0000141\end{funcdesc}
142
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000143\begin{funcdesc}{fork}{}
Fred Drake75aae9a1998-03-11 05:29:58 +0000144Fork a child process. Return \code{0} in the child, the child's
145process id in the parent.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000146(Not on MS-DOS.)
147\end{funcdesc}
148
149\begin{funcdesc}{fstat}{fd}
Fred Drake75aae9a1998-03-11 05:29:58 +0000150Return status for file descriptor \var{fd}, like \function{stat()}.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000151\end{funcdesc}
152
Fred Drakecce10901998-03-17 06:33:25 +0000153\begin{funcdesc}{ftruncate}{fd, length}
Guido van Rossumf967bf61997-06-02 17:28:51 +0000154Truncate the file corresponding to file descriptor \var{fd},
155so that it is at most \var{length} bytes in size.
156\end{funcdesc}
157
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000158\begin{funcdesc}{getcwd}{}
159Return a string representing the current working directory.
160\end{funcdesc}
161
162\begin{funcdesc}{getegid}{}
Guido van Rossumeb0f0661997-12-30 20:38:16 +0000163Return the current process' effective group id.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000164(Not on MS-DOS.)
165\end{funcdesc}
166
167\begin{funcdesc}{geteuid}{}
Guido van Rossumeb0f0661997-12-30 20:38:16 +0000168Return the current process' effective user id.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000169(Not on MS-DOS.)
170\end{funcdesc}
171
172\begin{funcdesc}{getgid}{}
Guido van Rossumeb0f0661997-12-30 20:38:16 +0000173Return the current process' group id.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000174(Not on MS-DOS.)
175\end{funcdesc}
176
Guido van Rossum1e8b63e1996-06-26 19:22:46 +0000177\begin{funcdesc}{getpgrp}{}
178Return the current process group id.
179(Not on MS-DOS.)
180\end{funcdesc}
181
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000182\begin{funcdesc}{getpid}{}
183Return the current process id.
184(Not on MS-DOS.)
185\end{funcdesc}
186
187\begin{funcdesc}{getppid}{}
188Return the parent's process id.
189(Not on MS-DOS.)
190\end{funcdesc}
191
192\begin{funcdesc}{getuid}{}
Guido van Rossumeb0f0661997-12-30 20:38:16 +0000193Return the current process' user id.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000194(Not on MS-DOS.)
195\end{funcdesc}
196
Fred Drakecce10901998-03-17 06:33:25 +0000197\begin{funcdesc}{kill}{pid, sig}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000198Kill the process \var{pid} with signal \var{sig}.
199(Not on MS-DOS.)
200\end{funcdesc}
201
Fred Drakecce10901998-03-17 06:33:25 +0000202\begin{funcdesc}{link}{src, dst}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000203Create a hard link pointing to \var{src} named \var{dst}.
204(Not on MS-DOS.)
205\end{funcdesc}
206
207\begin{funcdesc}{listdir}{path}
208Return a list containing the names of the entries in the directory.
Guido van Rossum8c07bb41996-02-12 23:16:08 +0000209The list is in arbitrary order. It does not include the special
210entries \code{'.'} and \code{'..'} even if they are present in the
211directory.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000212\end{funcdesc}
213
Fred Drakecce10901998-03-17 06:33:25 +0000214\begin{funcdesc}{lseek}{fd, pos, how}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000215Set the current position of file descriptor \var{fd} to position
Fred Drake75aae9a1998-03-11 05:29:58 +0000216\var{pos}, modified by \var{how}: \code{0} to set the position
217relative to the beginning of the file; \code{1} to set it relative to
218the current position; \code{2} to set it relative to the end of the
219file.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000220\end{funcdesc}
221
222\begin{funcdesc}{lstat}{path}
Fred Drake75aae9a1998-03-11 05:29:58 +0000223Like \function{stat()}, but do not follow symbolic links. (On systems
224without symbolic links, this is identical to \function{stat()}.)
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000225\end{funcdesc}
226
Fred Drakecce10901998-03-17 06:33:25 +0000227\begin{funcdesc}{mkfifo}{path\optional{, mode}}
Fred Drake65b32f71998-02-09 20:27:12 +0000228Create a FIFO (a \POSIX{} named pipe) named \var{path} with numeric mode
Fred Drake75aae9a1998-03-11 05:29:58 +0000229\var{mode}. The default \var{mode} is \code{0666} (octal). The current
Guido van Rossum1e8b63e1996-06-26 19:22:46 +0000230umask value is first masked out from the mode.
231(Not on MS-DOS.)
232
233FIFOs are pipes that can be accessed like regular files. FIFOs exist
Fred Drake75aae9a1998-03-11 05:29:58 +0000234until they are deleted (for example with \function{os.unlink()}).
235Generally, FIFOs are used as rendezvous between ``client'' and
Guido van Rossum1e8b63e1996-06-26 19:22:46 +0000236``server'' type processes: the server opens the FIFO for reading, and
Fred Drake75aae9a1998-03-11 05:29:58 +0000237the client opens it for writing. Note that \function{mkfifo()}
238doesn't open the FIFO --- it just creates the rendezvous point.
Guido van Rossum1e8b63e1996-06-26 19:22:46 +0000239\end{funcdesc}
240
Fred Drakecce10901998-03-17 06:33:25 +0000241\begin{funcdesc}{mkdir}{path\optional{, mode}}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000242Create a directory named \var{path} with numeric mode \var{mode}.
Fred Drake75aae9a1998-03-11 05:29:58 +0000243The default \var{mode} is \code{0777} (octal). On some systems,
244\var{mode} is ignored. Where it is used, the current umask value is
245first masked out.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000246\end{funcdesc}
247
248\begin{funcdesc}{nice}{increment}
Fred Drake75aae9a1998-03-11 05:29:58 +0000249Add \var{increment} to the process' ``niceness''. Return the new
250niceness. (Not on MS-DOS.)
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000251\end{funcdesc}
252
Fred Drakecce10901998-03-17 06:33:25 +0000253\begin{funcdesc}{open}{file, flags\optional{, mode}}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000254Open the file \var{file} and set various flags according to
255\var{flags} and possibly its mode according to \var{mode}.
Fred Drake75aae9a1998-03-11 05:29:58 +0000256The default \var{mode} is \code{0777} (octal), and the current umask
257value is first masked out. Return the file descriptor for the newly
258opened file.
Guido van Rossum28379701995-01-12 12:38:22 +0000259
Fred Drake75aae9a1998-03-11 05:29:58 +0000260For a description of the flag and mode values, see the \UNIX{} or \C{}
261run-time documentation; flag constants (like \constant{O_RDONLY} and
262\constant{O_WRONLY}) are defined in this module too (see below).
Guido van Rossum9c43c591997-08-08 21:05:09 +0000263
Guido van Rossum28379701995-01-12 12:38:22 +0000264Note: this function is intended for low-level I/O. For normal usage,
Fred Drake75aae9a1998-03-11 05:29:58 +0000265use the built-in function \function{open()}, which returns a ``file
266object'' with \method{read()} and \method{write()} methods (and many
267more).
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000268\end{funcdesc}
269
270\begin{funcdesc}{pipe}{}
Fred Drake75aae9a1998-03-11 05:29:58 +0000271Create a pipe. Return a pair of file descriptors \code{(\var{r},
272\var{w})} usable for reading and writing, respectively.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000273(Not on MS-DOS.)
274\end{funcdesc}
275
Guido van Rossum38e50881996-07-21 02:21:49 +0000276\begin{funcdesc}{plock}{op}
277Lock program segments into memory. The value of \var{op}
278(defined in \code{<sys/lock.h>}) determines which segments are locked.
279(Not on MS-DOS.)
280\end{funcdesc}
281
Fred Drakecce10901998-03-17 06:33:25 +0000282\begin{funcdesc}{popen}{command\optional{, mode\optional{, bufsize}}}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000283Open a pipe to or from \var{command}. The return value is an open
284file object connected to the pipe, which can be read or written
Guido van Rossum28379701995-01-12 12:38:22 +0000285depending on whether \var{mode} is \code{'r'} (default) or \code{'w'}.
286The \var{bufsize} argument has the same meaning as the corresponding
Fred Drake75aae9a1998-03-11 05:29:58 +0000287argument to the built-in \function{open()} function. The exit status of
288the command (encoded in the format specified for \function{wait()}) is
289available as the return value of the \method{close()} method of the file
Guido van Rossum7e691de1997-05-09 02:22:59 +0000290object.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000291(Not on MS-DOS.)
292\end{funcdesc}
293
Fred Drakecce10901998-03-17 06:33:25 +0000294\begin{funcdesc}{putenv}{varname, value}
Fred Drake52405c81998-03-16 05:21:08 +0000295\index{environment variables!setting}
Fred Drake75aae9a1998-03-11 05:29:58 +0000296Set the environment variable named \var{varname} to the string
297\var{value}. Such changes to the environment affect subprocesses
298started with \function{os.system()}, \function{os.popen()} or
299\function{os.fork()} and \function{os.execv()}. (Not on all systems.)
Guido van Rossumf967bf61997-06-02 17:28:51 +0000300
Fred Drake75aae9a1998-03-11 05:29:58 +0000301When \function{putenv()} is
Guido van Rossumf967bf61997-06-02 17:28:51 +0000302supported, assignments to items in \code{os.environ} are automatically
Fred Drake75aae9a1998-03-11 05:29:58 +0000303translated into corresponding calls to \function{putenv()}; however,
304calls to \function{putenv()} don't update \code{os.environ}, so it is
Guido van Rossumf967bf61997-06-02 17:28:51 +0000305actually preferable to assign to items of \code{os.environ}.
306\end{funcdesc}
307
Guido van Rossum0bfd1461997-10-05 18:54:52 +0000308\begin{funcdesc}{strerror}{code}
309Return the error message corresponding to the error code in \var{code}.
310\end{funcdesc}
311
Fred Drakecce10901998-03-17 06:33:25 +0000312\begin{funcdesc}{read}{fd, n}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000313Read at most \var{n} bytes from file descriptor \var{fd}.
314Return a string containing the bytes read.
Guido van Rossum28379701995-01-12 12:38:22 +0000315
316Note: this function is intended for low-level I/O and must be applied
Fred Drake75aae9a1998-03-11 05:29:58 +0000317to a file descriptor as returned by \function{open()} or
318\function{pipe()}. To read a ``file object'' returned by the
319built-in function \function{open()} or by \function{popen()} or
320\function{fdopen()}, or \code{sys.stdin}, use its
321\method{read()} or \method{readline()} methods.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000322\end{funcdesc}
323
324\begin{funcdesc}{readlink}{path}
325Return a string representing the path to which the symbolic link
326points. (On systems without symbolic links, this always raises
Fred Drake75aae9a1998-03-11 05:29:58 +0000327\exception{error}.)
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000328\end{funcdesc}
329
Guido van Rossum8c07bb41996-02-12 23:16:08 +0000330\begin{funcdesc}{remove}{path}
Fred Drake75aae9a1998-03-11 05:29:58 +0000331Remove the file \var{path}. See \function{rmdir()} below to remove a
332directory. This is identical to the \function{unlink()} function
333documented below.
Guido van Rossum8c07bb41996-02-12 23:16:08 +0000334\end{funcdesc}
335
Fred Drakecce10901998-03-17 06:33:25 +0000336\begin{funcdesc}{rename}{src, dst}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000337Rename the file or directory \var{src} to \var{dst}.
338\end{funcdesc}
339
340\begin{funcdesc}{rmdir}{path}
341Remove the directory \var{path}.
342\end{funcdesc}
343
344\begin{funcdesc}{setgid}{gid}
Guido van Rossumeb0f0661997-12-30 20:38:16 +0000345Set the current process' group id.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000346(Not on MS-DOS.)
347\end{funcdesc}
348
Guido van Rossum1e8b63e1996-06-26 19:22:46 +0000349\begin{funcdesc}{setpgrp}{}
Fred Drake75aae9a1998-03-11 05:29:58 +0000350Calls the system call \cfunction{setpgrp()} or \cfunction{setpgrp(0,
3510)} depending on which version is implemented (if any). See the
352\UNIX{} manual for the semantics.
Guido van Rossum1e8b63e1996-06-26 19:22:46 +0000353(Not on MS-DOS.)
354\end{funcdesc}
355
Fred Drakecce10901998-03-17 06:33:25 +0000356\begin{funcdesc}{setpgid}{pid, pgrp}
Fred Drake75aae9a1998-03-11 05:29:58 +0000357Calls the system call \cfunction{setpgid()}. See the \UNIX{} manual
358for the semantics.
Guido van Rossum1e8b63e1996-06-26 19:22:46 +0000359(Not on MS-DOS.)
360\end{funcdesc}
361
362\begin{funcdesc}{setsid}{}
Fred Drake75aae9a1998-03-11 05:29:58 +0000363Calls the system call \cfunction{setsid()}. See the \UNIX{} manual
364for the semantics.
Guido van Rossum1e8b63e1996-06-26 19:22:46 +0000365(Not on MS-DOS.)
366\end{funcdesc}
367
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000368\begin{funcdesc}{setuid}{uid}
Guido van Rossumeb0f0661997-12-30 20:38:16 +0000369Set the current process' user id.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000370(Not on MS-DOS.)
371\end{funcdesc}
372
373\begin{funcdesc}{stat}{path}
Fred Drake75aae9a1998-03-11 05:29:58 +0000374Perform a \cfunction{stat()} system call on the given path. The
375return value is a tuple of at least 10 integers giving the most
376important (and portable) members of the \emph{stat} structure, in the
377order
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000378\code{st_mode},
379\code{st_ino},
380\code{st_dev},
381\code{st_nlink},
382\code{st_uid},
383\code{st_gid},
384\code{st_size},
385\code{st_atime},
386\code{st_mtime},
387\code{st_ctime}.
388More items may be added at the end by some implementations.
389(On MS-DOS, some items are filled with dummy values.)
390
Fred Drake75aae9a1998-03-11 05:29:58 +0000391Note: The standard module \module{stat}\refstmodindex{stat} defines
392functions and constants that are useful for extracting information
393from a stat structure.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000394\end{funcdesc}
395
Fred Drakecce10901998-03-17 06:33:25 +0000396\begin{funcdesc}{symlink}{src, dst}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000397Create a symbolic link pointing to \var{src} named \var{dst}. (On
Fred Drake75aae9a1998-03-11 05:29:58 +0000398systems without symbolic links, this always raises \exception{error}.)
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000399\end{funcdesc}
400
401\begin{funcdesc}{system}{command}
402Execute the command (a string) in a subshell. This is implemented by
Fred Drake75aae9a1998-03-11 05:29:58 +0000403calling the Standard \C{} function \cfunction{system()}, and has the
404same limitations. Changes to \code{posix.environ}, \code{sys.stdin}
405etc.\ are not reflected in the environment of the executed command.
406The return value is the exit status of the process encoded in the
407format specified for \function{wait()}.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000408\end{funcdesc}
409
Guido van Rossum1e8b63e1996-06-26 19:22:46 +0000410\begin{funcdesc}{tcgetpgrp}{fd}
411Return the process group associated with the terminal given by
Fred Drake75aae9a1998-03-11 05:29:58 +0000412\var{fd} (an open file descriptor as returned by \function{open()}).
Guido van Rossum1e8b63e1996-06-26 19:22:46 +0000413(Not on MS-DOS.)
414\end{funcdesc}
415
Fred Drakecce10901998-03-17 06:33:25 +0000416\begin{funcdesc}{tcsetpgrp}{fd, pg}
Guido van Rossum1e8b63e1996-06-26 19:22:46 +0000417Set the process group associated with the terminal given by
Fred Drake75aae9a1998-03-11 05:29:58 +0000418\var{fd} (an open file descriptor as returned by \function{open()})
Guido van Rossum1e8b63e1996-06-26 19:22:46 +0000419to \var{pg}.
420(Not on MS-DOS.)
421\end{funcdesc}
422
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000423\begin{funcdesc}{times}{}
Guido van Rossum1e150611995-09-13 17:36:35 +0000424Return a 5-tuple of floating point numbers indicating accumulated (CPU
425or other)
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000426times, in seconds. The items are: user time, system time, children's
Guido van Rossum1e150611995-09-13 17:36:35 +0000427user time, children's system time, and elapsed real time since a fixed
428point in the past, in that order. See the \UNIX{}
Fred Drake75aae9a1998-03-11 05:29:58 +0000429manual page \manpage{times}{2}. (Not on MS-DOS.)
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000430\end{funcdesc}
431
432\begin{funcdesc}{umask}{mask}
433Set the current numeric umask and returns the previous umask.
434(Not on MS-DOS.)
435\end{funcdesc}
436
437\begin{funcdesc}{uname}{}
438Return a 5-tuple containing information identifying the current
439operating system. The tuple contains 5 strings:
Fred Drake75aae9a1998-03-11 05:29:58 +0000440\code{(\var{sysname}, \var{nodename}, \var{release}, \var{version},
441\var{machine})}. Some systems truncate the nodename to 8
Guido van Rossum6bb1adc1995-03-13 10:03:32 +0000442characters or to the leading component; a better way to get the
Fred Drake75aae9a1998-03-11 05:29:58 +0000443hostname is \function{socket.gethostname()}%
Fred Drake371ecc01998-03-12 06:44:58 +0000444\withsubitem{(in module socket)}{\ttindex{gethostname()}}
Fred Drake75aae9a1998-03-11 05:29:58 +0000445or even
446\code{socket.gethostbyaddr(socket.gethostname())}%
Fred Drake371ecc01998-03-12 06:44:58 +0000447\withsubitem{(in module socket)}{\ttindex{gethostbyaddr()}}.
Guido van Rossumeb0f0661997-12-30 20:38:16 +0000448(Not on MS-DOS, nor on older \UNIX{} systems.)
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000449\end{funcdesc}
450
451\begin{funcdesc}{unlink}{path}
Guido van Rossum8c07bb41996-02-12 23:16:08 +0000452Remove the file \var{path}. This is the same function as \code{remove};
453the \code{unlink} name is its traditional \UNIX{} name.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000454\end{funcdesc}
455
Fred Drakecce10901998-03-17 06:33:25 +0000456\begin{funcdesc}{utime}{path, {\rm (}atime, mtime{\rm )}}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000457Set the access and modified time of the file to the given values.
458(The second argument is a tuple of two items.)
459\end{funcdesc}
460
461\begin{funcdesc}{wait}{}
462Wait for completion of a child process, and return a tuple containing
Guido van Rossum7e691de1997-05-09 02:22:59 +0000463its pid and exit status indication: a 16-bit number, whose low byte is
464the signal number that killed the process, and whose high byte is the
465exit status (if the signal number is zero); the high bit of the low
466byte is set if a core file was produced. (Not on MS-DOS.)
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000467\end{funcdesc}
468
Fred Drakecce10901998-03-17 06:33:25 +0000469\begin{funcdesc}{waitpid}{pid, options}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000470Wait for completion of a child process given by proces id, and return
Guido van Rossum7e691de1997-05-09 02:22:59 +0000471a tuple containing its pid and exit status indication (encoded as for
Fred Drake75aae9a1998-03-11 05:29:58 +0000472\function{wait()}). The semantics of the call are affected by the
473value of the integer \var{options}, which should be \code{0} for
474normal operation. (If the system does not support
475\function{waitpid()}, this always raises \exception{error}. Not on
476MS-DOS.)
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000477\end{funcdesc}
478
Fred Drakecce10901998-03-17 06:33:25 +0000479\begin{funcdesc}{write}{fd, str}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000480Write the string \var{str} to file descriptor \var{fd}.
481Return the number of bytes actually written.
Guido van Rossum28379701995-01-12 12:38:22 +0000482
483Note: this function is intended for low-level I/O and must be applied
Fred Drake75aae9a1998-03-11 05:29:58 +0000484to a file descriptor as returned by \function{open()} or
485\function{pipe()}. To write a ``file object'' returned by the
486built-in function \function{open()} or by \function{popen()} or
487\function{fdopen()}, or \code{sys.stdout} or \code{sys.stderr}, use
488its \method{write()} method.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000489\end{funcdesc}
Guido van Rossum4bbe9c01995-03-30 16:00:36 +0000490
491\begin{datadesc}{WNOHANG}
Fred Drake75aae9a1998-03-11 05:29:58 +0000492The option for \function{waitpid()} to avoid hanging if no child
493process status is available immediately.
Guido van Rossum4bbe9c01995-03-30 16:00:36 +0000494\end{datadesc}
Barry Warsawe5a43a41996-12-19 23:50:34 +0000495
496
497\begin{datadesc}{O_RDONLY}
Fred Drake86b5dce1998-02-13 21:55:21 +0000498\dataline{O_WRONLY}
499\dataline{O_RDWR}
500\dataline{O_NDELAY}
501\dataline{O_NONBLOCK}
502\dataline{O_APPEND}
503\dataline{O_DSYNC}
504\dataline{O_RSYNC}
505\dataline{O_SYNC}
506\dataline{O_NOCTTY}
507\dataline{O_CREAT}
508\dataline{O_EXCL}
509\dataline{O_TRUNC}
Fred Drake75aae9a1998-03-11 05:29:58 +0000510Options for the \code{flag} argument to the \function{open()} function.
Barry Warsawe5a43a41996-12-19 23:50:34 +0000511These can be bit-wise OR'd together.
512\end{datadesc}