blob: 4297175f9ff66f0b4b949cb40f3d542d3ba9e6d8 [file] [log] [blame]
Fred Drake295da241998-08-10 19:42:37 +00001\section{\module{os} ---
Fred Drake215fe2f1999-02-02 19:02:35 +00002 Miscellaneous OS interfaces}
Fred Drakeb91e9341998-07-23 17:59:49 +00003
Fred Drakeec6baaf1999-04-21 18:13:31 +00004\declaremodule{standard}{os}
Fred Drakeb91e9341998-07-23 17:59:49 +00005\modulesynopsis{Miscellaneous OS interfaces.}
6
Fred Drakec4f15af1998-03-10 03:17:26 +00007
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00008This module provides a more portable way of using operating system
9(OS) dependent functionality than importing an OS dependent built-in
Fred Drake2f979011999-06-11 18:28:37 +000010module like \refmodule{posix} or \module{nt}.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000011
Fred Drake215fe2f1999-02-02 19:02:35 +000012This module searches for an OS dependent built-in module like
Fred Drake2f979011999-06-11 18:28:37 +000013\module{mac} or \refmodule{posix} and exports the same functions and data
Fred Drake215fe2f1999-02-02 19:02:35 +000014as found there. The design of all Python's built-in OS dependent
15modules is such that as long as the same functionality is available,
Fred Drake907e76b2001-07-06 20:30:11 +000016it uses the same interface; for example, the function
Fred Drakeec6baaf1999-04-21 18:13:31 +000017\code{os.stat(\var{path})} returns stat information about \var{path} in
18the same format (which happens to have originated with the
19\POSIX{} interface).
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000020
21Extensions peculiar to a particular OS are also available through the
Fred Drakec4f15af1998-03-10 03:17:26 +000022\module{os} module, but using them is of course a threat to
23portability!
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000024
Fred Drakec4f15af1998-03-10 03:17:26 +000025Note that after the first time \module{os} is imported, there is
26\emph{no} performance penalty in using functions from \module{os}
27instead of directly from the OS dependent built-in module, so there
28should be \emph{no} reason not to use \module{os}!
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000029
Fred Drake215fe2f1999-02-02 19:02:35 +000030
Fred Drake859dc531999-07-01 13:54:40 +000031% Frank Stajano <fstajano@uk.research.att.com> complained that it
32% wasn't clear that the entries described in the subsections were all
33% available at the module level (most uses of subsections are
34% different); I think this is only a problem for the HTML version,
35% where the relationship may not be as clear.
36%
37\ifhtml
38The \module{os} module contains many functions and data values.
39The items below and in the following sub-sections are all available
40directly from the \module{os} module.
41\fi
42
43
Fred Drake215fe2f1999-02-02 19:02:35 +000044\begin{excdesc}{error}
Fred Drake907e76b2001-07-06 20:30:11 +000045This exception is raised when a function returns a system-related
46error (not for illegal argument types or other incidental errors).
47This is also known as the built-in exception \exception{OSError}. The
Fred Drake215fe2f1999-02-02 19:02:35 +000048accompanying value is a pair containing the numeric error code from
49\cdata{errno} and the corresponding string, as would be printed by the
50C function \cfunction{perror()}. See the module
51\refmodule{errno}\refbimodindex{errno}, which contains names for the
52error codes defined by the underlying operating system.
53
54When exceptions are classes, this exception carries two attributes,
55\member{errno} and \member{strerror}. The first holds the value of
56the C \cdata{errno} variable, and the latter holds the corresponding
57error message from \cfunction{strerror()}. For exceptions that
Fred Drake907e76b2001-07-06 20:30:11 +000058involve a file system path (such as \function{chdir()} or
Fred Drake215fe2f1999-02-02 19:02:35 +000059\function{unlink()}), the exception instance will contain a third
60attribute, \member{filename}, which is the file name passed to the
61function.
62
63When exceptions are strings, the string for the exception is
64\code{'OSError'}.
65\end{excdesc}
Guido van Rossum470be141995-03-17 16:07:09 +000066
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000067\begin{datadesc}{name}
Guido van Rossum470be141995-03-17 16:07:09 +000068The name of the OS dependent module imported. The following names
69have currently been registered: \code{'posix'}, \code{'nt'},
Fred Drake933d5a71999-09-17 14:38:39 +000070\code{'dos'}, \code{'mac'}, \code{'os2'}, \code{'ce'}, \code{'java'}.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000071\end{datadesc}
72
73\begin{datadesc}{path}
74The corresponding OS dependent standard module for pathname
Fred Drake907e76b2001-07-06 20:30:11 +000075operations, such as \module{posixpath} or \module{macpath}. Thus,
76given the proper imports, \code{os.path.split(\var{file})} is
77equivalent to but more portable than
78\code{posixpath.split(\var{file})}. Note that this is also an
79importable module: it may be imported directly as
Fred Drake215fe2f1999-02-02 19:02:35 +000080\refmodule{os.path}.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000081\end{datadesc}
82
Fred Drake215fe2f1999-02-02 19:02:35 +000083
84
85\subsection{Process Parameters \label{os-procinfo}}
86
87These functions and data items provide information and operate on the
88current process and user.
89
Fred Drake215fe2f1999-02-02 19:02:35 +000090\begin{datadesc}{environ}
Fred Drake0e1de8b1999-04-29 12:57:32 +000091A mapping object representing the string environment. For example,
92\code{environ['HOME']} is the pathname of your home directory (on some
93platforms), and is equivalent to \code{getenv("HOME")} in C.
Fred Drake215fe2f1999-02-02 19:02:35 +000094
95If the platform supports the \function{putenv()} function, this
96mapping may be used to modify the environment as well as query the
97environment. \function{putenv()} will be called automatically when
98the mapping is modified.
99
100If \function{putenv()} is not provided, this mapping may be passed to
101the appropriate process-creation functions to cause child processes to
102use a modified environment.
103\end{datadesc}
104
Fred Drake6db897c1999-07-12 16:49:30 +0000105\begin{funcdescni}{chdir}{path}
106\funclineni{getcwd}{}
107These functions are described in ``Files and Directories'' (section
108\ref{os-file-dir}).
109\end{funcdescni}
Fred Drake215fe2f1999-02-02 19:02:35 +0000110
Fred Drake18f7a451999-12-09 22:11:43 +0000111\begin{funcdesc}{ctermid}{}
112Return the filename corresponding to the controlling terminal of the
113process.
114Availability: \UNIX{}.
115\end{funcdesc}
116
Fred Drake215fe2f1999-02-02 19:02:35 +0000117\begin{funcdesc}{getegid}{}
118Return the current process' effective group id.
119Availability: \UNIX{}.
120\end{funcdesc}
121
122\begin{funcdesc}{geteuid}{}
Fred Drake6b330ba81999-05-25 13:42:26 +0000123\index{user!effective id}
Fred Drake215fe2f1999-02-02 19:02:35 +0000124Return the current process' effective user id.
125Availability: \UNIX{}.
126\end{funcdesc}
127
128\begin{funcdesc}{getgid}{}
Fred Drake6b330ba81999-05-25 13:42:26 +0000129\index{process!group}
Fred Drake215fe2f1999-02-02 19:02:35 +0000130Return the current process' group id.
131Availability: \UNIX{}.
132\end{funcdesc}
133
Fred Drake88f6ca21999-12-15 19:39:04 +0000134\begin{funcdesc}{getgroups}{}
135Return list of supplemental group ids associated with the current
136process.
137Availability: \UNIX{}.
138\end{funcdesc}
139
140\begin{funcdesc}{getlogin}{}
141Return the actual login name for the current process, even if there
142are multiple login names which map to the same user id.
143Availability: \UNIX{}.
144\end{funcdesc}
145
Fred Drake215fe2f1999-02-02 19:02:35 +0000146\begin{funcdesc}{getpgrp}{}
147\index{process!group}
148Return the current process group id.
149Availability: \UNIX{}.
150\end{funcdesc}
151
152\begin{funcdesc}{getpid}{}
153\index{process!id}
154Return the current process id.
155Availability: \UNIX{}, Windows.
156\end{funcdesc}
157
158\begin{funcdesc}{getppid}{}
159\index{process!id of parent}
160Return the parent's process id.
161Availability: \UNIX{}.
162\end{funcdesc}
163
164\begin{funcdesc}{getuid}{}
Fred Drake6b330ba81999-05-25 13:42:26 +0000165\index{user!id}
Fred Drake215fe2f1999-02-02 19:02:35 +0000166Return the current process' user id.
167Availability: \UNIX{}.
168\end{funcdesc}
169
Fred Drake81e142b2001-05-31 20:27:46 +0000170\begin{funcdesc}{getenv}{varname\optional{, value}}
171Return the value of the environment variable \var{varname} if it
172exists, or \var{value} if it doesn't. \var{value} defaults to
173\code{None}.
174Availability: most flavors of \UNIX{}, Windows.
175\end{funcdesc}
176
Fred Drake215fe2f1999-02-02 19:02:35 +0000177\begin{funcdesc}{putenv}{varname, value}
178\index{environment variables!setting}
179Set the environment variable named \var{varname} to the string
180\var{value}. Such changes to the environment affect subprocesses
181started with \function{os.system()}, \function{popen()} or
182\function{fork()} and \function{execv()}.
183Availability: most flavors of \UNIX{}, Windows.
184
185When \function{putenv()} is
186supported, assignments to items in \code{os.environ} are automatically
187translated into corresponding calls to \function{putenv()}; however,
188calls to \function{putenv()} don't update \code{os.environ}, so it is
189actually preferable to assign to items of \code{os.environ}.
190\end{funcdesc}
191
Andrew M. Kuchling8d2f2b22000-07-13 01:26:58 +0000192\begin{funcdesc}{setegid}{egid}
193Set the current process's effective group id.
194Availability: \UNIX{}.
195\end{funcdesc}
196
197\begin{funcdesc}{seteuid}{euid}
198Set the current process's effective user id.
199Availability: \UNIX{}.
200\end{funcdesc}
201
Fred Drake215fe2f1999-02-02 19:02:35 +0000202\begin{funcdesc}{setgid}{gid}
203Set the current process' group id.
204Availability: \UNIX{}.
205\end{funcdesc}
206
207\begin{funcdesc}{setpgrp}{}
208Calls the system call \cfunction{setpgrp()} or \cfunction{setpgrp(0,
2090)} depending on which version is implemented (if any). See the
210\UNIX{} manual for the semantics.
211Availability: \UNIX{}.
212\end{funcdesc}
213
214\begin{funcdesc}{setpgid}{pid, pgrp}
215Calls the system call \cfunction{setpgid()}. See the \UNIX{} manual
216for the semantics.
217Availability: \UNIX{}.
218\end{funcdesc}
219
Andrew M. Kuchling8d2f2b22000-07-13 01:26:58 +0000220\begin{funcdesc}{setreuid}{ruid, euid}
221Set the current process's real and effective user ids.
222Availability: \UNIX{}.
223\end{funcdesc}
224
225\begin{funcdesc}{setregid}{rgid, egid}
226Set the current process's real and effective group ids.
227Availability: \UNIX{}.
228\end{funcdesc}
229
Fred Drake215fe2f1999-02-02 19:02:35 +0000230\begin{funcdesc}{setsid}{}
231Calls the system call \cfunction{setsid()}. See the \UNIX{} manual
232for the semantics.
233Availability: \UNIX{}.
234\end{funcdesc}
235
236\begin{funcdesc}{setuid}{uid}
Fred Drake6b330ba81999-05-25 13:42:26 +0000237\index{user!id, setting}
Fred Drake215fe2f1999-02-02 19:02:35 +0000238Set the current process' user id.
239Availability: \UNIX{}.
240\end{funcdesc}
241
242% placed in this section since it relates to errno.... a little weak ;-(
243\begin{funcdesc}{strerror}{code}
244Return the error message corresponding to the error code in
245\var{code}.
246Availability: \UNIX{}, Windows.
247\end{funcdesc}
248
249\begin{funcdesc}{umask}{mask}
250Set the current numeric umask and returns the previous umask.
251Availability: \UNIX{}, Windows.
252\end{funcdesc}
253
254\begin{funcdesc}{uname}{}
255Return a 5-tuple containing information identifying the current
256operating system. The tuple contains 5 strings:
257\code{(\var{sysname}, \var{nodename}, \var{release}, \var{version},
258\var{machine})}. Some systems truncate the nodename to 8
259characters or to the leading component; a better way to get the
260hostname is \function{socket.gethostname()}
261\withsubitem{(in module socket)}{\ttindex{gethostname()}}
262or even
263\withsubitem{(in module socket)}{\ttindex{gethostbyaddr()}}
264\code{socket.gethostbyaddr(socket.gethostname())}.
265Availability: recent flavors of \UNIX{}.
266\end{funcdesc}
267
268
269
270\subsection{File Object Creation \label{os-newstreams}}
271
272These functions create new file objects.
273
274
275\begin{funcdesc}{fdopen}{fd\optional{, mode\optional{, bufsize}}}
276Return an open file object connected to the file descriptor \var{fd}.
Fred Drake8c9fc001999-08-05 13:41:31 +0000277\index{I/O control!buffering}
Fred Drake215fe2f1999-02-02 19:02:35 +0000278The \var{mode} and \var{bufsize} arguments have the same meaning as
279the corresponding arguments to the built-in \function{open()}
280function.
281Availability: Macintosh, \UNIX{}, Windows.
282\end{funcdesc}
283
284\begin{funcdesc}{popen}{command\optional{, mode\optional{, bufsize}}}
285Open a pipe to or from \var{command}. The return value is an open
286file object connected to the pipe, which can be read or written
287depending on whether \var{mode} is \code{'r'} (default) or \code{'w'}.
288The \var{bufsize} argument has the same meaning as the corresponding
289argument to the built-in \function{open()} function. The exit status of
290the command (encoded in the format specified for \function{wait()}) is
291available as the return value of the \method{close()} method of the file
292object, except that when the exit status is zero (termination without
Fred Drake1319e3e2000-10-03 17:14:27 +0000293errors), \code{None} is returned.
Fred Drake215fe2f1999-02-02 19:02:35 +0000294Availability: \UNIX{}, Windows.
Fred Drakec71c23e2000-10-04 13:57:27 +0000295
296\versionchanged[This function worked unreliably under Windows in
297 earlier versions of Python. This was due to the use of the
298 \cfunction{_popen()} function from the libraries provided with
299 Windows. Newer versions of Python do not use the broken
300 implementation from the Windows libraries]{2.0}
Fred Drake215fe2f1999-02-02 19:02:35 +0000301\end{funcdesc}
302
Fred Drake18f7a451999-12-09 22:11:43 +0000303\begin{funcdesc}{tmpfile}{}
304Return a new file object opened in update mode (\samp{w+}). The file
305has no directory entries associated with it and will be automatically
306deleted once there are no file descriptors for the file.
307Availability: \UNIX{}.
308\end{funcdesc}
Fred Drake215fe2f1999-02-02 19:02:35 +0000309
310
Fred Drake8a9db992000-09-28 20:27:51 +0000311For each of these \function{popen()} variants, if \var{bufsize} is
312specified, it specifies the buffer size for the I/O pipes.
313\var{mode}, if provided, should be the string \code{'b'} or
314\code{'t'}; on Windows this is needed to determine whether the file
315objects should be opened in binary or text mode. The default value
316for \var{mode} is \code{'t'}.
317
Fred Drake046f4d82001-06-11 15:21:48 +0000318\begin{funcdesc}{popen2}{cmd\optional{, mode\optional{, bufsize}}}
Fred Drake8a9db992000-09-28 20:27:51 +0000319Executes \var{cmd} as a sub-process. Returns the file objects
320\code{(\var{child_stdin}, \var{child_stdout})}.
Fred Drake0b9bc202001-06-11 18:25:34 +0000321Availability: \UNIX{}, Windows.
Fred Drake8a9db992000-09-28 20:27:51 +0000322\versionadded{2.0}
323\end{funcdesc}
324
Fred Drake046f4d82001-06-11 15:21:48 +0000325\begin{funcdesc}{popen3}{cmd\optional{, mode\optional{, bufsize}}}
Fred Drake8a9db992000-09-28 20:27:51 +0000326Executes \var{cmd} as a sub-process. Returns the file objects
327\code{(\var{child_stdin}, \var{child_stdout}, \var{child_stderr})}.
Fred Drake0b9bc202001-06-11 18:25:34 +0000328Availability: \UNIX{}, Windows.
Fred Drake8a9db992000-09-28 20:27:51 +0000329\versionadded{2.0}
330\end{funcdesc}
331
Fred Drake046f4d82001-06-11 15:21:48 +0000332\begin{funcdesc}{popen4}{cmd\optional{, mode\optional{, bufsize}}}
Fred Drake8a9db992000-09-28 20:27:51 +0000333Executes \var{cmd} as a sub-process. Returns the file objects
334\code{(\var{child_stdin}, \var{child_stdout_and_stderr})}.
Fred Drake0b9bc202001-06-11 18:25:34 +0000335Availability: \UNIX{}, Windows.
Fred Drake8a9db992000-09-28 20:27:51 +0000336\versionadded{2.0}
337\end{funcdesc}
338
339This functionality is also available in the \refmodule{popen2} module
340using functions of the same names, but the return values of those
341functions have a different order.
342
343
Fred Drake215fe2f1999-02-02 19:02:35 +0000344\subsection{File Descriptor Operations \label{os-fd-ops}}
345
346These functions operate on I/O streams referred to
347using file descriptors.
348
349
350\begin{funcdesc}{close}{fd}
351Close file descriptor \var{fd}.
352Availability: Macintosh, \UNIX{}, Windows.
353
354Note: this function is intended for low-level I/O and must be applied
355to a file descriptor as returned by \function{open()} or
356\function{pipe()}. To close a ``file object'' returned by the
357built-in function \function{open()} or by \function{popen()} or
358\function{fdopen()}, use its \method{close()} method.
359\end{funcdesc}
360
361\begin{funcdesc}{dup}{fd}
362Return a duplicate of file descriptor \var{fd}.
363Availability: Macintosh, \UNIX{}, Windows.
364\end{funcdesc}
365
366\begin{funcdesc}{dup2}{fd, fd2}
367Duplicate file descriptor \var{fd} to \var{fd2}, closing the latter
368first if necessary.
369Availability: \UNIX{}, Windows.
370\end{funcdesc}
371
Fred Drake88f6ca21999-12-15 19:39:04 +0000372\begin{funcdesc}{fpathconf}{fd, name}
Thomas Woutersf8316632000-07-16 19:01:10 +0000373Return system configuration information relevant to an open file.
Fred Drake88f6ca21999-12-15 19:39:04 +0000374\var{name} specifies the configuration value to retrieve; it may be a
375string which is the name of a defined system value; these names are
376specified in a number of standards (\POSIX.1, Unix95, Unix98, and
377others). Some platforms define additional names as well. The names
378known to the host operating system are given in the
379\code{pathconf_names} dictionary. For configuration variables not
380included in that mapping, passing an integer for \var{name} is also
381accepted.
382Availability: \UNIX{}.
383
384If \var{name} is a string and is not known, \exception{ValueError} is
385raised. If a specific value for \var{name} is not supported by the
386host system, even if it is included in \code{pathconf_names}, an
387\exception{OSError} is raised with \constant{errno.EINVAL} for the
388error number.
389\end{funcdesc}
390
Fred Drake215fe2f1999-02-02 19:02:35 +0000391\begin{funcdesc}{fstat}{fd}
392Return status for file descriptor \var{fd}, like \function{stat()}.
393Availability: \UNIX{}, Windows.
394\end{funcdesc}
395
396\begin{funcdesc}{fstatvfs}{fd}
397Return information about the filesystem containing the file associated
398with file descriptor \var{fd}, like \function{statvfs()}.
399Availability: \UNIX{}.
400\end{funcdesc}
401
402\begin{funcdesc}{ftruncate}{fd, length}
403Truncate the file corresponding to file descriptor \var{fd},
404so that it is at most \var{length} bytes in size.
405Availability: \UNIX{}.
406\end{funcdesc}
407
Skip Montanarod3725212000-07-19 17:30:58 +0000408\begin{funcdesc}{isatty}{fd}
409Return \code{1} if the file descriptor \var{fd} is open and connected to a
410tty(-like) device, else \code{0}.
411Availability: \UNIX{}
412\end{funcdesc}
413
Fred Drake215fe2f1999-02-02 19:02:35 +0000414\begin{funcdesc}{lseek}{fd, pos, how}
415Set the current position of file descriptor \var{fd} to position
416\var{pos}, modified by \var{how}: \code{0} to set the position
417relative to the beginning of the file; \code{1} to set it relative to
418the current position; \code{2} to set it relative to the end of the
419file.
420Availability: Macintosh, \UNIX{}, Windows.
421\end{funcdesc}
422
423\begin{funcdesc}{open}{file, flags\optional{, mode}}
424Open the file \var{file} and set various flags according to
425\var{flags} and possibly its mode according to \var{mode}.
426The default \var{mode} is \code{0777} (octal), and the current umask
427value is first masked out. Return the file descriptor for the newly
428opened file.
429Availability: Macintosh, \UNIX{}, Windows.
430
431For a description of the flag and mode values, see the C run-time
432documentation; flag constants (like \constant{O_RDONLY} and
433\constant{O_WRONLY}) are defined in this module too (see below).
434
435Note: this function is intended for low-level I/O. For normal usage,
436use the built-in function \function{open()}, which returns a ``file
437object'' with \method{read()} and \method{write()} methods (and many
438more).
439\end{funcdesc}
440
Fred Drakec82634c2000-06-28 17:27:48 +0000441\begin{funcdesc}{openpty}{}
442Open a new pseudo-terminal pair. Return a pair of file descriptors
443\code{(\var{master}, \var{slave})} for the pty and the tty,
444respectively. For a (slightly) more portable approach, use the
445\refmodule{pty}\refstmodindex{pty} module.
446Availability: Some flavors of \UNIX{}
447\end{funcdesc}
448
Fred Drake215fe2f1999-02-02 19:02:35 +0000449\begin{funcdesc}{pipe}{}
450Create a pipe. Return a pair of file descriptors \code{(\var{r},
451\var{w})} usable for reading and writing, respectively.
452Availability: \UNIX{}, Windows.
453\end{funcdesc}
454
455\begin{funcdesc}{read}{fd, n}
456Read at most \var{n} bytes from file descriptor \var{fd}.
457Return a string containing the bytes read.
458Availability: Macintosh, \UNIX{}, Windows.
459
460Note: this function is intended for low-level I/O and must be applied
461to a file descriptor as returned by \function{open()} or
462\function{pipe()}. To read a ``file object'' returned by the
463built-in function \function{open()} or by \function{popen()} or
464\function{fdopen()}, or \code{sys.stdin}, use its
465\method{read()} or \method{readline()} methods.
466\end{funcdesc}
467
468\begin{funcdesc}{tcgetpgrp}{fd}
469Return the process group associated with the terminal given by
470\var{fd} (an open file descriptor as returned by \function{open()}).
471Availability: \UNIX{}.
472\end{funcdesc}
473
474\begin{funcdesc}{tcsetpgrp}{fd, pg}
475Set the process group associated with the terminal given by
476\var{fd} (an open file descriptor as returned by \function{open()})
477to \var{pg}.
478Availability: \UNIX{}.
479\end{funcdesc}
480
481\begin{funcdesc}{ttyname}{fd}
482Return a string which specifies the terminal device associated with
483file-descriptor \var{fd}. If \var{fd} is not associated with a terminal
484device, an exception is raised.
485Availability: \UNIX{}.
486\end{funcdesc}
487
488\begin{funcdesc}{write}{fd, str}
489Write the string \var{str} to file descriptor \var{fd}.
490Return the number of bytes actually written.
491Availability: Macintosh, \UNIX{}, Windows.
492
493Note: this function is intended for low-level I/O and must be applied
494to a file descriptor as returned by \function{open()} or
495\function{pipe()}. To write a ``file object'' returned by the
496built-in function \function{open()} or by \function{popen()} or
497\function{fdopen()}, or \code{sys.stdout} or \code{sys.stderr}, use
498its \method{write()} method.
499\end{funcdesc}
500
501
502The following data items are available for use in constructing the
503\var{flags} parameter to the \function{open()} function.
504
505\begin{datadesc}{O_RDONLY}
506\dataline{O_WRONLY}
507\dataline{O_RDWR}
508\dataline{O_NDELAY}
509\dataline{O_NONBLOCK}
510\dataline{O_APPEND}
511\dataline{O_DSYNC}
512\dataline{O_RSYNC}
513\dataline{O_SYNC}
514\dataline{O_NOCTTY}
515\dataline{O_CREAT}
516\dataline{O_EXCL}
517\dataline{O_TRUNC}
518Options for the \var{flag} argument to the \function{open()} function.
519These can be bit-wise OR'd together.
520Availability: Macintosh, \UNIX{}, Windows.
521\end{datadesc}
522
Fred Drake3ac977e2000-08-11 20:19:51 +0000523\begin{datadesc}{O_BINARY}
524Option for the \var{flag} argument to the \function{open()} function.
525This can be bit-wise OR'd together with those listed above.
526Availability: Macintosh, Windows.
527% XXX need to check on the availability of this one.
528\end{datadesc}
529
Fred Drake215fe2f1999-02-02 19:02:35 +0000530
531\subsection{Files and Directories \label{os-file-dir}}
532
533\begin{funcdesc}{access}{path, mode}
Fred Drake38e5d272000-04-03 20:13:55 +0000534Check read/write/execute permissions for this process or existence of
535file \var{path}. \var{mode} should be \constant{F_OK} to test the
536existence of \var{path}, or it can be the inclusive OR of one or more
537of \constant{R_OK}, \constant{W_OK}, and \constant{X_OK} to test
538permissions. Return \code{1} if access is allowed, \code{0} if not.
539See the \UNIX{} man page \manpage{access}{2} for more information.
Fred Drake3ac977e2000-08-11 20:19:51 +0000540Availability: \UNIX{}, Windows.
Fred Drake215fe2f1999-02-02 19:02:35 +0000541\end{funcdesc}
542
Fred Drake38e5d272000-04-03 20:13:55 +0000543\begin{datadesc}{F_OK}
544 Value to pass as the \var{mode} parameter of \function{access()} to
545 test the existence of \var{path}.
546\end{datadesc}
547
548\begin{datadesc}{R_OK}
549 Value to include in the \var{mode} parameter of \function{access()}
550 to test the readability of \var{path}.
551\end{datadesc}
552
553\begin{datadesc}{W_OK}
554 Value to include in the \var{mode} parameter of \function{access()}
555 to test the writability of \var{path}.
556\end{datadesc}
557
558\begin{datadesc}{X_OK}
559 Value to include in the \var{mode} parameter of \function{access()}
560 to determine if \var{path} can be executed.
561\end{datadesc}
562
Fred Drake6db897c1999-07-12 16:49:30 +0000563\begin{funcdesc}{chdir}{path}
564\index{directory!changing}
565Change the current working directory to \var{path}.
566Availability: Macintosh, \UNIX{}, Windows.
567\end{funcdesc}
568
569\begin{funcdesc}{getcwd}{}
570Return a string representing the current working directory.
571Availability: Macintosh, \UNIX{}, Windows.
572\end{funcdesc}
573
Fred Drake215fe2f1999-02-02 19:02:35 +0000574\begin{funcdesc}{chmod}{path, mode}
575Change the mode of \var{path} to the numeric \var{mode}.
576Availability: \UNIX{}, Windows.
577\end{funcdesc}
578
579\begin{funcdesc}{chown}{path, uid, gid}
580Change the owner and group id of \var{path} to the numeric \var{uid}
581and \var{gid}.
582Availability: \UNIX{}.
583\end{funcdesc}
584
585\begin{funcdesc}{link}{src, dst}
586Create a hard link pointing to \var{src} named \var{dst}.
587Availability: \UNIX{}.
588\end{funcdesc}
589
590\begin{funcdesc}{listdir}{path}
591Return a list containing the names of the entries in the directory.
592The list is in arbitrary order. It does not include the special
593entries \code{'.'} and \code{'..'} even if they are present in the
594directory.
595Availability: Macintosh, \UNIX{}, Windows.
596\end{funcdesc}
597
598\begin{funcdesc}{lstat}{path}
599Like \function{stat()}, but do not follow symbolic links.
600Availability: \UNIX{}.
601\end{funcdesc}
602
603\begin{funcdesc}{mkfifo}{path\optional{, mode}}
604Create a FIFO (a named pipe) named \var{path} with numeric mode
605\var{mode}. The default \var{mode} is \code{0666} (octal). The current
606umask value is first masked out from the mode.
607Availability: \UNIX{}.
608
609FIFOs are pipes that can be accessed like regular files. FIFOs exist
610until they are deleted (for example with \function{os.unlink()}).
611Generally, FIFOs are used as rendezvous between ``client'' and
612``server'' type processes: the server opens the FIFO for reading, and
613the client opens it for writing. Note that \function{mkfifo()}
614doesn't open the FIFO --- it just creates the rendezvous point.
615\end{funcdesc}
616
617\begin{funcdesc}{mkdir}{path\optional{, mode}}
618Create a directory named \var{path} with numeric mode \var{mode}.
619The default \var{mode} is \code{0777} (octal). On some systems,
620\var{mode} is ignored. Where it is used, the current umask value is
621first masked out.
622Availability: Macintosh, \UNIX{}, Windows.
623\end{funcdesc}
624
625\begin{funcdesc}{makedirs}{path\optional{, mode}}
626\index{directory!creating}
627Recursive directory creation function. Like \function{mkdir()},
628but makes all intermediate-level directories needed to contain the
629leaf directory. Throws an \exception{error} exception if the leaf
630directory already exists or cannot be created. The default \var{mode}
631is \code{0777} (octal).
632\versionadded{1.5.2}
633\end{funcdesc}
634
Fred Drake88f6ca21999-12-15 19:39:04 +0000635\begin{funcdesc}{pathconf}{path, name}
Thomas Woutersf8316632000-07-16 19:01:10 +0000636Return system configuration information relevant to a named file.
Fred Drake88f6ca21999-12-15 19:39:04 +0000637\var{name} specifies the configuration value to retrieve; it may be a
638string which is the name of a defined system value; these names are
639specified in a number of standards (\POSIX.1, Unix95, Unix98, and
640others). Some platforms define additional names as well. The names
641known to the host operating system are given in the
642\code{pathconf_names} dictionary. For configuration variables not
643included in that mapping, passing an integer for \var{name} is also
644accepted.
645Availability: \UNIX{}.
646
647If \var{name} is a string and is not known, \exception{ValueError} is
648raised. If a specific value for \var{name} is not supported by the
649host system, even if it is included in \code{pathconf_names}, an
650\exception{OSError} is raised with \constant{errno.EINVAL} for the
651error number.
652\end{funcdesc}
653
654\begin{datadesc}{pathconf_names}
655Dictionary mapping names accepted by \function{pathconf()} and
656\function{fpathconf()} to the integer values defined for those names
657by the host operating system. This can be used to determine the set
658of names known to the system.
659Availability: \UNIX.
660\end{datadesc}
661
Fred Drake215fe2f1999-02-02 19:02:35 +0000662\begin{funcdesc}{readlink}{path}
663Return a string representing the path to which the symbolic link
Fred Drakedc9e7e42001-05-29 18:13:06 +0000664points. The result may be either an absolute or relative pathname; if
665it is relative, it may be converted to an absolute pathname using
666\code{os.path.join(os.path.dirname(\var{path}), \var{result})}.
Fred Drake215fe2f1999-02-02 19:02:35 +0000667Availability: \UNIX{}.
668\end{funcdesc}
669
670\begin{funcdesc}{remove}{path}
Fred Drakedc9e7e42001-05-29 18:13:06 +0000671Remove the file \var{path}. If \var{path} is a directory,
672\exception{OSError} is raised; see \function{rmdir()} below to remove
673a directory. This is identical to the \function{unlink()} function
674documented below. On Windows, attempting to remove a file that is in
675use causes an exception to be raised; on \UNIX, the directory entry is
676removed but the storage allocated to the file is not made available
677until the original file is no longer in use.
Fred Drake215fe2f1999-02-02 19:02:35 +0000678Availability: Macintosh, \UNIX{}, Windows.
679\end{funcdesc}
680
681\begin{funcdesc}{removedirs}{path}
682\index{directory!deleting}
683Recursive directory removal function. Works like
684\function{rmdir()} except that, if the leaf directory is
685successfully removed, directories corresponding to rightmost path
686segments will be pruned way until either the whole path is consumed or
687an error is raised (which is ignored, because it generally means that
688a parent directory is not empty). Throws an \exception{error}
689exception if the leaf directory could not be successfully removed.
690\versionadded{1.5.2}
691\end{funcdesc}
692
693\begin{funcdesc}{rename}{src, dst}
Fred Drakedc9e7e42001-05-29 18:13:06 +0000694Rename the file or directory \var{src} to \var{dst}. If \var{dst} is
695a directory, \exception{OSError} will be raised. On \UNIX, if
696\var{dst} exists and is a file, it will be removed silently if the
697user has permission. The operation may fail on some \UNIX{} flavors
Skip Montanarob9d973d2001-06-04 15:31:17 +0000698if \var{src} and \var{dst} are on different filesystems. If
Fred Drakedc9e7e42001-05-29 18:13:06 +0000699successful, the renaming will be an atomic operation (this is a
700\POSIX{} requirement). On Windows, if \var{dst} already exists,
701\exception{OSError} will be raised even if it is a file; there may be
702no way to implement an atomic rename when \var{dst} names an existing
703file.
Fred Drake215fe2f1999-02-02 19:02:35 +0000704Availability: Macintosh, \UNIX{}, Windows.
705\end{funcdesc}
706
707\begin{funcdesc}{renames}{old, new}
708Recursive directory or file renaming function.
709Works like \function{rename()}, except creation of any intermediate
710directories needed to make the new pathname good is attempted first.
711After the rename, directories corresponding to rightmost path segments
712of the old name will be pruned away using \function{removedirs()}.
713
714Note: this function can fail with the new directory structure made if
715you lack permissions needed to remove the leaf directory or file.
716\versionadded{1.5.2}
717\end{funcdesc}
718
719\begin{funcdesc}{rmdir}{path}
720Remove the directory \var{path}.
721Availability: Macintosh, \UNIX{}, Windows.
722\end{funcdesc}
723
724\begin{funcdesc}{stat}{path}
725Perform a \cfunction{stat()} system call on the given path. The
726return value is a tuple of at least 10 integers giving the most
727important (and portable) members of the \emph{stat} structure, in the
728order
729\code{st_mode},
730\code{st_ino},
731\code{st_dev},
732\code{st_nlink},
733\code{st_uid},
734\code{st_gid},
735\code{st_size},
736\code{st_atime},
737\code{st_mtime},
738\code{st_ctime}.
Fred Drake21c9df72000-10-14 05:46:11 +0000739More items may be added at the end by some implementations. Note that
740on the Macintosh, the time values are floating point values, like all
741time values on the Macintosh.
Fred Drake215fe2f1999-02-02 19:02:35 +0000742(On MS Windows, some items are filled with dummy values.)
743Availability: Macintosh, \UNIX{}, Windows.
744
745Note: The standard module \refmodule{stat}\refstmodindex{stat} defines
746functions and constants that are useful for extracting information
747from a \ctype{stat} structure.
748\end{funcdesc}
749
750\begin{funcdesc}{statvfs}{path}
751Perform a \cfunction{statvfs()} system call on the given path. The
Guido van Rossum0c9608c1999-02-03 16:32:37 +0000752return value is a tuple of 10 integers giving the most common
Fred Drake215fe2f1999-02-02 19:02:35 +0000753members of the \ctype{statvfs} structure, in the order
754\code{f_bsize},
755\code{f_frsize},
756\code{f_blocks},
757\code{f_bfree},
758\code{f_bavail},
759\code{f_files},
760\code{f_ffree},
761\code{f_favail},
Fred Drake215fe2f1999-02-02 19:02:35 +0000762\code{f_flag},
763\code{f_namemax}.
764Availability: \UNIX{}.
765
766Note: The standard module \module{statvfs}\refstmodindex{statvfs}
767defines constants that are useful for extracting information
768from a \ctype{statvfs} structure.
769\end{funcdesc}
770
771\begin{funcdesc}{symlink}{src, dst}
772Create a symbolic link pointing to \var{src} named \var{dst}.
773Availability: \UNIX{}.
774\end{funcdesc}
775
Fred Drake18f7a451999-12-09 22:11:43 +0000776\begin{funcdesc}{tempnam}{\optional{dir\optional{, prefix}}}
777Return a unique path name that is reasonable for creating a temporary
778file. This will be an absolute path that names a potential directory
779entry in the directory \var{dir} or a common location for temporary
780files if \var{dir} is omitted or \code{None}. If given and not
781\code{None}, \var{prefix} is used to provide a short prefix to the
782filename. Applications are responsible for properly creating and
783managing files created using paths returned by \function{tempnam()};
784no automatic cleanup is provided.
785\end{funcdesc}
786
787\begin{funcdesc}{tmpnam}{}
788Return a unique path name that is reasonable for creating a temporary
789file. This will be an absolute path that names a potential directory
790entry in a common location for temporary files. Applications are
791responsible for properly creating and managing files created using
792paths returned by \function{tmpnam()}; no automatic cleanup is
793provided.
794\end{funcdesc}
795
796\begin{datadesc}{TMP_MAX}
797The maximum number of unique names that \function{tmpnam()} will
798generate before reusing names.
799\end{datadesc}
800
Fred Drake215fe2f1999-02-02 19:02:35 +0000801\begin{funcdesc}{unlink}{path}
802Remove the file \var{path}. This is the same function as
803\function{remove()}; the \function{unlink()} name is its traditional
804\UNIX{} name.
805Availability: Macintosh, \UNIX{}, Windows.
806\end{funcdesc}
807
Barry Warsaw93a8eac2000-05-01 16:18:22 +0000808\begin{funcdesc}{utime}{path, times}
809Set the access and modified times of the file specified by \var{path}.
810If \var{times} is \code{None}, then the file's access and modified
811times are set to the current time. Otherwise, \var{times} must be a
Fred Drakee06d0252000-05-02 17:29:35 +00008122-tuple of numbers, of the form \code{(\var{atime}, \var{mtime})}
813which is used to set the access and modified times, respectively.
Fred Drake4a152632000-10-19 05:33:46 +0000814\versionchanged[Added support for \code{None} for \var{times}]{2.0}
Fred Drake215fe2f1999-02-02 19:02:35 +0000815Availability: Macintosh, \UNIX{}, Windows.
816\end{funcdesc}
817
818
819\subsection{Process Management \label{os-process}}
820
Fred Drake18f7a451999-12-09 22:11:43 +0000821These functions may be used to create and manage processes.
Fred Drake215fe2f1999-02-02 19:02:35 +0000822
Fred Drake7be31152000-09-23 05:22:07 +0000823The various \function{exec*()} functions take a list of arguments for
824the new program loaded into the process. In each case, the first of
825these arguments is passed to the new program as its own name rather
826than as an argument a user may have typed on a command line. For the
827C programmer, this is the \code{argv[0]} passed to a program's
828\cfunction{main()}. For example, \samp{os.execv('/bin/echo', ['foo',
829'bar'])} will only print \samp{bar} on standard output; \samp{foo}
830will seem to be ignored.
831
Fred Drake215fe2f1999-02-02 19:02:35 +0000832
Fred Drake18f7a451999-12-09 22:11:43 +0000833\begin{funcdesc}{abort}{}
834Generate a \constant{SIGABRT} signal to the current process. On
835\UNIX, the default behavior is to produce a core dump; on Windows, the
836process immediately returns an exit code of \code{3}. Be aware that
837programs which use \function{signal.signal()} to register a handler
838for \constant{SIGABRT} will behave differently.
839Availability: \UNIX, Windows.
840\end{funcdesc}
841
Fred Drake215fe2f1999-02-02 19:02:35 +0000842\begin{funcdesc}{execl}{path, arg0, arg1, ...}
843This is equivalent to
844\samp{execv(\var{path}, (\var{arg0}, \var{arg1}, ...))}.
845Availability: \UNIX{}, Windows.
846\end{funcdesc}
847
848\begin{funcdesc}{execle}{path, arg0, arg1, ..., env}
849This is equivalent to
850\samp{execve(\var{path}, (\var{arg0}, \var{arg1}, ...), \var{env})}.
851Availability: \UNIX{}, Windows.
852\end{funcdesc}
853
854\begin{funcdesc}{execlp}{path, arg0, arg1, ...}
855This is equivalent to
856\samp{execvp(\var{path}, (\var{arg0}, \var{arg1}, ...))}.
857Availability: \UNIX{}, Windows.
858\end{funcdesc}
859
860\begin{funcdesc}{execv}{path, args}
861Execute the executable \var{path} with argument list \var{args},
Fred Drake907e76b2001-07-06 20:30:11 +0000862replacing the current process (the Python interpreter).
Fred Drake215fe2f1999-02-02 19:02:35 +0000863The argument list may be a tuple or list of strings.
864Availability: \UNIX{}, Windows.
865\end{funcdesc}
866
867\begin{funcdesc}{execve}{path, args, env}
868Execute the executable \var{path} with argument list \var{args},
Fred Drake907e76b2001-07-06 20:30:11 +0000869and environment \var{env}, replacing the current process (the Python
870interpreter).
Fred Drake215fe2f1999-02-02 19:02:35 +0000871The argument list may be a tuple or list of strings.
872The environment must be a dictionary mapping strings to strings.
873Availability: \UNIX{}, Windows.
874\end{funcdesc}
875
876\begin{funcdesc}{execvp}{path, args}
877This is like \samp{execv(\var{path}, \var{args})} but duplicates
878the shell's actions in searching for an executable file in a list of
879directories. The directory list is obtained from
880\code{environ['PATH']}.
881Availability: \UNIX{}, Windows.
882\end{funcdesc}
883
884\begin{funcdesc}{execvpe}{path, args, env}
885This is a cross between \function{execve()} and \function{execvp()}.
886The directory list is obtained from \code{\var{env}['PATH']}.
887Availability: \UNIX{}, Windows.
888\end{funcdesc}
889
890\begin{funcdesc}{_exit}{n}
891Exit to the system with status \var{n}, without calling cleanup
892handlers, flushing stdio buffers, etc.
893Availability: \UNIX{}, Windows.
894
895Note: the standard way to exit is \code{sys.exit(\var{n})}.
896\function{_exit()} should normally only be used in the child process
897after a \function{fork()}.
898\end{funcdesc}
899
900\begin{funcdesc}{fork}{}
901Fork a child process. Return \code{0} in the child, the child's
902process id in the parent.
903Availability: \UNIX{}.
904\end{funcdesc}
905
Fred Drakec82634c2000-06-28 17:27:48 +0000906\begin{funcdesc}{forkpty}{}
907Fork a child process, using a new pseudo-terminal as the child's
908controlling terminal. Return a pair of \code{(\var{pid}, \var{fd})},
909where \var{pid} is \code{0} in the child, the new child's process id
910in the parent, and \code{fd} is the file descriptor of the master end
911of the pseudo-terminal. For a more portable approach, use the
912\refmodule{pty} module.
913Availability: Some flavors of \UNIX{}
914\end{funcdesc}
915
Fred Drake215fe2f1999-02-02 19:02:35 +0000916\begin{funcdesc}{kill}{pid, sig}
917\index{process!killing}
918\index{process!signalling}
919Kill the process \var{pid} with signal \var{sig}.
920Availability: \UNIX{}.
921\end{funcdesc}
922
923\begin{funcdesc}{nice}{increment}
924Add \var{increment} to the process's ``niceness''. Return the new
925niceness.
926Availability: \UNIX{}.
927\end{funcdesc}
928
929\begin{funcdesc}{plock}{op}
930Lock program segments into memory. The value of \var{op}
931(defined in \code{<sys/lock.h>}) determines which segments are locked.
Fred Drake39063631999-02-26 14:05:02 +0000932Availability: \UNIX{}.
Fred Drake215fe2f1999-02-02 19:02:35 +0000933\end{funcdesc}
934
Fred Drake046f4d82001-06-11 15:21:48 +0000935\begin{funcdescni}{popen}{\unspecified}
936\funclineni{popen2}{\unspecified}
937\funclineni{popen3}{\unspecified}
938\funclineni{popen4}{\unspecified}
939Run child processes, returning opened pipes for communications. These
940functions are described in section \ref{os-newstreams}.
941\end{funcdescni}
942
Fred Drake215fe2f1999-02-02 19:02:35 +0000943\begin{funcdesc}{spawnv}{mode, path, args}
944Execute the program \var{path} in a new process, passing the arguments
945specified in \var{args} as command-line parameters. \var{args} may be
946a list or a tuple. \var{mode} is a magic operational constant. See
947the Visual \Cpp{} Runtime Library documentation for further
Fred Drake22702081999-07-02 14:01:03 +0000948information; the constants are exposed to the Python programmer as
949listed below.
Fred Drake15861b22000-02-29 05:19:38 +0000950Availability: \UNIX{}, Windows.
Fred Drake0b9bc202001-06-11 18:25:34 +0000951\versionadded{1.6}
Fred Drake215fe2f1999-02-02 19:02:35 +0000952\end{funcdesc}
953
954\begin{funcdesc}{spawnve}{mode, path, args, env}
955Execute the program \var{path} in a new process, passing the arguments
956specified in \var{args} as command-line parameters and the contents of
957the mapping \var{env} as the environment. \var{args} may be a list or
958a tuple. \var{mode} is a magic operational constant. See the Visual
Fred Drake22702081999-07-02 14:01:03 +0000959\Cpp{} Runtime Library documentation for further information; the
960constants are exposed to the Python programmer as listed below.
Fred Drake15861b22000-02-29 05:19:38 +0000961Availability: \UNIX{}, Windows.
Fred Drake0b9bc202001-06-11 18:25:34 +0000962\versionadded{1.6}
Fred Drake215fe2f1999-02-02 19:02:35 +0000963\end{funcdesc}
964
Fred Drake9329e5e1999-02-16 19:40:19 +0000965\begin{datadesc}{P_WAIT}
966\dataline{P_NOWAIT}
967\dataline{P_NOWAITO}
Fred Drake215fe2f1999-02-02 19:02:35 +0000968Possible values for the \var{mode} parameter to \function{spawnv()}
969and \function{spawnve()}.
Fred Drake15861b22000-02-29 05:19:38 +0000970Availability: \UNIX{}, Windows.
Fred Drake0b9bc202001-06-11 18:25:34 +0000971\versionadded{1.6}
Fred Drake15861b22000-02-29 05:19:38 +0000972\end{datadesc}
973
974\begin{datadesc}{P_OVERLAY}
975\dataline{P_DETACH}
976Possible values for the \var{mode} parameter to \function{spawnv()}
977and \function{spawnve()}. These are less portable than those listed
978above.
Fred Drake215fe2f1999-02-02 19:02:35 +0000979Availability: Windows.
Fred Drake0b9bc202001-06-11 18:25:34 +0000980\versionadded{1.6}
Fred Drake215fe2f1999-02-02 19:02:35 +0000981\end{datadesc}
982
Fred Drake4ce4f2e2000-09-29 04:15:19 +0000983\begin{funcdesc}{startfile}{path}
984Start a file with its associated application. This acts like
985double-clicking the file in Windows Explorer, or giving the file name
986as an argument to the DOS \program{start} command: the file is opened
987with whatever application (if any) its extension is associated.
988
989\function{startfile()} returns as soon as the associated application
990is launched. There is no option to wait for the application to close,
991and no way to retrieve the application's exit status. The \var{path}
992parameter is relative to the current directory. If you want to use an
993absolute path, make sure the first character is not a slash
994(\character{/}); the underlying Win32 \cfunction{ShellExecute()}
995function doesn't work it is. Use the \function{os.path.normpath()}
996function to ensure that the path is properly encoded for Win32.
997Availability: Windows.
998\versionadded{2.0}
999\end{funcdesc}
1000
Fred Drake215fe2f1999-02-02 19:02:35 +00001001\begin{funcdesc}{system}{command}
1002Execute the command (a string) in a subshell. This is implemented by
1003calling the Standard C function \cfunction{system()}, and has the
Fred Drakeec6baaf1999-04-21 18:13:31 +00001004same limitations. Changes to \code{posix.environ}, \code{sys.stdin},
Fred Drake215fe2f1999-02-02 19:02:35 +00001005etc.\ are not reflected in the environment of the executed command.
1006The return value is the exit status of the process encoded in the
Fred Drake7a621281999-06-10 15:07:05 +00001007format specified for \function{wait()}, except on Windows 95 and 98,
Fred Drakea88ef001999-06-18 19:11:25 +00001008where it is always \code{0}. Note that \POSIX{} does not specify the
1009meaning of the return value of the C \cfunction{system()} function,
1010so the return value of the Python function is system-dependent.
Fred Drake215fe2f1999-02-02 19:02:35 +00001011Availability: \UNIX{}, Windows.
1012\end{funcdesc}
1013
1014\begin{funcdesc}{times}{}
1015Return a 5-tuple of floating point numbers indicating accumulated (CPU
1016or other)
1017times, in seconds. The items are: user time, system time, children's
1018user time, children's system time, and elapsed real time since a fixed
Fred Drakeec6baaf1999-04-21 18:13:31 +00001019point in the past, in that order. See the \UNIX{} manual page
1020\manpage{times}{2} or the corresponding Windows Platform API
1021documentation.
Fred Drake215fe2f1999-02-02 19:02:35 +00001022Availability: \UNIX{}, Windows.
1023\end{funcdesc}
1024
1025\begin{funcdesc}{wait}{}
1026Wait for completion of a child process, and return a tuple containing
1027its pid and exit status indication: a 16-bit number, whose low byte is
1028the signal number that killed the process, and whose high byte is the
1029exit status (if the signal number is zero); the high bit of the low
1030byte is set if a core file was produced.
1031Availability: \UNIX{}.
1032\end{funcdesc}
1033
1034\begin{funcdesc}{waitpid}{pid, options}
Fred Drake31e5e371999-08-13 13:36:33 +00001035Wait for completion of a child process given by process id \var{pid},
1036and return a tuple containing its process id and exit status
1037indication (encoded as for \function{wait()}). The semantics of the
1038call are affected by the value of the integer \var{options}, which
1039should be \code{0} for normal operation.
Fred Drake215fe2f1999-02-02 19:02:35 +00001040Availability: \UNIX{}.
Fred Drake31e5e371999-08-13 13:36:33 +00001041
1042If \var{pid} is greater than \code{0}, \function{waitpid()} requests
1043status information for that specific process. If \var{pid} is
1044\code{0}, the request is for the status of any child in the process
1045group of the current process. If \var{pid} is \code{-1}, the request
1046pertains to any child of the current process. If \var{pid} is less
1047than \code{-1}, status is requested for any process in the process
1048group \code{-\var{pid}} (the absolute value of \var{pid}).
Fred Drake215fe2f1999-02-02 19:02:35 +00001049\end{funcdesc}
1050
1051\begin{datadesc}{WNOHANG}
1052The option for \function{waitpid()} to avoid hanging if no child
1053process status is available immediately.
1054Availability: \UNIX{}.
1055\end{datadesc}
1056
Fred Drake38e5d272000-04-03 20:13:55 +00001057The following functions take a process status code as returned by
1058\function{system()}, \function{wait()}, or \function{waitpid()} as a
1059parameter. They may be used to determine the disposition of a
1060process.
Fred Drake215fe2f1999-02-02 19:02:35 +00001061
1062\begin{funcdesc}{WIFSTOPPED}{status}
1063Return true if the process has been stopped.
1064Availability: \UNIX{}.
1065\end{funcdesc}
1066
1067\begin{funcdesc}{WIFSIGNALED}{status}
1068Return true if the process exited due to a signal.
1069Availability: \UNIX{}.
1070\end{funcdesc}
1071
1072\begin{funcdesc}{WIFEXITED}{status}
1073Return true if the process exited using the \manpage{exit}{2} system
1074call.
1075Availability: \UNIX{}.
1076\end{funcdesc}
1077
1078\begin{funcdesc}{WEXITSTATUS}{status}
1079If \code{WIFEXITED(\var{status})} is true, return the integer
1080parameter to the \manpage{exit}{2} system call. Otherwise, the return
1081value is meaningless.
1082Availability: \UNIX{}.
1083\end{funcdesc}
1084
1085\begin{funcdesc}{WSTOPSIG}{status}
Fred Drake35c3ffd1999-03-04 14:08:10 +00001086Return the signal which caused the process to stop.
1087Availability: \UNIX{}.
1088\end{funcdesc}
1089
1090\begin{funcdesc}{WTERMSIG}{status}
Fred Drake215fe2f1999-02-02 19:02:35 +00001091Return the signal which caused the process to exit.
1092Availability: \UNIX{}.
1093\end{funcdesc}
1094
1095
Thomas Woutersf8316632000-07-16 19:01:10 +00001096\subsection{Miscellaneous System Information \label{os-path}}
Fred Drake88f6ca21999-12-15 19:39:04 +00001097
1098
1099\begin{funcdesc}{confstr}{name}
1100Return string-valued system configuration values.
1101\var{name} specifies the configuration value to retrieve; it may be a
1102string which is the name of a defined system value; these names are
1103specified in a number of standards (\POSIX, Unix95, Unix98, and
1104others). Some platforms define additional names as well. The names
1105known to the host operating system are given in the
1106\code{confstr_names} dictionary. For configuration variables not
1107included in that mapping, passing an integer for \var{name} is also
1108accepted.
1109Availability: \UNIX{}.
1110
1111If the configuration value specified by \var{name} isn't defined, the
1112empty string is returned.
1113
1114If \var{name} is a string and is not known, \exception{ValueError} is
1115raised. If a specific value for \var{name} is not supported by the
1116host system, even if it is included in \code{confstr_names}, an
1117\exception{OSError} is raised with \constant{errno.EINVAL} for the
1118error number.
1119\end{funcdesc}
1120
1121\begin{datadesc}{confstr_names}
1122Dictionary mapping names accepted by \function{confstr()} to the
1123integer values defined for those names by the host operating system.
1124This can be used to determine the set of names known to the system.
1125Availability: \UNIX.
1126\end{datadesc}
1127
1128\begin{funcdesc}{sysconf}{name}
1129Return integer-valued system configuration values.
1130If the configuration value specified by \var{name} isn't defined,
1131\code{-1} is returned. The comments regarding the \var{name}
1132parameter for \function{confstr()} apply here as well; the dictionary
1133that provides information on the known names is given by
1134\code{sysconf_names}.
1135Availability: \UNIX{}.
1136\end{funcdesc}
1137
1138\begin{datadesc}{sysconf_names}
1139Dictionary mapping names accepted by \function{sysconf()} to the
1140integer values defined for those names by the host operating system.
1141This can be used to determine the set of names known to the system.
1142Availability: \UNIX.
1143\end{datadesc}
1144
Fred Drake215fe2f1999-02-02 19:02:35 +00001145
1146The follow data values are used to support path manipulation
1147operations. These are defined for all platforms.
1148
1149Higher-level operations on pathnames are defined in the
1150\refmodule{os.path} module.
1151
1152
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00001153\begin{datadesc}{curdir}
Fred Drake907e76b2001-07-06 20:30:11 +00001154The constant string used by the OS to refer to the current directory.
1155For example: \code{'.'} for \POSIX{} or \code{':'} for the Macintosh.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00001156\end{datadesc}
1157
1158\begin{datadesc}{pardir}
Fred Drake907e76b2001-07-06 20:30:11 +00001159The constant string used by the OS to refer to the parent directory.
1160For example: \code{'..'} for \POSIX{} or \code{'::'} for the Macintosh.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00001161\end{datadesc}
1162
1163\begin{datadesc}{sep}
Guido van Rossumb2afc811997-08-29 22:37:44 +00001164The character used by the OS to separate pathname components,
Fred Drake907e76b2001-07-06 20:30:11 +00001165for example, \character{/} for \POSIX{} or \character{:} for the
1166Macintosh. Note that knowing this is not sufficient to be able to
1167parse or concatenate pathnames --- use \function{os.path.split()} and
Fred Drake1a3c2a01998-08-06 15:18:23 +00001168\function{os.path.join()} --- but it is occasionally useful.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00001169\end{datadesc}
1170
Guido van Rossumb2afc811997-08-29 22:37:44 +00001171\begin{datadesc}{altsep}
1172An alternative character used by the OS to separate pathname components,
1173or \code{None} if only one separator character exists. This is set to
Fred Drake215fe2f1999-02-02 19:02:35 +00001174\character{/} on DOS and Windows systems where \code{sep} is a backslash.
Guido van Rossumb2afc811997-08-29 22:37:44 +00001175\end{datadesc}
1176
Guido van Rossum470be141995-03-17 16:07:09 +00001177\begin{datadesc}{pathsep}
1178The character conventionally used by the OS to separate search patch
Fred Drake907e76b2001-07-06 20:30:11 +00001179components (as in \envvar{PATH}), such as \character{:} for \POSIX{} or
Fred Drake215fe2f1999-02-02 19:02:35 +00001180\character{;} for DOS and Windows.
Guido van Rossum9c59ce91998-06-30 15:54:27 +00001181\end{datadesc}
1182
Guido van Rossum470be141995-03-17 16:07:09 +00001183\begin{datadesc}{defpath}
Fred Drake1a3c2a01998-08-06 15:18:23 +00001184The default search path used by \function{exec*p*()} if the environment
Guido van Rossum470be141995-03-17 16:07:09 +00001185doesn't have a \code{'PATH'} key.
1186\end{datadesc}
1187
Fred Drake215fe2f1999-02-02 19:02:35 +00001188\begin{datadesc}{linesep}
1189The string used to separate (or, rather, terminate) lines on the
Fred Drake907e76b2001-07-06 20:30:11 +00001190current platform. This may be a single character, such as \code{'\e
1191n'} for \POSIX{} or \code{'\e r'} for MacOS, or multiple characters,
1192for example, \code{'\e r\e n'} for MS-DOS and MS Windows.
Fred Drake215fe2f1999-02-02 19:02:35 +00001193\end{datadesc}