blob: dbfc69224adfefeffc76dd43243788312f8da702 [file] [log] [blame]
Fred Drake3a0351c1998-04-04 07:23:21 +00001\section{Built-in Module \module{posix}}
Fred Drakeb91e9341998-07-23 17:59:49 +00002\declaremodule{builtin}{posix}
3
4\modulesynopsis{The most common \POSIX{} system calls (normally used via module
5\module{os}).}
6
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00007
8This module provides access to operating system functionality that is
Fred Drake75aae9a1998-03-11 05:29:58 +00009standardized by the \C{} Standard and the \POSIX{} standard (a thinly
10disguised \UNIX{} interface).
Guido van Rossum470be141995-03-17 16:07:09 +000011
12\strong{Do not import this module directly.} Instead, import the
Fred Drake75aae9a1998-03-11 05:29:58 +000013module \module{os}, which provides a \emph{portable} version of this
14interface. On \UNIX{}, the \module{os} module provides a superset of
15the \module{posix} interface. On non-\UNIX{} operating systems the
16\module{posix} module is not available, but a subset is always
17available through the \module{os} interface. Once \module{os} is
18imported, there is \emph{no} performance penalty in using it instead
19of \module{posix}. In addition, \module{os} provides some additional
20functionality, such as automatically calling \function{putenv()}
21when an entry in \code{os.environ} is changed.
Fred Drake62063941997-12-15 21:42:51 +000022\refstmodindex{os}
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
31\exception{OSError}), described
32below.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000033
Fred Drake75aae9a1998-03-11 05:29:58 +000034Module \module{posix} defines the following data items:
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000035
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000036\begin{datadesc}{environ}
37A dictionary representing the string environment at the time
38the interpreter was started.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000039For example,
40\code{posix.environ['HOME']}
41is the pathname of your home directory, equivalent to
42\code{getenv("HOME")}
Fred Drake75aae9a1998-03-11 05:29:58 +000043in \C{}.
Guido van Rossum9c43c591997-08-08 21:05:09 +000044
Guido van Rossum470be141995-03-17 16:07:09 +000045Modifying this dictionary does not affect the string environment
Fred Drake75aae9a1998-03-11 05:29:58 +000046passed on by \function{execv()}, \function{popen()} or
47\function{system()}; if you need to change the environment, pass
48\code{environ} to \function{execve()} or add variable assignments and
49export statements to the command string for \function{system()} or
50\function{popen()}.
Guido van Rossum9c43c591997-08-08 21:05:09 +000051
Fred Drake75aae9a1998-03-11 05:29:58 +000052\emph{However:} If you are using this module via the \module{os}
53module (as you should -- see the introduction above), \code{environ}
54is a a mapping object that behaves almost like a dictionary but
55invokes \function{putenv()} automatically called whenever an item is
56changed.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000057\end{datadesc}
58
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000059\begin{excdesc}{error}
Fred Drake65b32f71998-02-09 20:27:12 +000060This exception is raised when a \POSIX{} function returns a
Fred Drake75aae9a1998-03-11 05:29:58 +000061\POSIX{}-related error (e.g., not for illegal argument types). The
62accompanying value is a pair containing the numeric error code from
63\cdata{errno} and the corresponding string, as would be printed by the
64\C{} function \cfunction{perror()}. See the module
65\module{errno}\refbimodindex{errno}, which contains names for the
66error codes defined by the underlying operating system.
67
68When exceptions are classes, this exception carries two attributes,
69\member{errno} and \member{strerror}. The first holds the value of
70the \C{} \cdata{errno} variable, and the latter holds the
Barry Warsaweef2cd11998-07-23 19:50:09 +000071corresponding error message from \cfunction{strerror()}. For
72exceptions that involve a file system path (e.g. \code{chdir} or
73\code{unlink}), the exception instance will contain a third attribute
74\member{filename} which is the file name passed to the
75function.
Fred Drake75aae9a1998-03-11 05:29:58 +000076
77When exceptions are strings, the string for the exception is
Barry Warsaweef2cd11998-07-23 19:50:09 +000078\code{'OSError'}.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000079\end{excdesc}
80
Guido van Rossum4bbe9c01995-03-30 16:00:36 +000081It defines the following functions and constants:
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000082
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000083\begin{funcdesc}{chdir}{path}
84Change the current working directory to \var{path}.
85\end{funcdesc}
86
Fred Drakecce10901998-03-17 06:33:25 +000087\begin{funcdesc}{chmod}{path, mode}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000088Change the mode of \var{path} to the numeric \var{mode}.
89\end{funcdesc}
90
Fred Drakecce10901998-03-17 06:33:25 +000091\begin{funcdesc}{chown}{path, uid, gid}
Guido van Rossum31cce971995-01-04 19:17:34 +000092Change the owner and group id of \var{path} to the numeric \var{uid}
93and \var{gid}.
94(Not on MS-DOS.)
95\end{funcdesc}
96
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000097\begin{funcdesc}{close}{fd}
98Close file descriptor \var{fd}.
Guido van Rossum28379701995-01-12 12:38:22 +000099
100Note: this function is intended for low-level I/O and must be applied
Fred Drake75aae9a1998-03-11 05:29:58 +0000101to a file descriptor as returned by \function{open()} or
102\function{pipe()}. To close a ``file object'' returned by the
103built-in function \function{open()} or by \function{popen()} or
104\function{fdopen()}, use its \method{close()} method.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000105\end{funcdesc}
106
107\begin{funcdesc}{dup}{fd}
108Return a duplicate of file descriptor \var{fd}.
109\end{funcdesc}
110
Fred Drakecce10901998-03-17 06:33:25 +0000111\begin{funcdesc}{dup2}{fd, fd2}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000112Duplicate file descriptor \var{fd} to \var{fd2}, closing the latter
Fred Drake75aae9a1998-03-11 05:29:58 +0000113first if necessary.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000114\end{funcdesc}
115
Fred Drakecce10901998-03-17 06:33:25 +0000116\begin{funcdesc}{execv}{path, args}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000117Execute the executable \var{path} with argument list \var{args},
118replacing the current process (i.e., the Python interpreter).
119The argument list may be a tuple or list of strings.
120(Not on MS-DOS.)
121\end{funcdesc}
122
Fred Drakecce10901998-03-17 06:33:25 +0000123\begin{funcdesc}{execve}{path, args, env}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000124Execute the executable \var{path} with argument list \var{args},
125and environment \var{env},
126replacing the current process (i.e., the Python interpreter).
127The argument list may be a tuple or list of strings.
128The environment must be a dictionary mapping strings to strings.
129(Not on MS-DOS.)
130\end{funcdesc}
131
132\begin{funcdesc}{_exit}{n}
133Exit to the system with status \var{n}, without calling cleanup
134handlers, flushing stdio buffers, etc.
135(Not on MS-DOS.)
136
137Note: the standard way to exit is \code{sys.exit(\var{n})}.
Fred Drake75aae9a1998-03-11 05:29:58 +0000138\function{_exit()} should normally only be used in the child process
139after a \function{fork()}.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000140\end{funcdesc}
141
Fred Drakecce10901998-03-17 06:33:25 +0000142\begin{funcdesc}{fdopen}{fd\optional{, mode\optional{, bufsize}}}
Guido van Rossum28379701995-01-12 12:38:22 +0000143Return an open file object connected to the file descriptor \var{fd}.
144The \var{mode} and \var{bufsize} arguments have the same meaning as
Fred Drake75aae9a1998-03-11 05:29:58 +0000145the corresponding arguments to the built-in \function{open()} function.
Guido van Rossumc5c67bc1994-02-15 15:59:23 +0000146\end{funcdesc}
147
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000148\begin{funcdesc}{fork}{}
Fred Drake75aae9a1998-03-11 05:29:58 +0000149Fork a child process. Return \code{0} in the child, the child's
150process id in the parent.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000151(Not on MS-DOS.)
152\end{funcdesc}
153
154\begin{funcdesc}{fstat}{fd}
Fred Drake75aae9a1998-03-11 05:29:58 +0000155Return status for file descriptor \var{fd}, like \function{stat()}.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000156\end{funcdesc}
157
Fred Drakecce10901998-03-17 06:33:25 +0000158\begin{funcdesc}{ftruncate}{fd, length}
Guido van Rossumf967bf61997-06-02 17:28:51 +0000159Truncate the file corresponding to file descriptor \var{fd},
160so that it is at most \var{length} bytes in size.
161\end{funcdesc}
162
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000163\begin{funcdesc}{getcwd}{}
164Return a string representing the current working directory.
165\end{funcdesc}
166
167\begin{funcdesc}{getegid}{}
Guido van Rossumeb0f0661997-12-30 20:38:16 +0000168Return the current process' effective group id.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000169(Not on MS-DOS.)
170\end{funcdesc}
171
172\begin{funcdesc}{geteuid}{}
Guido van Rossumeb0f0661997-12-30 20:38:16 +0000173Return the current process' effective user id.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000174(Not on MS-DOS.)
175\end{funcdesc}
176
177\begin{funcdesc}{getgid}{}
Guido van Rossumeb0f0661997-12-30 20:38:16 +0000178Return the current process' group id.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000179(Not on MS-DOS.)
180\end{funcdesc}
181
Guido van Rossum1e8b63e1996-06-26 19:22:46 +0000182\begin{funcdesc}{getpgrp}{}
183Return the current process group id.
184(Not on MS-DOS.)
185\end{funcdesc}
186
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000187\begin{funcdesc}{getpid}{}
188Return the current process id.
189(Not on MS-DOS.)
190\end{funcdesc}
191
192\begin{funcdesc}{getppid}{}
193Return the parent's process id.
194(Not on MS-DOS.)
195\end{funcdesc}
196
197\begin{funcdesc}{getuid}{}
Guido van Rossumeb0f0661997-12-30 20:38:16 +0000198Return the current process' user id.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000199(Not on MS-DOS.)
200\end{funcdesc}
201
Fred Drakecce10901998-03-17 06:33:25 +0000202\begin{funcdesc}{kill}{pid, sig}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000203Kill the process \var{pid} with signal \var{sig}.
204(Not on MS-DOS.)
205\end{funcdesc}
206
Fred Drakecce10901998-03-17 06:33:25 +0000207\begin{funcdesc}{link}{src, dst}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000208Create a hard link pointing to \var{src} named \var{dst}.
209(Not on MS-DOS.)
210\end{funcdesc}
211
212\begin{funcdesc}{listdir}{path}
213Return a list containing the names of the entries in the directory.
Guido van Rossum8c07bb41996-02-12 23:16:08 +0000214The list is in arbitrary order. It does not include the special
215entries \code{'.'} and \code{'..'} even if they are present in the
216directory.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000217\end{funcdesc}
218
Fred Drakecce10901998-03-17 06:33:25 +0000219\begin{funcdesc}{lseek}{fd, pos, how}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000220Set the current position of file descriptor \var{fd} to position
Fred Drake75aae9a1998-03-11 05:29:58 +0000221\var{pos}, modified by \var{how}: \code{0} to set the position
222relative to the beginning of the file; \code{1} to set it relative to
223the current position; \code{2} to set it relative to the end of the
224file.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000225\end{funcdesc}
226
227\begin{funcdesc}{lstat}{path}
Fred Drake75aae9a1998-03-11 05:29:58 +0000228Like \function{stat()}, but do not follow symbolic links. (On systems
229without symbolic links, this is identical to \function{stat()}.)
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000230\end{funcdesc}
231
Fred Drakecce10901998-03-17 06:33:25 +0000232\begin{funcdesc}{mkfifo}{path\optional{, mode}}
Fred Drake65b32f71998-02-09 20:27:12 +0000233Create a FIFO (a \POSIX{} named pipe) named \var{path} with numeric mode
Fred Drake75aae9a1998-03-11 05:29:58 +0000234\var{mode}. The default \var{mode} is \code{0666} (octal). The current
Guido van Rossum1e8b63e1996-06-26 19:22:46 +0000235umask value is first masked out from the mode.
236(Not on MS-DOS.)
237
238FIFOs are pipes that can be accessed like regular files. FIFOs exist
Fred Drake75aae9a1998-03-11 05:29:58 +0000239until they are deleted (for example with \function{os.unlink()}).
240Generally, FIFOs are used as rendezvous between ``client'' and
Guido van Rossum1e8b63e1996-06-26 19:22:46 +0000241``server'' type processes: the server opens the FIFO for reading, and
Fred Drake75aae9a1998-03-11 05:29:58 +0000242the client opens it for writing. Note that \function{mkfifo()}
243doesn't open the FIFO --- it just creates the rendezvous point.
Guido van Rossum1e8b63e1996-06-26 19:22:46 +0000244\end{funcdesc}
245
Fred Drakecce10901998-03-17 06:33:25 +0000246\begin{funcdesc}{mkdir}{path\optional{, mode}}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000247Create a directory named \var{path} with numeric mode \var{mode}.
Fred Drake75aae9a1998-03-11 05:29:58 +0000248The default \var{mode} is \code{0777} (octal). On some systems,
249\var{mode} is ignored. Where it is used, the current umask value is
250first masked out.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000251\end{funcdesc}
252
253\begin{funcdesc}{nice}{increment}
Fred Drake75aae9a1998-03-11 05:29:58 +0000254Add \var{increment} to the process' ``niceness''. Return the new
255niceness. (Not on MS-DOS.)
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000256\end{funcdesc}
257
Fred Drakecce10901998-03-17 06:33:25 +0000258\begin{funcdesc}{open}{file, flags\optional{, mode}}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000259Open the file \var{file} and set various flags according to
260\var{flags} and possibly its mode according to \var{mode}.
Fred Drake75aae9a1998-03-11 05:29:58 +0000261The default \var{mode} is \code{0777} (octal), and the current umask
262value is first masked out. Return the file descriptor for the newly
263opened file.
Guido van Rossum28379701995-01-12 12:38:22 +0000264
Fred Drake75aae9a1998-03-11 05:29:58 +0000265For a description of the flag and mode values, see the \UNIX{} or \C{}
266run-time documentation; flag constants (like \constant{O_RDONLY} and
267\constant{O_WRONLY}) are defined in this module too (see below).
Guido van Rossum9c43c591997-08-08 21:05:09 +0000268
Guido van Rossum28379701995-01-12 12:38:22 +0000269Note: this function is intended for low-level I/O. For normal usage,
Fred Drake75aae9a1998-03-11 05:29:58 +0000270use the built-in function \function{open()}, which returns a ``file
271object'' with \method{read()} and \method{write()} methods (and many
272more).
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000273\end{funcdesc}
274
275\begin{funcdesc}{pipe}{}
Fred Drake75aae9a1998-03-11 05:29:58 +0000276Create a pipe. Return a pair of file descriptors \code{(\var{r},
277\var{w})} usable for reading and writing, respectively.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000278(Not on MS-DOS.)
279\end{funcdesc}
280
Guido van Rossum38e50881996-07-21 02:21:49 +0000281\begin{funcdesc}{plock}{op}
282Lock program segments into memory. The value of \var{op}
283(defined in \code{<sys/lock.h>}) determines which segments are locked.
284(Not on MS-DOS.)
285\end{funcdesc}
286
Fred Drakecce10901998-03-17 06:33:25 +0000287\begin{funcdesc}{popen}{command\optional{, mode\optional{, bufsize}}}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000288Open a pipe to or from \var{command}. The return value is an open
289file object connected to the pipe, which can be read or written
Guido van Rossum28379701995-01-12 12:38:22 +0000290depending on whether \var{mode} is \code{'r'} (default) or \code{'w'}.
291The \var{bufsize} argument has the same meaning as the corresponding
Fred Drake75aae9a1998-03-11 05:29:58 +0000292argument to the built-in \function{open()} function. The exit status of
293the command (encoded in the format specified for \function{wait()}) is
294available as the return value of the \method{close()} method of the file
Guido van Rossum7e691de1997-05-09 02:22:59 +0000295object.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000296(Not on MS-DOS.)
297\end{funcdesc}
298
Fred Drakecce10901998-03-17 06:33:25 +0000299\begin{funcdesc}{putenv}{varname, value}
Fred Drake52405c81998-03-16 05:21:08 +0000300\index{environment variables!setting}
Fred Drake75aae9a1998-03-11 05:29:58 +0000301Set the environment variable named \var{varname} to the string
302\var{value}. Such changes to the environment affect subprocesses
303started with \function{os.system()}, \function{os.popen()} or
304\function{os.fork()} and \function{os.execv()}. (Not on all systems.)
Guido van Rossumf967bf61997-06-02 17:28:51 +0000305
Fred Drake75aae9a1998-03-11 05:29:58 +0000306When \function{putenv()} is
Guido van Rossumf967bf61997-06-02 17:28:51 +0000307supported, assignments to items in \code{os.environ} are automatically
Fred Drake75aae9a1998-03-11 05:29:58 +0000308translated into corresponding calls to \function{putenv()}; however,
309calls to \function{putenv()} don't update \code{os.environ}, so it is
Guido van Rossumf967bf61997-06-02 17:28:51 +0000310actually preferable to assign to items of \code{os.environ}.
311\end{funcdesc}
312
Guido van Rossum0bfd1461997-10-05 18:54:52 +0000313\begin{funcdesc}{strerror}{code}
314Return the error message corresponding to the error code in \var{code}.
315\end{funcdesc}
316
Fred Drakecce10901998-03-17 06:33:25 +0000317\begin{funcdesc}{read}{fd, n}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000318Read at most \var{n} bytes from file descriptor \var{fd}.
319Return a string containing the bytes read.
Guido van Rossum28379701995-01-12 12:38:22 +0000320
321Note: this function is intended for low-level I/O and must be applied
Fred Drake75aae9a1998-03-11 05:29:58 +0000322to a file descriptor as returned by \function{open()} or
323\function{pipe()}. To read a ``file object'' returned by the
324built-in function \function{open()} or by \function{popen()} or
325\function{fdopen()}, or \code{sys.stdin}, use its
326\method{read()} or \method{readline()} methods.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000327\end{funcdesc}
328
329\begin{funcdesc}{readlink}{path}
330Return a string representing the path to which the symbolic link
331points. (On systems without symbolic links, this always raises
Fred Drake75aae9a1998-03-11 05:29:58 +0000332\exception{error}.)
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000333\end{funcdesc}
334
Guido van Rossum8c07bb41996-02-12 23:16:08 +0000335\begin{funcdesc}{remove}{path}
Fred Drake75aae9a1998-03-11 05:29:58 +0000336Remove the file \var{path}. See \function{rmdir()} below to remove a
337directory. This is identical to the \function{unlink()} function
338documented below.
Guido van Rossum8c07bb41996-02-12 23:16:08 +0000339\end{funcdesc}
340
Fred Drakecce10901998-03-17 06:33:25 +0000341\begin{funcdesc}{rename}{src, dst}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000342Rename the file or directory \var{src} to \var{dst}.
343\end{funcdesc}
344
345\begin{funcdesc}{rmdir}{path}
346Remove the directory \var{path}.
347\end{funcdesc}
348
349\begin{funcdesc}{setgid}{gid}
Guido van Rossumeb0f0661997-12-30 20:38:16 +0000350Set the current process' group id.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000351(Not on MS-DOS.)
352\end{funcdesc}
353
Guido van Rossum1e8b63e1996-06-26 19:22:46 +0000354\begin{funcdesc}{setpgrp}{}
Fred Drake75aae9a1998-03-11 05:29:58 +0000355Calls the system call \cfunction{setpgrp()} or \cfunction{setpgrp(0,
3560)} depending on which version is implemented (if any). See the
357\UNIX{} manual for the semantics.
Guido van Rossum1e8b63e1996-06-26 19:22:46 +0000358(Not on MS-DOS.)
359\end{funcdesc}
360
Fred Drakecce10901998-03-17 06:33:25 +0000361\begin{funcdesc}{setpgid}{pid, pgrp}
Fred Drake75aae9a1998-03-11 05:29:58 +0000362Calls the system call \cfunction{setpgid()}. See the \UNIX{} manual
363for the semantics.
Guido van Rossum1e8b63e1996-06-26 19:22:46 +0000364(Not on MS-DOS.)
365\end{funcdesc}
366
367\begin{funcdesc}{setsid}{}
Fred Drake75aae9a1998-03-11 05:29:58 +0000368Calls the system call \cfunction{setsid()}. See the \UNIX{} manual
369for the semantics.
Guido van Rossum1e8b63e1996-06-26 19:22:46 +0000370(Not on MS-DOS.)
371\end{funcdesc}
372
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000373\begin{funcdesc}{setuid}{uid}
Guido van Rossumeb0f0661997-12-30 20:38:16 +0000374Set the current process' user id.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000375(Not on MS-DOS.)
376\end{funcdesc}
377
378\begin{funcdesc}{stat}{path}
Fred Drake75aae9a1998-03-11 05:29:58 +0000379Perform a \cfunction{stat()} system call on the given path. The
380return value is a tuple of at least 10 integers giving the most
381important (and portable) members of the \emph{stat} structure, in the
382order
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000383\code{st_mode},
384\code{st_ino},
385\code{st_dev},
386\code{st_nlink},
387\code{st_uid},
388\code{st_gid},
389\code{st_size},
390\code{st_atime},
391\code{st_mtime},
392\code{st_ctime}.
393More items may be added at the end by some implementations.
394(On MS-DOS, some items are filled with dummy values.)
395
Fred Drake75aae9a1998-03-11 05:29:58 +0000396Note: The standard module \module{stat}\refstmodindex{stat} defines
397functions and constants that are useful for extracting information
398from a stat structure.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000399\end{funcdesc}
400
Fred Drakecce10901998-03-17 06:33:25 +0000401\begin{funcdesc}{symlink}{src, dst}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000402Create a symbolic link pointing to \var{src} named \var{dst}. (On
Fred Drake75aae9a1998-03-11 05:29:58 +0000403systems without symbolic links, this always raises \exception{error}.)
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000404\end{funcdesc}
405
406\begin{funcdesc}{system}{command}
407Execute the command (a string) in a subshell. This is implemented by
Fred Drake75aae9a1998-03-11 05:29:58 +0000408calling the Standard \C{} function \cfunction{system()}, and has the
409same limitations. Changes to \code{posix.environ}, \code{sys.stdin}
410etc.\ are not reflected in the environment of the executed command.
411The return value is the exit status of the process encoded in the
412format specified for \function{wait()}.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000413\end{funcdesc}
414
Guido van Rossum1e8b63e1996-06-26 19:22:46 +0000415\begin{funcdesc}{tcgetpgrp}{fd}
416Return 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 +0000418(Not on MS-DOS.)
419\end{funcdesc}
420
Fred Drakecce10901998-03-17 06:33:25 +0000421\begin{funcdesc}{tcsetpgrp}{fd, pg}
Guido van Rossum1e8b63e1996-06-26 19:22:46 +0000422Set the process group associated with the terminal given by
Fred Drake75aae9a1998-03-11 05:29:58 +0000423\var{fd} (an open file descriptor as returned by \function{open()})
Guido van Rossum1e8b63e1996-06-26 19:22:46 +0000424to \var{pg}.
425(Not on MS-DOS.)
426\end{funcdesc}
427
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000428\begin{funcdesc}{times}{}
Guido van Rossum1e150611995-09-13 17:36:35 +0000429Return a 5-tuple of floating point numbers indicating accumulated (CPU
430or other)
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000431times, in seconds. The items are: user time, system time, children's
Guido van Rossum1e150611995-09-13 17:36:35 +0000432user time, children's system time, and elapsed real time since a fixed
433point in the past, in that order. See the \UNIX{}
Fred Drake75aae9a1998-03-11 05:29:58 +0000434manual page \manpage{times}{2}. (Not on MS-DOS.)
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000435\end{funcdesc}
436
437\begin{funcdesc}{umask}{mask}
438Set the current numeric umask and returns the previous umask.
439(Not on MS-DOS.)
440\end{funcdesc}
441
442\begin{funcdesc}{uname}{}
443Return a 5-tuple containing information identifying the current
444operating system. The tuple contains 5 strings:
Fred Drake75aae9a1998-03-11 05:29:58 +0000445\code{(\var{sysname}, \var{nodename}, \var{release}, \var{version},
446\var{machine})}. Some systems truncate the nodename to 8
Guido van Rossum6bb1adc1995-03-13 10:03:32 +0000447characters or to the leading component; a better way to get the
Fred Drake75aae9a1998-03-11 05:29:58 +0000448hostname is \function{socket.gethostname()}%
Fred Drake371ecc01998-03-12 06:44:58 +0000449\withsubitem{(in module socket)}{\ttindex{gethostname()}}
Fred Drake75aae9a1998-03-11 05:29:58 +0000450or even
451\code{socket.gethostbyaddr(socket.gethostname())}%
Fred Drake371ecc01998-03-12 06:44:58 +0000452\withsubitem{(in module socket)}{\ttindex{gethostbyaddr()}}.
Guido van Rossumeb0f0661997-12-30 20:38:16 +0000453(Not on MS-DOS, nor on older \UNIX{} systems.)
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000454\end{funcdesc}
455
456\begin{funcdesc}{unlink}{path}
Guido van Rossum8c07bb41996-02-12 23:16:08 +0000457Remove the file \var{path}. This is the same function as \code{remove};
458the \code{unlink} name is its traditional \UNIX{} name.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000459\end{funcdesc}
460
Fred Drakecce10901998-03-17 06:33:25 +0000461\begin{funcdesc}{utime}{path, {\rm (}atime, mtime{\rm )}}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000462Set the access and modified time of the file to the given values.
463(The second argument is a tuple of two items.)
464\end{funcdesc}
465
466\begin{funcdesc}{wait}{}
467Wait for completion of a child process, and return a tuple containing
Guido van Rossum7e691de1997-05-09 02:22:59 +0000468its pid and exit status indication: a 16-bit number, whose low byte is
469the signal number that killed the process, and whose high byte is the
470exit status (if the signal number is zero); the high bit of the low
471byte is set if a core file was produced. (Not on MS-DOS.)
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000472\end{funcdesc}
473
Fred Drakecce10901998-03-17 06:33:25 +0000474\begin{funcdesc}{waitpid}{pid, options}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000475Wait for completion of a child process given by proces id, and return
Guido van Rossum7e691de1997-05-09 02:22:59 +0000476a tuple containing its pid and exit status indication (encoded as for
Fred Drake75aae9a1998-03-11 05:29:58 +0000477\function{wait()}). The semantics of the call are affected by the
478value of the integer \var{options}, which should be \code{0} for
479normal operation. (If the system does not support
480\function{waitpid()}, this always raises \exception{error}. Not on
481MS-DOS.)
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000482\end{funcdesc}
483
Fred Drakecce10901998-03-17 06:33:25 +0000484\begin{funcdesc}{write}{fd, str}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000485Write the string \var{str} to file descriptor \var{fd}.
486Return the number of bytes actually written.
Guido van Rossum28379701995-01-12 12:38:22 +0000487
488Note: this function is intended for low-level I/O and must be applied
Fred Drake75aae9a1998-03-11 05:29:58 +0000489to a file descriptor as returned by \function{open()} or
490\function{pipe()}. To write a ``file object'' returned by the
491built-in function \function{open()} or by \function{popen()} or
492\function{fdopen()}, or \code{sys.stdout} or \code{sys.stderr}, use
493its \method{write()} method.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000494\end{funcdesc}
Guido van Rossum4bbe9c01995-03-30 16:00:36 +0000495
496\begin{datadesc}{WNOHANG}
Fred Drake75aae9a1998-03-11 05:29:58 +0000497The option for \function{waitpid()} to avoid hanging if no child
498process status is available immediately.
Guido van Rossum4bbe9c01995-03-30 16:00:36 +0000499\end{datadesc}
Barry Warsawe5a43a41996-12-19 23:50:34 +0000500
501
502\begin{datadesc}{O_RDONLY}
Fred Drake86b5dce1998-02-13 21:55:21 +0000503\dataline{O_WRONLY}
504\dataline{O_RDWR}
505\dataline{O_NDELAY}
506\dataline{O_NONBLOCK}
507\dataline{O_APPEND}
508\dataline{O_DSYNC}
509\dataline{O_RSYNC}
510\dataline{O_SYNC}
511\dataline{O_NOCTTY}
512\dataline{O_CREAT}
513\dataline{O_EXCL}
514\dataline{O_TRUNC}
Fred Drake75aae9a1998-03-11 05:29:58 +0000515Options for the \code{flag} argument to the \function{open()} function.
Barry Warsawe5a43a41996-12-19 23:50:34 +0000516These can be bit-wise OR'd together.
517\end{datadesc}