blob: bccc283eb31ac216d16a0acf364bddea583f7d1d [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
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000031\begin{datadesc}{environ}
32A dictionary representing the string environment at the time
33the interpreter was started.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000034For example,
35\code{posix.environ['HOME']}
36is the pathname of your home directory, equivalent to
37\code{getenv("HOME")}
Fred Drake75aae9a1998-03-11 05:29:58 +000038in \C{}.
Guido van Rossum9c43c591997-08-08 21:05:09 +000039
Guido van Rossum470be141995-03-17 16:07:09 +000040Modifying this dictionary does not affect the string environment
Fred Drake75aae9a1998-03-11 05:29:58 +000041passed on by \function{execv()}, \function{popen()} or
42\function{system()}; if you need to change the environment, pass
43\code{environ} to \function{execve()} or add variable assignments and
44export statements to the command string for \function{system()} or
45\function{popen()}.
Guido van Rossum9c43c591997-08-08 21:05:09 +000046
Fred Drake75aae9a1998-03-11 05:29:58 +000047\emph{However:} If you are using this module via the \module{os}
48module (as you should -- see the introduction above), \code{environ}
49is a a mapping object that behaves almost like a dictionary but
50invokes \function{putenv()} automatically called whenever an item is
51changed.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000052\end{datadesc}
53
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000054\begin{excdesc}{error}
Fred Drake65b32f71998-02-09 20:27:12 +000055This exception is raised when a \POSIX{} function returns a
Fred Drake75aae9a1998-03-11 05:29:58 +000056\POSIX{}-related error (e.g., not for illegal argument types). The
57accompanying value is a pair containing the numeric error code from
58\cdata{errno} and the corresponding string, as would be printed by the
59\C{} function \cfunction{perror()}. See the module
60\module{errno}\refbimodindex{errno}, which contains names for the
61error codes defined by the underlying operating system.
62
63When exceptions are classes, this exception carries two attributes,
64\member{errno} and \member{strerror}. The first holds the value of
65the \C{} \cdata{errno} variable, and the latter holds the
66corresponding error message from \cfunction{strerror()}.
67
68When exceptions are strings, the string for the exception is
69\code{'os.error'}; this reflects the more portable access to the
70exception through the \module{os} module.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000071\end{excdesc}
72
Guido van Rossum4bbe9c01995-03-30 16:00:36 +000073It defines the following functions and constants:
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000074
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000075\begin{funcdesc}{chdir}{path}
76Change the current working directory to \var{path}.
77\end{funcdesc}
78
Fred Drakecce10901998-03-17 06:33:25 +000079\begin{funcdesc}{chmod}{path, mode}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000080Change the mode of \var{path} to the numeric \var{mode}.
81\end{funcdesc}
82
Fred Drakecce10901998-03-17 06:33:25 +000083\begin{funcdesc}{chown}{path, uid, gid}
Guido van Rossum31cce971995-01-04 19:17:34 +000084Change the owner and group id of \var{path} to the numeric \var{uid}
85and \var{gid}.
86(Not on MS-DOS.)
87\end{funcdesc}
88
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000089\begin{funcdesc}{close}{fd}
90Close file descriptor \var{fd}.
Guido van Rossum28379701995-01-12 12:38:22 +000091
92Note: this function is intended for low-level I/O and must be applied
Fred Drake75aae9a1998-03-11 05:29:58 +000093to a file descriptor as returned by \function{open()} or
94\function{pipe()}. To close a ``file object'' returned by the
95built-in function \function{open()} or by \function{popen()} or
96\function{fdopen()}, use its \method{close()} method.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000097\end{funcdesc}
98
99\begin{funcdesc}{dup}{fd}
100Return a duplicate of file descriptor \var{fd}.
101\end{funcdesc}
102
Fred Drakecce10901998-03-17 06:33:25 +0000103\begin{funcdesc}{dup2}{fd, fd2}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000104Duplicate file descriptor \var{fd} to \var{fd2}, closing the latter
Fred Drake75aae9a1998-03-11 05:29:58 +0000105first if necessary.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000106\end{funcdesc}
107
Fred Drakecce10901998-03-17 06:33:25 +0000108\begin{funcdesc}{execv}{path, args}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000109Execute the executable \var{path} with argument list \var{args},
110replacing the current process (i.e., the Python interpreter).
111The argument list may be a tuple or list of strings.
112(Not on MS-DOS.)
113\end{funcdesc}
114
Fred Drakecce10901998-03-17 06:33:25 +0000115\begin{funcdesc}{execve}{path, args, env}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000116Execute the executable \var{path} with argument list \var{args},
117and environment \var{env},
118replacing the current process (i.e., the Python interpreter).
119The argument list may be a tuple or list of strings.
120The environment must be a dictionary mapping strings to strings.
121(Not on MS-DOS.)
122\end{funcdesc}
123
124\begin{funcdesc}{_exit}{n}
125Exit to the system with status \var{n}, without calling cleanup
126handlers, flushing stdio buffers, etc.
127(Not on MS-DOS.)
128
129Note: the standard way to exit is \code{sys.exit(\var{n})}.
Fred Drake75aae9a1998-03-11 05:29:58 +0000130\function{_exit()} should normally only be used in the child process
131after a \function{fork()}.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000132\end{funcdesc}
133
Fred Drakecce10901998-03-17 06:33:25 +0000134\begin{funcdesc}{fdopen}{fd\optional{, mode\optional{, bufsize}}}
Guido van Rossum28379701995-01-12 12:38:22 +0000135Return an open file object connected to the file descriptor \var{fd}.
136The \var{mode} and \var{bufsize} arguments have the same meaning as
Fred Drake75aae9a1998-03-11 05:29:58 +0000137the corresponding arguments to the built-in \function{open()} function.
Guido van Rossumc5c67bc1994-02-15 15:59:23 +0000138\end{funcdesc}
139
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000140\begin{funcdesc}{fork}{}
Fred Drake75aae9a1998-03-11 05:29:58 +0000141Fork a child process. Return \code{0} in the child, the child's
142process id in the parent.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000143(Not on MS-DOS.)
144\end{funcdesc}
145
146\begin{funcdesc}{fstat}{fd}
Fred Drake75aae9a1998-03-11 05:29:58 +0000147Return status for file descriptor \var{fd}, like \function{stat()}.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000148\end{funcdesc}
149
Fred Drakecce10901998-03-17 06:33:25 +0000150\begin{funcdesc}{ftruncate}{fd, length}
Guido van Rossumf967bf61997-06-02 17:28:51 +0000151Truncate the file corresponding to file descriptor \var{fd},
152so that it is at most \var{length} bytes in size.
153\end{funcdesc}
154
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000155\begin{funcdesc}{getcwd}{}
156Return a string representing the current working directory.
157\end{funcdesc}
158
159\begin{funcdesc}{getegid}{}
Guido van Rossumeb0f0661997-12-30 20:38:16 +0000160Return the current process' effective group id.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000161(Not on MS-DOS.)
162\end{funcdesc}
163
164\begin{funcdesc}{geteuid}{}
Guido van Rossumeb0f0661997-12-30 20:38:16 +0000165Return the current process' effective user id.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000166(Not on MS-DOS.)
167\end{funcdesc}
168
169\begin{funcdesc}{getgid}{}
Guido van Rossumeb0f0661997-12-30 20:38:16 +0000170Return the current process' group id.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000171(Not on MS-DOS.)
172\end{funcdesc}
173
Guido van Rossum1e8b63e1996-06-26 19:22:46 +0000174\begin{funcdesc}{getpgrp}{}
175Return the current process group id.
176(Not on MS-DOS.)
177\end{funcdesc}
178
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000179\begin{funcdesc}{getpid}{}
180Return the current process id.
181(Not on MS-DOS.)
182\end{funcdesc}
183
184\begin{funcdesc}{getppid}{}
185Return the parent's process id.
186(Not on MS-DOS.)
187\end{funcdesc}
188
189\begin{funcdesc}{getuid}{}
Guido van Rossumeb0f0661997-12-30 20:38:16 +0000190Return the current process' user id.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000191(Not on MS-DOS.)
192\end{funcdesc}
193
Fred Drakecce10901998-03-17 06:33:25 +0000194\begin{funcdesc}{kill}{pid, sig}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000195Kill the process \var{pid} with signal \var{sig}.
196(Not on MS-DOS.)
197\end{funcdesc}
198
Fred Drakecce10901998-03-17 06:33:25 +0000199\begin{funcdesc}{link}{src, dst}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000200Create a hard link pointing to \var{src} named \var{dst}.
201(Not on MS-DOS.)
202\end{funcdesc}
203
204\begin{funcdesc}{listdir}{path}
205Return a list containing the names of the entries in the directory.
Guido van Rossum8c07bb41996-02-12 23:16:08 +0000206The list is in arbitrary order. It does not include the special
207entries \code{'.'} and \code{'..'} even if they are present in the
208directory.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000209\end{funcdesc}
210
Fred Drakecce10901998-03-17 06:33:25 +0000211\begin{funcdesc}{lseek}{fd, pos, how}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000212Set the current position of file descriptor \var{fd} to position
Fred Drake75aae9a1998-03-11 05:29:58 +0000213\var{pos}, modified by \var{how}: \code{0} to set the position
214relative to the beginning of the file; \code{1} to set it relative to
215the current position; \code{2} to set it relative to the end of the
216file.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000217\end{funcdesc}
218
219\begin{funcdesc}{lstat}{path}
Fred Drake75aae9a1998-03-11 05:29:58 +0000220Like \function{stat()}, but do not follow symbolic links. (On systems
221without symbolic links, this is identical to \function{stat()}.)
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000222\end{funcdesc}
223
Fred Drakecce10901998-03-17 06:33:25 +0000224\begin{funcdesc}{mkfifo}{path\optional{, mode}}
Fred Drake65b32f71998-02-09 20:27:12 +0000225Create a FIFO (a \POSIX{} named pipe) named \var{path} with numeric mode
Fred Drake75aae9a1998-03-11 05:29:58 +0000226\var{mode}. The default \var{mode} is \code{0666} (octal). The current
Guido van Rossum1e8b63e1996-06-26 19:22:46 +0000227umask value is first masked out from the mode.
228(Not on MS-DOS.)
229
230FIFOs are pipes that can be accessed like regular files. FIFOs exist
Fred Drake75aae9a1998-03-11 05:29:58 +0000231until they are deleted (for example with \function{os.unlink()}).
232Generally, FIFOs are used as rendezvous between ``client'' and
Guido van Rossum1e8b63e1996-06-26 19:22:46 +0000233``server'' type processes: the server opens the FIFO for reading, and
Fred Drake75aae9a1998-03-11 05:29:58 +0000234the client opens it for writing. Note that \function{mkfifo()}
235doesn't open the FIFO --- it just creates the rendezvous point.
Guido van Rossum1e8b63e1996-06-26 19:22:46 +0000236\end{funcdesc}
237
Fred Drakecce10901998-03-17 06:33:25 +0000238\begin{funcdesc}{mkdir}{path\optional{, mode}}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000239Create a directory named \var{path} with numeric mode \var{mode}.
Fred Drake75aae9a1998-03-11 05:29:58 +0000240The default \var{mode} is \code{0777} (octal). On some systems,
241\var{mode} is ignored. Where it is used, the current umask value is
242first masked out.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000243\end{funcdesc}
244
245\begin{funcdesc}{nice}{increment}
Fred Drake75aae9a1998-03-11 05:29:58 +0000246Add \var{increment} to the process' ``niceness''. Return the new
247niceness. (Not on MS-DOS.)
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000248\end{funcdesc}
249
Fred Drakecce10901998-03-17 06:33:25 +0000250\begin{funcdesc}{open}{file, flags\optional{, mode}}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000251Open the file \var{file} and set various flags according to
252\var{flags} and possibly its mode according to \var{mode}.
Fred Drake75aae9a1998-03-11 05:29:58 +0000253The default \var{mode} is \code{0777} (octal), and the current umask
254value is first masked out. Return the file descriptor for the newly
255opened file.
Guido van Rossum28379701995-01-12 12:38:22 +0000256
Fred Drake75aae9a1998-03-11 05:29:58 +0000257For a description of the flag and mode values, see the \UNIX{} or \C{}
258run-time documentation; flag constants (like \constant{O_RDONLY} and
259\constant{O_WRONLY}) are defined in this module too (see below).
Guido van Rossum9c43c591997-08-08 21:05:09 +0000260
Guido van Rossum28379701995-01-12 12:38:22 +0000261Note: this function is intended for low-level I/O. For normal usage,
Fred Drake75aae9a1998-03-11 05:29:58 +0000262use the built-in function \function{open()}, which returns a ``file
263object'' with \method{read()} and \method{write()} methods (and many
264more).
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000265\end{funcdesc}
266
267\begin{funcdesc}{pipe}{}
Fred Drake75aae9a1998-03-11 05:29:58 +0000268Create a pipe. Return a pair of file descriptors \code{(\var{r},
269\var{w})} usable for reading and writing, respectively.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000270(Not on MS-DOS.)
271\end{funcdesc}
272
Guido van Rossum38e50881996-07-21 02:21:49 +0000273\begin{funcdesc}{plock}{op}
274Lock program segments into memory. The value of \var{op}
275(defined in \code{<sys/lock.h>}) determines which segments are locked.
276(Not on MS-DOS.)
277\end{funcdesc}
278
Fred Drakecce10901998-03-17 06:33:25 +0000279\begin{funcdesc}{popen}{command\optional{, mode\optional{, bufsize}}}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000280Open a pipe to or from \var{command}. The return value is an open
281file object connected to the pipe, which can be read or written
Guido van Rossum28379701995-01-12 12:38:22 +0000282depending on whether \var{mode} is \code{'r'} (default) or \code{'w'}.
283The \var{bufsize} argument has the same meaning as the corresponding
Fred Drake75aae9a1998-03-11 05:29:58 +0000284argument to the built-in \function{open()} function. The exit status of
285the command (encoded in the format specified for \function{wait()}) is
286available as the return value of the \method{close()} method of the file
Guido van Rossum7e691de1997-05-09 02:22:59 +0000287object.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000288(Not on MS-DOS.)
289\end{funcdesc}
290
Fred Drakecce10901998-03-17 06:33:25 +0000291\begin{funcdesc}{putenv}{varname, value}
Fred Drake52405c81998-03-16 05:21:08 +0000292\index{environment variables!setting}
Fred Drake75aae9a1998-03-11 05:29:58 +0000293Set the environment variable named \var{varname} to the string
294\var{value}. Such changes to the environment affect subprocesses
295started with \function{os.system()}, \function{os.popen()} or
296\function{os.fork()} and \function{os.execv()}. (Not on all systems.)
Guido van Rossumf967bf61997-06-02 17:28:51 +0000297
Fred Drake75aae9a1998-03-11 05:29:58 +0000298When \function{putenv()} is
Guido van Rossumf967bf61997-06-02 17:28:51 +0000299supported, assignments to items in \code{os.environ} are automatically
Fred Drake75aae9a1998-03-11 05:29:58 +0000300translated into corresponding calls to \function{putenv()}; however,
301calls to \function{putenv()} don't update \code{os.environ}, so it is
Guido van Rossumf967bf61997-06-02 17:28:51 +0000302actually preferable to assign to items of \code{os.environ}.
303\end{funcdesc}
304
Guido van Rossum0bfd1461997-10-05 18:54:52 +0000305\begin{funcdesc}{strerror}{code}
306Return the error message corresponding to the error code in \var{code}.
307\end{funcdesc}
308
Fred Drakecce10901998-03-17 06:33:25 +0000309\begin{funcdesc}{read}{fd, n}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000310Read at most \var{n} bytes from file descriptor \var{fd}.
311Return a string containing the bytes read.
Guido van Rossum28379701995-01-12 12:38:22 +0000312
313Note: this function is intended for low-level I/O and must be applied
Fred Drake75aae9a1998-03-11 05:29:58 +0000314to a file descriptor as returned by \function{open()} or
315\function{pipe()}. To read a ``file object'' returned by the
316built-in function \function{open()} or by \function{popen()} or
317\function{fdopen()}, or \code{sys.stdin}, use its
318\method{read()} or \method{readline()} methods.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000319\end{funcdesc}
320
321\begin{funcdesc}{readlink}{path}
322Return a string representing the path to which the symbolic link
323points. (On systems without symbolic links, this always raises
Fred Drake75aae9a1998-03-11 05:29:58 +0000324\exception{error}.)
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000325\end{funcdesc}
326
Guido van Rossum8c07bb41996-02-12 23:16:08 +0000327\begin{funcdesc}{remove}{path}
Fred Drake75aae9a1998-03-11 05:29:58 +0000328Remove the file \var{path}. See \function{rmdir()} below to remove a
329directory. This is identical to the \function{unlink()} function
330documented below.
Guido van Rossum8c07bb41996-02-12 23:16:08 +0000331\end{funcdesc}
332
Fred Drakecce10901998-03-17 06:33:25 +0000333\begin{funcdesc}{rename}{src, dst}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000334Rename the file or directory \var{src} to \var{dst}.
335\end{funcdesc}
336
337\begin{funcdesc}{rmdir}{path}
338Remove the directory \var{path}.
339\end{funcdesc}
340
341\begin{funcdesc}{setgid}{gid}
Guido van Rossumeb0f0661997-12-30 20:38:16 +0000342Set the current process' group id.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000343(Not on MS-DOS.)
344\end{funcdesc}
345
Guido van Rossum1e8b63e1996-06-26 19:22:46 +0000346\begin{funcdesc}{setpgrp}{}
Fred Drake75aae9a1998-03-11 05:29:58 +0000347Calls the system call \cfunction{setpgrp()} or \cfunction{setpgrp(0,
3480)} depending on which version is implemented (if any). See the
349\UNIX{} manual for the semantics.
Guido van Rossum1e8b63e1996-06-26 19:22:46 +0000350(Not on MS-DOS.)
351\end{funcdesc}
352
Fred Drakecce10901998-03-17 06:33:25 +0000353\begin{funcdesc}{setpgid}{pid, pgrp}
Fred Drake75aae9a1998-03-11 05:29:58 +0000354Calls the system call \cfunction{setpgid()}. See the \UNIX{} manual
355for the semantics.
Guido van Rossum1e8b63e1996-06-26 19:22:46 +0000356(Not on MS-DOS.)
357\end{funcdesc}
358
359\begin{funcdesc}{setsid}{}
Fred Drake75aae9a1998-03-11 05:29:58 +0000360Calls the system call \cfunction{setsid()}. See the \UNIX{} manual
361for the semantics.
Guido van Rossum1e8b63e1996-06-26 19:22:46 +0000362(Not on MS-DOS.)
363\end{funcdesc}
364
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000365\begin{funcdesc}{setuid}{uid}
Guido van Rossumeb0f0661997-12-30 20:38:16 +0000366Set the current process' user id.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000367(Not on MS-DOS.)
368\end{funcdesc}
369
370\begin{funcdesc}{stat}{path}
Fred Drake75aae9a1998-03-11 05:29:58 +0000371Perform a \cfunction{stat()} system call on the given path. The
372return value is a tuple of at least 10 integers giving the most
373important (and portable) members of the \emph{stat} structure, in the
374order
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000375\code{st_mode},
376\code{st_ino},
377\code{st_dev},
378\code{st_nlink},
379\code{st_uid},
380\code{st_gid},
381\code{st_size},
382\code{st_atime},
383\code{st_mtime},
384\code{st_ctime}.
385More items may be added at the end by some implementations.
386(On MS-DOS, some items are filled with dummy values.)
387
Fred Drake75aae9a1998-03-11 05:29:58 +0000388Note: The standard module \module{stat}\refstmodindex{stat} defines
389functions and constants that are useful for extracting information
390from a stat structure.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000391\end{funcdesc}
392
Fred Drakecce10901998-03-17 06:33:25 +0000393\begin{funcdesc}{symlink}{src, dst}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000394Create a symbolic link pointing to \var{src} named \var{dst}. (On
Fred Drake75aae9a1998-03-11 05:29:58 +0000395systems without symbolic links, this always raises \exception{error}.)
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000396\end{funcdesc}
397
398\begin{funcdesc}{system}{command}
399Execute the command (a string) in a subshell. This is implemented by
Fred Drake75aae9a1998-03-11 05:29:58 +0000400calling the Standard \C{} function \cfunction{system()}, and has the
401same limitations. Changes to \code{posix.environ}, \code{sys.stdin}
402etc.\ are not reflected in the environment of the executed command.
403The return value is the exit status of the process encoded in the
404format specified for \function{wait()}.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000405\end{funcdesc}
406
Guido van Rossum1e8b63e1996-06-26 19:22:46 +0000407\begin{funcdesc}{tcgetpgrp}{fd}
408Return the process group associated with the terminal given by
Fred Drake75aae9a1998-03-11 05:29:58 +0000409\var{fd} (an open file descriptor as returned by \function{open()}).
Guido van Rossum1e8b63e1996-06-26 19:22:46 +0000410(Not on MS-DOS.)
411\end{funcdesc}
412
Fred Drakecce10901998-03-17 06:33:25 +0000413\begin{funcdesc}{tcsetpgrp}{fd, pg}
Guido van Rossum1e8b63e1996-06-26 19:22:46 +0000414Set the process group associated with the terminal given by
Fred Drake75aae9a1998-03-11 05:29:58 +0000415\var{fd} (an open file descriptor as returned by \function{open()})
Guido van Rossum1e8b63e1996-06-26 19:22:46 +0000416to \var{pg}.
417(Not on MS-DOS.)
418\end{funcdesc}
419
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000420\begin{funcdesc}{times}{}
Guido van Rossum1e150611995-09-13 17:36:35 +0000421Return a 5-tuple of floating point numbers indicating accumulated (CPU
422or other)
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000423times, in seconds. The items are: user time, system time, children's
Guido van Rossum1e150611995-09-13 17:36:35 +0000424user time, children's system time, and elapsed real time since a fixed
425point in the past, in that order. See the \UNIX{}
Fred Drake75aae9a1998-03-11 05:29:58 +0000426manual page \manpage{times}{2}. (Not on MS-DOS.)
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000427\end{funcdesc}
428
429\begin{funcdesc}{umask}{mask}
430Set the current numeric umask and returns the previous umask.
431(Not on MS-DOS.)
432\end{funcdesc}
433
434\begin{funcdesc}{uname}{}
435Return a 5-tuple containing information identifying the current
436operating system. The tuple contains 5 strings:
Fred Drake75aae9a1998-03-11 05:29:58 +0000437\code{(\var{sysname}, \var{nodename}, \var{release}, \var{version},
438\var{machine})}. Some systems truncate the nodename to 8
Guido van Rossum6bb1adc1995-03-13 10:03:32 +0000439characters or to the leading component; a better way to get the
Fred Drake75aae9a1998-03-11 05:29:58 +0000440hostname is \function{socket.gethostname()}%
Fred Drake371ecc01998-03-12 06:44:58 +0000441\withsubitem{(in module socket)}{\ttindex{gethostname()}}
Fred Drake75aae9a1998-03-11 05:29:58 +0000442or even
443\code{socket.gethostbyaddr(socket.gethostname())}%
Fred Drake371ecc01998-03-12 06:44:58 +0000444\withsubitem{(in module socket)}{\ttindex{gethostbyaddr()}}.
Guido van Rossumeb0f0661997-12-30 20:38:16 +0000445(Not on MS-DOS, nor on older \UNIX{} systems.)
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000446\end{funcdesc}
447
448\begin{funcdesc}{unlink}{path}
Guido van Rossum8c07bb41996-02-12 23:16:08 +0000449Remove the file \var{path}. This is the same function as \code{remove};
450the \code{unlink} name is its traditional \UNIX{} name.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000451\end{funcdesc}
452
Fred Drakecce10901998-03-17 06:33:25 +0000453\begin{funcdesc}{utime}{path, {\rm (}atime, mtime{\rm )}}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000454Set the access and modified time of the file to the given values.
455(The second argument is a tuple of two items.)
456\end{funcdesc}
457
458\begin{funcdesc}{wait}{}
459Wait for completion of a child process, and return a tuple containing
Guido van Rossum7e691de1997-05-09 02:22:59 +0000460its pid and exit status indication: a 16-bit number, whose low byte is
461the signal number that killed the process, and whose high byte is the
462exit status (if the signal number is zero); the high bit of the low
463byte is set if a core file was produced. (Not on MS-DOS.)
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000464\end{funcdesc}
465
Fred Drakecce10901998-03-17 06:33:25 +0000466\begin{funcdesc}{waitpid}{pid, options}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000467Wait for completion of a child process given by proces id, and return
Guido van Rossum7e691de1997-05-09 02:22:59 +0000468a tuple containing its pid and exit status indication (encoded as for
Fred Drake75aae9a1998-03-11 05:29:58 +0000469\function{wait()}). The semantics of the call are affected by the
470value of the integer \var{options}, which should be \code{0} for
471normal operation. (If the system does not support
472\function{waitpid()}, this always raises \exception{error}. Not on
473MS-DOS.)
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000474\end{funcdesc}
475
Fred Drakecce10901998-03-17 06:33:25 +0000476\begin{funcdesc}{write}{fd, str}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000477Write the string \var{str} to file descriptor \var{fd}.
478Return the number of bytes actually written.
Guido van Rossum28379701995-01-12 12:38:22 +0000479
480Note: this function is intended for low-level I/O and must be applied
Fred Drake75aae9a1998-03-11 05:29:58 +0000481to a file descriptor as returned by \function{open()} or
482\function{pipe()}. To write a ``file object'' returned by the
483built-in function \function{open()} or by \function{popen()} or
484\function{fdopen()}, or \code{sys.stdout} or \code{sys.stderr}, use
485its \method{write()} method.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000486\end{funcdesc}
Guido van Rossum4bbe9c01995-03-30 16:00:36 +0000487
488\begin{datadesc}{WNOHANG}
Fred Drake75aae9a1998-03-11 05:29:58 +0000489The option for \function{waitpid()} to avoid hanging if no child
490process status is available immediately.
Guido van Rossum4bbe9c01995-03-30 16:00:36 +0000491\end{datadesc}
Barry Warsawe5a43a41996-12-19 23:50:34 +0000492
493
494\begin{datadesc}{O_RDONLY}
Fred Drake86b5dce1998-02-13 21:55:21 +0000495\dataline{O_WRONLY}
496\dataline{O_RDWR}
497\dataline{O_NDELAY}
498\dataline{O_NONBLOCK}
499\dataline{O_APPEND}
500\dataline{O_DSYNC}
501\dataline{O_RSYNC}
502\dataline{O_SYNC}
503\dataline{O_NOCTTY}
504\dataline{O_CREAT}
505\dataline{O_EXCL}
506\dataline{O_TRUNC}
Fred Drake75aae9a1998-03-11 05:29:58 +0000507Options for the \code{flag} argument to the \function{open()} function.
Barry Warsawe5a43a41996-12-19 23:50:34 +0000508These can be bit-wise OR'd together.
509\end{datadesc}