blob: 43d63e5cf3ae9923f655bd1ae68121fcc1bb3e9b [file] [log] [blame]
Fred Drake295da241998-08-10 19:42:37 +00001\section{\module{posix} ---
2 The most common \POSIX{} system calls.}
Fred Drakeb91e9341998-07-23 17:59:49 +00003\declaremodule{builtin}{posix}
4
5\modulesynopsis{The most common \POSIX{} system calls (normally used via module
6\module{os}).}
7
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00008
9This module provides access to operating system functionality that is
Fred Drake75aae9a1998-03-11 05:29:58 +000010standardized by the \C{} Standard and the \POSIX{} standard (a thinly
11disguised \UNIX{} interface).
Guido van Rossum470be141995-03-17 16:07:09 +000012
13\strong{Do not import this module directly.} Instead, import the
Fred Drake75aae9a1998-03-11 05:29:58 +000014module \module{os}, which provides a \emph{portable} version of this
15interface. On \UNIX{}, the \module{os} module provides a superset of
16the \module{posix} interface. On non-\UNIX{} operating systems the
17\module{posix} module is not available, but a subset is always
18available through the \module{os} interface. Once \module{os} is
19imported, there is \emph{no} performance penalty in using it instead
20of \module{posix}. In addition, \module{os} provides some additional
21functionality, such as automatically calling \function{putenv()}
22when an entry in \code{os.environ} is changed.
Fred Drake62063941997-12-15 21:42:51 +000023\refstmodindex{os}
Guido van Rossum470be141995-03-17 16:07:09 +000024
Guido van Rossum282290f1997-08-27 14:54:25 +000025The descriptions below are very terse; refer to the corresponding
Fred Drake65b32f71998-02-09 20:27:12 +000026\UNIX{} manual (or \POSIX{} documentation) entry for more information.
Guido van Rossum282290f1997-08-27 14:54:25 +000027Arguments called \var{path} refer to a pathname given as a string.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000028
Barry Warsaweef2cd11998-07-23 19:50:09 +000029Errors are reported as exceptions; the usual exceptions are given for
30type errors, while errors reported by the system calls raise
31\exception{error} (a synonym for the standard exception
32\exception{OSError}), described
33below.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000034
Fred Drake75aae9a1998-03-11 05:29:58 +000035Module \module{posix} defines the following data items:
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000036
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000037\begin{datadesc}{environ}
Guido van Rossum04101961998-10-24 20:16:56 +000038A dictionary or dictionary look-alike representing the string
39environment at the time the interpreter was started.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000040For example,
41\code{posix.environ['HOME']}
42is the pathname of your home directory, equivalent to
43\code{getenv("HOME")}
Fred Drake75aae9a1998-03-11 05:29:58 +000044in \C{}.
Guido van Rossum9c43c591997-08-08 21:05:09 +000045
Guido van Rossum470be141995-03-17 16:07:09 +000046Modifying this dictionary does not affect the string environment
Fred Drake75aae9a1998-03-11 05:29:58 +000047passed on by \function{execv()}, \function{popen()} or
48\function{system()}; if you need to change the environment, pass
49\code{environ} to \function{execve()} or add variable assignments and
50export statements to the command string for \function{system()} or
51\function{popen()}.
Guido van Rossum9c43c591997-08-08 21:05:09 +000052
Fred Drake75aae9a1998-03-11 05:29:58 +000053\emph{However:} If you are using this module via the \module{os}
54module (as you should -- see the introduction above), \code{environ}
55is a a mapping object that behaves almost like a dictionary but
Fred Drakec024c991998-10-28 18:19:16 +000056invokes \function{putenv()} automatically whenever an item is changed.
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 Rossum74429ea1999-01-06 23:03:43 +000083\begin{funcdesc}{access}{path, mode}
84Check read/write/execute permissions for this process or extance of file
85\var{path}. Return \code{1} if access is granted, \code{0} if not.
86See the \UNIX{} manual for the semantics.
87\end{funcdesc}
88
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000089\begin{funcdesc}{chdir}{path}
90Change the current working directory to \var{path}.
91\end{funcdesc}
92
Fred Drakecce10901998-03-17 06:33:25 +000093\begin{funcdesc}{chmod}{path, mode}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000094Change the mode of \var{path} to the numeric \var{mode}.
95\end{funcdesc}
96
Fred Drakecce10901998-03-17 06:33:25 +000097\begin{funcdesc}{chown}{path, uid, gid}
Guido van Rossum31cce971995-01-04 19:17:34 +000098Change the owner and group id of \var{path} to the numeric \var{uid}
99and \var{gid}.
100(Not on MS-DOS.)
101\end{funcdesc}
102
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000103\begin{funcdesc}{close}{fd}
104Close file descriptor \var{fd}.
Guido van Rossum28379701995-01-12 12:38:22 +0000105
106Note: this function is intended for low-level I/O and must be applied
Fred Drake75aae9a1998-03-11 05:29:58 +0000107to a file descriptor as returned by \function{open()} or
108\function{pipe()}. To close a ``file object'' returned by the
109built-in function \function{open()} or by \function{popen()} or
110\function{fdopen()}, use its \method{close()} method.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000111\end{funcdesc}
112
113\begin{funcdesc}{dup}{fd}
114Return a duplicate of file descriptor \var{fd}.
115\end{funcdesc}
116
Fred Drakecce10901998-03-17 06:33:25 +0000117\begin{funcdesc}{dup2}{fd, fd2}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000118Duplicate file descriptor \var{fd} to \var{fd2}, closing the latter
Fred Drake75aae9a1998-03-11 05:29:58 +0000119first if necessary.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000120\end{funcdesc}
121
Fred Drakecce10901998-03-17 06:33:25 +0000122\begin{funcdesc}{execv}{path, args}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000123Execute the executable \var{path} with argument list \var{args},
124replacing the current process (i.e., the Python interpreter).
125The argument list may be a tuple or list of strings.
126(Not on MS-DOS.)
127\end{funcdesc}
128
Fred Drakecce10901998-03-17 06:33:25 +0000129\begin{funcdesc}{execve}{path, args, env}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000130Execute the executable \var{path} with argument list \var{args},
131and environment \var{env},
132replacing the current process (i.e., the Python interpreter).
133The argument list may be a tuple or list of strings.
134The environment must be a dictionary mapping strings to strings.
135(Not on MS-DOS.)
136\end{funcdesc}
137
138\begin{funcdesc}{_exit}{n}
139Exit to the system with status \var{n}, without calling cleanup
140handlers, flushing stdio buffers, etc.
141(Not on MS-DOS.)
142
143Note: the standard way to exit is \code{sys.exit(\var{n})}.
Fred Drake75aae9a1998-03-11 05:29:58 +0000144\function{_exit()} should normally only be used in the child process
145after a \function{fork()}.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000146\end{funcdesc}
147
Fred Drakecce10901998-03-17 06:33:25 +0000148\begin{funcdesc}{fdopen}{fd\optional{, mode\optional{, bufsize}}}
Guido van Rossum28379701995-01-12 12:38:22 +0000149Return an open file object connected to the file descriptor \var{fd}.
150The \var{mode} and \var{bufsize} arguments have the same meaning as
Fred Drake75aae9a1998-03-11 05:29:58 +0000151the corresponding arguments to the built-in \function{open()} function.
Guido van Rossumc5c67bc1994-02-15 15:59:23 +0000152\end{funcdesc}
153
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000154\begin{funcdesc}{fork}{}
Fred Drake75aae9a1998-03-11 05:29:58 +0000155Fork a child process. Return \code{0} in the child, the child's
156process id in the parent.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000157(Not on MS-DOS.)
158\end{funcdesc}
159
160\begin{funcdesc}{fstat}{fd}
Fred Drake75aae9a1998-03-11 05:29:58 +0000161Return status for file descriptor \var{fd}, like \function{stat()}.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000162\end{funcdesc}
163
Fred Drakecce10901998-03-17 06:33:25 +0000164\begin{funcdesc}{ftruncate}{fd, length}
Guido van Rossumf967bf61997-06-02 17:28:51 +0000165Truncate the file corresponding to file descriptor \var{fd},
166so that it is at most \var{length} bytes in size.
167\end{funcdesc}
168
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000169\begin{funcdesc}{getcwd}{}
170Return a string representing the current working directory.
171\end{funcdesc}
172
173\begin{funcdesc}{getegid}{}
Guido van Rossumeb0f0661997-12-30 20:38:16 +0000174Return the current process' effective group id.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000175(Not on MS-DOS.)
176\end{funcdesc}
177
178\begin{funcdesc}{geteuid}{}
Guido van Rossumeb0f0661997-12-30 20:38:16 +0000179Return the current process' effective user id.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000180(Not on MS-DOS.)
181\end{funcdesc}
182
183\begin{funcdesc}{getgid}{}
Guido van Rossumeb0f0661997-12-30 20:38:16 +0000184Return the current process' group id.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000185(Not on MS-DOS.)
186\end{funcdesc}
187
Guido van Rossum1e8b63e1996-06-26 19:22:46 +0000188\begin{funcdesc}{getpgrp}{}
Fred Drake3b02ddf1998-12-21 18:52:53 +0000189\index{process!group}
Guido van Rossum1e8b63e1996-06-26 19:22:46 +0000190Return the current process group id.
191(Not on MS-DOS.)
192\end{funcdesc}
193
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000194\begin{funcdesc}{getpid}{}
Fred Drake3b02ddf1998-12-21 18:52:53 +0000195\index{process!id}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000196Return the current process id.
197(Not on MS-DOS.)
198\end{funcdesc}
199
200\begin{funcdesc}{getppid}{}
Fred Drake3b02ddf1998-12-21 18:52:53 +0000201\index{process!id of parent}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000202Return the parent's process id.
203(Not on MS-DOS.)
204\end{funcdesc}
205
206\begin{funcdesc}{getuid}{}
Fred Drake3b02ddf1998-12-21 18:52:53 +0000207\index{user id}
Guido van Rossumeb0f0661997-12-30 20:38:16 +0000208Return the current process' user id.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000209(Not on MS-DOS.)
210\end{funcdesc}
211
Fred Drakecce10901998-03-17 06:33:25 +0000212\begin{funcdesc}{kill}{pid, sig}
Fred Drake3b02ddf1998-12-21 18:52:53 +0000213\index{process!killing}
214\index{process!signalling}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000215Kill the process \var{pid} with signal \var{sig}.
216(Not on MS-DOS.)
217\end{funcdesc}
218
Fred Drakecce10901998-03-17 06:33:25 +0000219\begin{funcdesc}{link}{src, dst}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000220Create a hard link pointing to \var{src} named \var{dst}.
221(Not on MS-DOS.)
222\end{funcdesc}
223
224\begin{funcdesc}{listdir}{path}
225Return a list containing the names of the entries in the directory.
Guido van Rossum8c07bb41996-02-12 23:16:08 +0000226The list is in arbitrary order. It does not include the special
227entries \code{'.'} and \code{'..'} even if they are present in the
228directory.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000229\end{funcdesc}
230
Fred Drakecce10901998-03-17 06:33:25 +0000231\begin{funcdesc}{lseek}{fd, pos, how}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000232Set the current position of file descriptor \var{fd} to position
Fred Drake75aae9a1998-03-11 05:29:58 +0000233\var{pos}, modified by \var{how}: \code{0} to set the position
234relative to the beginning of the file; \code{1} to set it relative to
235the current position; \code{2} to set it relative to the end of the
236file.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000237\end{funcdesc}
238
239\begin{funcdesc}{lstat}{path}
Fred Drake75aae9a1998-03-11 05:29:58 +0000240Like \function{stat()}, but do not follow symbolic links. (On systems
241without symbolic links, this is identical to \function{stat()}.)
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000242\end{funcdesc}
243
Fred Drakecce10901998-03-17 06:33:25 +0000244\begin{funcdesc}{mkfifo}{path\optional{, mode}}
Fred Drake65b32f71998-02-09 20:27:12 +0000245Create a FIFO (a \POSIX{} named pipe) named \var{path} with numeric mode
Fred Drake75aae9a1998-03-11 05:29:58 +0000246\var{mode}. The default \var{mode} is \code{0666} (octal). The current
Guido van Rossum1e8b63e1996-06-26 19:22:46 +0000247umask value is first masked out from the mode.
248(Not on MS-DOS.)
249
250FIFOs are pipes that can be accessed like regular files. FIFOs exist
Fred Drake75aae9a1998-03-11 05:29:58 +0000251until they are deleted (for example with \function{os.unlink()}).
252Generally, FIFOs are used as rendezvous between ``client'' and
Guido van Rossum1e8b63e1996-06-26 19:22:46 +0000253``server'' type processes: the server opens the FIFO for reading, and
Fred Drake75aae9a1998-03-11 05:29:58 +0000254the client opens it for writing. Note that \function{mkfifo()}
255doesn't open the FIFO --- it just creates the rendezvous point.
Guido van Rossum1e8b63e1996-06-26 19:22:46 +0000256\end{funcdesc}
257
Fred Drakecce10901998-03-17 06:33:25 +0000258\begin{funcdesc}{mkdir}{path\optional{, mode}}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000259Create a directory named \var{path} with numeric mode \var{mode}.
Fred Drake75aae9a1998-03-11 05:29:58 +0000260The default \var{mode} is \code{0777} (octal). On some systems,
261\var{mode} is ignored. Where it is used, the current umask value is
262first masked out.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000263\end{funcdesc}
264
265\begin{funcdesc}{nice}{increment}
Fred Drake75aae9a1998-03-11 05:29:58 +0000266Add \var{increment} to the process' ``niceness''. Return the new
267niceness. (Not on MS-DOS.)
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000268\end{funcdesc}
269
Fred Drakecce10901998-03-17 06:33:25 +0000270\begin{funcdesc}{open}{file, flags\optional{, mode}}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000271Open the file \var{file} and set various flags according to
272\var{flags} and possibly its mode according to \var{mode}.
Fred Drake75aae9a1998-03-11 05:29:58 +0000273The default \var{mode} is \code{0777} (octal), and the current umask
274value is first masked out. Return the file descriptor for the newly
275opened file.
Guido van Rossum28379701995-01-12 12:38:22 +0000276
Fred Drake75aae9a1998-03-11 05:29:58 +0000277For a description of the flag and mode values, see the \UNIX{} or \C{}
278run-time documentation; flag constants (like \constant{O_RDONLY} and
279\constant{O_WRONLY}) are defined in this module too (see below).
Guido van Rossum9c43c591997-08-08 21:05:09 +0000280
Guido van Rossum28379701995-01-12 12:38:22 +0000281Note: this function is intended for low-level I/O. For normal usage,
Fred Drake75aae9a1998-03-11 05:29:58 +0000282use the built-in function \function{open()}, which returns a ``file
283object'' with \method{read()} and \method{write()} methods (and many
284more).
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000285\end{funcdesc}
286
287\begin{funcdesc}{pipe}{}
Fred Drake75aae9a1998-03-11 05:29:58 +0000288Create a pipe. Return a pair of file descriptors \code{(\var{r},
289\var{w})} usable for reading and writing, respectively.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000290(Not on MS-DOS.)
291\end{funcdesc}
292
Guido van Rossum38e50881996-07-21 02:21:49 +0000293\begin{funcdesc}{plock}{op}
294Lock program segments into memory. The value of \var{op}
295(defined in \code{<sys/lock.h>}) determines which segments are locked.
296(Not on MS-DOS.)
297\end{funcdesc}
298
Fred Drakecce10901998-03-17 06:33:25 +0000299\begin{funcdesc}{popen}{command\optional{, mode\optional{, bufsize}}}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000300Open a pipe to or from \var{command}. The return value is an open
301file object connected to the pipe, which can be read or written
Guido van Rossum28379701995-01-12 12:38:22 +0000302depending on whether \var{mode} is \code{'r'} (default) or \code{'w'}.
303The \var{bufsize} argument has the same meaning as the corresponding
Fred Drake75aae9a1998-03-11 05:29:58 +0000304argument to the built-in \function{open()} function. The exit status of
305the command (encoded in the format specified for \function{wait()}) is
306available as the return value of the \method{close()} method of the file
Guido van Rossumf35b8841998-10-15 13:28:29 +0000307object, except that when the exit status is zero (termination without
308errors), \code{None} is returned.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000309(Not on MS-DOS.)
310\end{funcdesc}
311
Fred Drakecce10901998-03-17 06:33:25 +0000312\begin{funcdesc}{putenv}{varname, value}
Fred Drake52405c81998-03-16 05:21:08 +0000313\index{environment variables!setting}
Fred Drake75aae9a1998-03-11 05:29:58 +0000314Set the environment variable named \var{varname} to the string
315\var{value}. Such changes to the environment affect subprocesses
316started with \function{os.system()}, \function{os.popen()} or
317\function{os.fork()} and \function{os.execv()}. (Not on all systems.)
Guido van Rossumf967bf61997-06-02 17:28:51 +0000318
Fred Drake75aae9a1998-03-11 05:29:58 +0000319When \function{putenv()} is
Guido van Rossumf967bf61997-06-02 17:28:51 +0000320supported, assignments to items in \code{os.environ} are automatically
Fred Drake75aae9a1998-03-11 05:29:58 +0000321translated into corresponding calls to \function{putenv()}; however,
322calls to \function{putenv()} don't update \code{os.environ}, so it is
Guido van Rossumf967bf61997-06-02 17:28:51 +0000323actually preferable to assign to items of \code{os.environ}.
324\end{funcdesc}
325
Guido van Rossum0bfd1461997-10-05 18:54:52 +0000326\begin{funcdesc}{strerror}{code}
327Return the error message corresponding to the error code in \var{code}.
328\end{funcdesc}
329
Guido van Rossum74429ea1999-01-06 23:03:43 +0000330\begin{funcdesc}{ttyname}{fd}
331Return a string which specifies the terminal device associated with
332file-descriptor \var{fd}. If \var{fd} is not associated with a terminal
333device, an exception is raised.
334\end{funcdesc}
335
Fred Drakecce10901998-03-17 06:33:25 +0000336\begin{funcdesc}{read}{fd, n}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000337Read at most \var{n} bytes from file descriptor \var{fd}.
338Return a string containing the bytes read.
Guido van Rossum28379701995-01-12 12:38:22 +0000339
340Note: this function is intended for low-level I/O and must be applied
Fred Drake75aae9a1998-03-11 05:29:58 +0000341to a file descriptor as returned by \function{open()} or
342\function{pipe()}. To read a ``file object'' returned by the
343built-in function \function{open()} or by \function{popen()} or
344\function{fdopen()}, or \code{sys.stdin}, use its
345\method{read()} or \method{readline()} methods.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000346\end{funcdesc}
347
348\begin{funcdesc}{readlink}{path}
349Return a string representing the path to which the symbolic link
350points. (On systems without symbolic links, this always raises
Fred Drake75aae9a1998-03-11 05:29:58 +0000351\exception{error}.)
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000352\end{funcdesc}
353
Guido van Rossum8c07bb41996-02-12 23:16:08 +0000354\begin{funcdesc}{remove}{path}
Fred Drake75aae9a1998-03-11 05:29:58 +0000355Remove the file \var{path}. See \function{rmdir()} below to remove a
356directory. This is identical to the \function{unlink()} function
357documented below.
Guido van Rossum8c07bb41996-02-12 23:16:08 +0000358\end{funcdesc}
359
Fred Drakecce10901998-03-17 06:33:25 +0000360\begin{funcdesc}{rename}{src, dst}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000361Rename the file or directory \var{src} to \var{dst}.
362\end{funcdesc}
363
364\begin{funcdesc}{rmdir}{path}
365Remove the directory \var{path}.
366\end{funcdesc}
367
368\begin{funcdesc}{setgid}{gid}
Guido van Rossumeb0f0661997-12-30 20:38:16 +0000369Set the current process' group id.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000370(Not on MS-DOS.)
371\end{funcdesc}
372
Guido van Rossum1e8b63e1996-06-26 19:22:46 +0000373\begin{funcdesc}{setpgrp}{}
Fred Drake75aae9a1998-03-11 05:29:58 +0000374Calls the system call \cfunction{setpgrp()} or \cfunction{setpgrp(0,
3750)} depending on which version is implemented (if any). See the
376\UNIX{} manual for the semantics.
Guido van Rossum1e8b63e1996-06-26 19:22:46 +0000377(Not on MS-DOS.)
378\end{funcdesc}
379
Fred Drakecce10901998-03-17 06:33:25 +0000380\begin{funcdesc}{setpgid}{pid, pgrp}
Fred Drake75aae9a1998-03-11 05:29:58 +0000381Calls the system call \cfunction{setpgid()}. See the \UNIX{} manual
382for the semantics.
Guido van Rossum1e8b63e1996-06-26 19:22:46 +0000383(Not on MS-DOS.)
384\end{funcdesc}
385
386\begin{funcdesc}{setsid}{}
Fred Drake75aae9a1998-03-11 05:29:58 +0000387Calls the system call \cfunction{setsid()}. See the \UNIX{} manual
388for the semantics.
Guido van Rossum1e8b63e1996-06-26 19:22:46 +0000389(Not on MS-DOS.)
390\end{funcdesc}
391
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000392\begin{funcdesc}{setuid}{uid}
Guido van Rossumeb0f0661997-12-30 20:38:16 +0000393Set the current process' user id.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000394(Not on MS-DOS.)
395\end{funcdesc}
396
397\begin{funcdesc}{stat}{path}
Fred Drake75aae9a1998-03-11 05:29:58 +0000398Perform a \cfunction{stat()} system call on the given path. The
399return value is a tuple of at least 10 integers giving the most
400important (and portable) members of the \emph{stat} structure, in the
401order
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000402\code{st_mode},
403\code{st_ino},
404\code{st_dev},
405\code{st_nlink},
406\code{st_uid},
407\code{st_gid},
408\code{st_size},
409\code{st_atime},
410\code{st_mtime},
411\code{st_ctime}.
412More items may be added at the end by some implementations.
413(On MS-DOS, some items are filled with dummy values.)
414
Fred Drake75aae9a1998-03-11 05:29:58 +0000415Note: The standard module \module{stat}\refstmodindex{stat} defines
416functions and constants that are useful for extracting information
417from a stat structure.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000418\end{funcdesc}
419
Fred Drakecce10901998-03-17 06:33:25 +0000420\begin{funcdesc}{symlink}{src, dst}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000421Create a symbolic link pointing to \var{src} named \var{dst}. (On
Fred Drake75aae9a1998-03-11 05:29:58 +0000422systems without symbolic links, this always raises \exception{error}.)
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000423\end{funcdesc}
424
425\begin{funcdesc}{system}{command}
426Execute the command (a string) in a subshell. This is implemented by
Fred Drake75aae9a1998-03-11 05:29:58 +0000427calling the Standard \C{} function \cfunction{system()}, and has the
428same limitations. Changes to \code{posix.environ}, \code{sys.stdin}
429etc.\ are not reflected in the environment of the executed command.
430The return value is the exit status of the process encoded in the
431format specified for \function{wait()}.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000432\end{funcdesc}
433
Guido van Rossum1e8b63e1996-06-26 19:22:46 +0000434\begin{funcdesc}{tcgetpgrp}{fd}
435Return the process group associated with the terminal given by
Fred Drake75aae9a1998-03-11 05:29:58 +0000436\var{fd} (an open file descriptor as returned by \function{open()}).
Guido van Rossum1e8b63e1996-06-26 19:22:46 +0000437(Not on MS-DOS.)
438\end{funcdesc}
439
Fred Drakecce10901998-03-17 06:33:25 +0000440\begin{funcdesc}{tcsetpgrp}{fd, pg}
Guido van Rossum1e8b63e1996-06-26 19:22:46 +0000441Set the process group associated with the terminal given by
Fred Drake75aae9a1998-03-11 05:29:58 +0000442\var{fd} (an open file descriptor as returned by \function{open()})
Guido van Rossum1e8b63e1996-06-26 19:22:46 +0000443to \var{pg}.
444(Not on MS-DOS.)
445\end{funcdesc}
446
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000447\begin{funcdesc}{times}{}
Guido van Rossum1e150611995-09-13 17:36:35 +0000448Return a 5-tuple of floating point numbers indicating accumulated (CPU
449or other)
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000450times, in seconds. The items are: user time, system time, children's
Guido van Rossum1e150611995-09-13 17:36:35 +0000451user time, children's system time, and elapsed real time since a fixed
452point in the past, in that order. See the \UNIX{}
Fred Drake75aae9a1998-03-11 05:29:58 +0000453manual page \manpage{times}{2}. (Not on MS-DOS.)
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000454\end{funcdesc}
455
456\begin{funcdesc}{umask}{mask}
457Set the current numeric umask and returns the previous umask.
458(Not on MS-DOS.)
459\end{funcdesc}
460
461\begin{funcdesc}{uname}{}
462Return a 5-tuple containing information identifying the current
463operating system. The tuple contains 5 strings:
Fred Drake75aae9a1998-03-11 05:29:58 +0000464\code{(\var{sysname}, \var{nodename}, \var{release}, \var{version},
465\var{machine})}. Some systems truncate the nodename to 8
Guido van Rossum6bb1adc1995-03-13 10:03:32 +0000466characters or to the leading component; a better way to get the
Fred Drake75aae9a1998-03-11 05:29:58 +0000467hostname is \function{socket.gethostname()}%
Fred Drake371ecc01998-03-12 06:44:58 +0000468\withsubitem{(in module socket)}{\ttindex{gethostname()}}
Fred Drake75aae9a1998-03-11 05:29:58 +0000469or even
470\code{socket.gethostbyaddr(socket.gethostname())}%
Fred Drake371ecc01998-03-12 06:44:58 +0000471\withsubitem{(in module socket)}{\ttindex{gethostbyaddr()}}.
Guido van Rossumeb0f0661997-12-30 20:38:16 +0000472(Not on MS-DOS, nor on older \UNIX{} systems.)
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000473\end{funcdesc}
474
475\begin{funcdesc}{unlink}{path}
Guido van Rossum8c07bb41996-02-12 23:16:08 +0000476Remove the file \var{path}. This is the same function as \code{remove};
477the \code{unlink} name is its traditional \UNIX{} name.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000478\end{funcdesc}
479
Fred Drakecaa33791998-11-30 21:53:47 +0000480\begin{funcdesc}{utime}{path, (atime, mtime)}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000481Set the access and modified time of the file to the given values.
482(The second argument is a tuple of two items.)
483\end{funcdesc}
484
485\begin{funcdesc}{wait}{}
486Wait for completion of a child process, and return a tuple containing
Guido van Rossum7e691de1997-05-09 02:22:59 +0000487its pid and exit status indication: a 16-bit number, whose low byte is
488the signal number that killed the process, and whose high byte is the
489exit status (if the signal number is zero); the high bit of the low
490byte is set if a core file was produced. (Not on MS-DOS.)
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000491\end{funcdesc}
492
Fred Drakecce10901998-03-17 06:33:25 +0000493\begin{funcdesc}{waitpid}{pid, options}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000494Wait for completion of a child process given by proces id, and return
Guido van Rossum7e691de1997-05-09 02:22:59 +0000495a tuple containing its pid and exit status indication (encoded as for
Fred Drake75aae9a1998-03-11 05:29:58 +0000496\function{wait()}). The semantics of the call are affected by the
497value of the integer \var{options}, which should be \code{0} for
498normal operation. (If the system does not support
499\function{waitpid()}, this always raises \exception{error}. Not on
500MS-DOS.)
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000501\end{funcdesc}
502
Fred Drakecce10901998-03-17 06:33:25 +0000503\begin{funcdesc}{write}{fd, str}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000504Write the string \var{str} to file descriptor \var{fd}.
505Return the number of bytes actually written.
Guido van Rossum28379701995-01-12 12:38:22 +0000506
507Note: this function is intended for low-level I/O and must be applied
Fred Drake75aae9a1998-03-11 05:29:58 +0000508to a file descriptor as returned by \function{open()} or
509\function{pipe()}. To write a ``file object'' returned by the
510built-in function \function{open()} or by \function{popen()} or
511\function{fdopen()}, or \code{sys.stdout} or \code{sys.stderr}, use
512its \method{write()} method.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000513\end{funcdesc}
Guido van Rossum4bbe9c01995-03-30 16:00:36 +0000514
515\begin{datadesc}{WNOHANG}
Fred Drake75aae9a1998-03-11 05:29:58 +0000516The option for \function{waitpid()} to avoid hanging if no child
517process status is available immediately.
Guido van Rossum4bbe9c01995-03-30 16:00:36 +0000518\end{datadesc}
Barry Warsawe5a43a41996-12-19 23:50:34 +0000519
520
521\begin{datadesc}{O_RDONLY}
Fred Drake86b5dce1998-02-13 21:55:21 +0000522\dataline{O_WRONLY}
523\dataline{O_RDWR}
524\dataline{O_NDELAY}
525\dataline{O_NONBLOCK}
526\dataline{O_APPEND}
527\dataline{O_DSYNC}
528\dataline{O_RSYNC}
529\dataline{O_SYNC}
530\dataline{O_NOCTTY}
531\dataline{O_CREAT}
532\dataline{O_EXCL}
533\dataline{O_TRUNC}
Fred Drake75aae9a1998-03-11 05:29:58 +0000534Options for the \code{flag} argument to the \function{open()} function.
Barry Warsawe5a43a41996-12-19 23:50:34 +0000535These can be bit-wise OR'd together.
536\end{datadesc}