blob: f211f99e6dfaad7ba90533834583d2dc5c8e03a6 [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,
16it uses the same interface; e.g., 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}
45This exception is raised when a function returns a
46system-related error (e.g., not for illegal argument types). This is
47also known as the built-in exception \exception{OSError}. The
48accompanying 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
58involve a file system path (e.g. \function{chdir()} or
59\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 Drake215fe2f1999-02-02 19:02:35 +000075operations, e.g., \module{posixpath} or \module{macpath}. Thus, given
76the proper imports, \code{os.path.split(\var{file})} is equivalent to but
77more portable than \code{posixpath.split(\var{file})}. Note that this
78is also a valid module: it may be imported directly as
79\refmodule{os.path}.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000080\end{datadesc}
81
Fred Drake215fe2f1999-02-02 19:02:35 +000082
83
84\subsection{Process Parameters \label{os-procinfo}}
85
86These functions and data items provide information and operate on the
87current process and user.
88
Fred Drake215fe2f1999-02-02 19:02:35 +000089\begin{datadesc}{environ}
Fred Drake0e1de8b1999-04-29 12:57:32 +000090A mapping object representing the string environment. For example,
91\code{environ['HOME']} is the pathname of your home directory (on some
92platforms), and is equivalent to \code{getenv("HOME")} in C.
Fred Drake215fe2f1999-02-02 19:02:35 +000093
94If the platform supports the \function{putenv()} function, this
95mapping may be used to modify the environment as well as query the
96environment. \function{putenv()} will be called automatically when
97the mapping is modified.
98
99If \function{putenv()} is not provided, this mapping may be passed to
100the appropriate process-creation functions to cause child processes to
101use a modified environment.
102\end{datadesc}
103
Fred Drake6db897c1999-07-12 16:49:30 +0000104\begin{funcdescni}{chdir}{path}
105\funclineni{getcwd}{}
106These functions are described in ``Files and Directories'' (section
107\ref{os-file-dir}).
108\end{funcdescni}
Fred Drake215fe2f1999-02-02 19:02:35 +0000109
Fred Drake18f7a451999-12-09 22:11:43 +0000110\begin{funcdesc}{ctermid}{}
111Return the filename corresponding to the controlling terminal of the
112process.
113Availability: \UNIX{}.
114\end{funcdesc}
115
Fred Drake215fe2f1999-02-02 19:02:35 +0000116\begin{funcdesc}{getegid}{}
117Return the current process' effective group id.
118Availability: \UNIX{}.
119\end{funcdesc}
120
121\begin{funcdesc}{geteuid}{}
Fred Drake6b330ba81999-05-25 13:42:26 +0000122\index{user!effective id}
Fred Drake215fe2f1999-02-02 19:02:35 +0000123Return the current process' effective user id.
124Availability: \UNIX{}.
125\end{funcdesc}
126
127\begin{funcdesc}{getgid}{}
Fred Drake6b330ba81999-05-25 13:42:26 +0000128\index{process!group}
Fred Drake215fe2f1999-02-02 19:02:35 +0000129Return the current process' group id.
130Availability: \UNIX{}.
131\end{funcdesc}
132
Fred Drake88f6ca21999-12-15 19:39:04 +0000133\begin{funcdesc}{getgroups}{}
134Return list of supplemental group ids associated with the current
135process.
136Availability: \UNIX{}.
137\end{funcdesc}
138
139\begin{funcdesc}{getlogin}{}
140Return the actual login name for the current process, even if there
141are multiple login names which map to the same user id.
142Availability: \UNIX{}.
143\end{funcdesc}
144
Fred Drake215fe2f1999-02-02 19:02:35 +0000145\begin{funcdesc}{getpgrp}{}
146\index{process!group}
147Return the current process group id.
148Availability: \UNIX{}.
149\end{funcdesc}
150
151\begin{funcdesc}{getpid}{}
152\index{process!id}
153Return the current process id.
154Availability: \UNIX{}, Windows.
155\end{funcdesc}
156
157\begin{funcdesc}{getppid}{}
158\index{process!id of parent}
159Return the parent's process id.
160Availability: \UNIX{}.
161\end{funcdesc}
162
163\begin{funcdesc}{getuid}{}
Fred Drake6b330ba81999-05-25 13:42:26 +0000164\index{user!id}
Fred Drake215fe2f1999-02-02 19:02:35 +0000165Return the current process' user id.
166Availability: \UNIX{}.
167\end{funcdesc}
168
Fred Drake81e142b2001-05-31 20:27:46 +0000169\begin{funcdesc}{getenv}{varname\optional{, value}}
170Return the value of the environment variable \var{varname} if it
171exists, or \var{value} if it doesn't. \var{value} defaults to
172\code{None}.
173Availability: most flavors of \UNIX{}, Windows.
174\end{funcdesc}
175
Fred Drake215fe2f1999-02-02 19:02:35 +0000176\begin{funcdesc}{putenv}{varname, value}
177\index{environment variables!setting}
178Set the environment variable named \var{varname} to the string
179\var{value}. Such changes to the environment affect subprocesses
180started with \function{os.system()}, \function{popen()} or
181\function{fork()} and \function{execv()}.
182Availability: most flavors of \UNIX{}, Windows.
183
184When \function{putenv()} is
185supported, assignments to items in \code{os.environ} are automatically
186translated into corresponding calls to \function{putenv()}; however,
187calls to \function{putenv()} don't update \code{os.environ}, so it is
188actually preferable to assign to items of \code{os.environ}.
189\end{funcdesc}
190
Andrew M. Kuchling8d2f2b22000-07-13 01:26:58 +0000191\begin{funcdesc}{setegid}{egid}
192Set the current process's effective group id.
193Availability: \UNIX{}.
194\end{funcdesc}
195
196\begin{funcdesc}{seteuid}{euid}
197Set the current process's effective user id.
198Availability: \UNIX{}.
199\end{funcdesc}
200
Fred Drake215fe2f1999-02-02 19:02:35 +0000201\begin{funcdesc}{setgid}{gid}
202Set the current process' group id.
203Availability: \UNIX{}.
204\end{funcdesc}
205
206\begin{funcdesc}{setpgrp}{}
207Calls the system call \cfunction{setpgrp()} or \cfunction{setpgrp(0,
2080)} depending on which version is implemented (if any). See the
209\UNIX{} manual for the semantics.
210Availability: \UNIX{}.
211\end{funcdesc}
212
213\begin{funcdesc}{setpgid}{pid, pgrp}
214Calls the system call \cfunction{setpgid()}. See the \UNIX{} manual
215for the semantics.
216Availability: \UNIX{}.
217\end{funcdesc}
218
Andrew M. Kuchling8d2f2b22000-07-13 01:26:58 +0000219\begin{funcdesc}{setreuid}{ruid, euid}
220Set the current process's real and effective user ids.
221Availability: \UNIX{}.
222\end{funcdesc}
223
224\begin{funcdesc}{setregid}{rgid, egid}
225Set the current process's real and effective group ids.
226Availability: \UNIX{}.
227\end{funcdesc}
228
Fred Drake215fe2f1999-02-02 19:02:35 +0000229\begin{funcdesc}{setsid}{}
230Calls the system call \cfunction{setsid()}. See the \UNIX{} manual
231for the semantics.
232Availability: \UNIX{}.
233\end{funcdesc}
234
235\begin{funcdesc}{setuid}{uid}
Fred Drake6b330ba81999-05-25 13:42:26 +0000236\index{user!id, setting}
Fred Drake215fe2f1999-02-02 19:02:35 +0000237Set the current process' user id.
238Availability: \UNIX{}.
239\end{funcdesc}
240
241% placed in this section since it relates to errno.... a little weak ;-(
242\begin{funcdesc}{strerror}{code}
243Return the error message corresponding to the error code in
244\var{code}.
245Availability: \UNIX{}, Windows.
246\end{funcdesc}
247
248\begin{funcdesc}{umask}{mask}
249Set the current numeric umask and returns the previous umask.
250Availability: \UNIX{}, Windows.
251\end{funcdesc}
252
253\begin{funcdesc}{uname}{}
254Return a 5-tuple containing information identifying the current
255operating system. The tuple contains 5 strings:
256\code{(\var{sysname}, \var{nodename}, \var{release}, \var{version},
257\var{machine})}. Some systems truncate the nodename to 8
258characters or to the leading component; a better way to get the
259hostname is \function{socket.gethostname()}
260\withsubitem{(in module socket)}{\ttindex{gethostname()}}
261or even
262\withsubitem{(in module socket)}{\ttindex{gethostbyaddr()}}
263\code{socket.gethostbyaddr(socket.gethostname())}.
264Availability: recent flavors of \UNIX{}.
265\end{funcdesc}
266
267
268
269\subsection{File Object Creation \label{os-newstreams}}
270
271These functions create new file objects.
272
273
274\begin{funcdesc}{fdopen}{fd\optional{, mode\optional{, bufsize}}}
275Return an open file object connected to the file descriptor \var{fd}.
Fred Drake8c9fc001999-08-05 13:41:31 +0000276\index{I/O control!buffering}
Fred Drake215fe2f1999-02-02 19:02:35 +0000277The \var{mode} and \var{bufsize} arguments have the same meaning as
278the corresponding arguments to the built-in \function{open()}
279function.
280Availability: Macintosh, \UNIX{}, Windows.
281\end{funcdesc}
282
283\begin{funcdesc}{popen}{command\optional{, mode\optional{, bufsize}}}
284Open a pipe to or from \var{command}. The return value is an open
285file object connected to the pipe, which can be read or written
286depending on whether \var{mode} is \code{'r'} (default) or \code{'w'}.
287The \var{bufsize} argument has the same meaning as the corresponding
288argument to the built-in \function{open()} function. The exit status of
289the command (encoded in the format specified for \function{wait()}) is
290available as the return value of the \method{close()} method of the file
291object, except that when the exit status is zero (termination without
Fred Drake1319e3e2000-10-03 17:14:27 +0000292errors), \code{None} is returned.
Fred Drake215fe2f1999-02-02 19:02:35 +0000293Availability: \UNIX{}, Windows.
Fred Drakec71c23e2000-10-04 13:57:27 +0000294
295\versionchanged[This function worked unreliably under Windows in
296 earlier versions of Python. This was due to the use of the
297 \cfunction{_popen()} function from the libraries provided with
298 Windows. Newer versions of Python do not use the broken
299 implementation from the Windows libraries]{2.0}
Fred Drake215fe2f1999-02-02 19:02:35 +0000300\end{funcdesc}
301
Fred Drake18f7a451999-12-09 22:11:43 +0000302\begin{funcdesc}{tmpfile}{}
303Return a new file object opened in update mode (\samp{w+}). The file
304has no directory entries associated with it and will be automatically
305deleted once there are no file descriptors for the file.
306Availability: \UNIX{}.
307\end{funcdesc}
Fred Drake215fe2f1999-02-02 19:02:35 +0000308
309
Fred Drake8a9db992000-09-28 20:27:51 +0000310For each of these \function{popen()} variants, if \var{bufsize} is
311specified, it specifies the buffer size for the I/O pipes.
312\var{mode}, if provided, should be the string \code{'b'} or
313\code{'t'}; on Windows this is needed to determine whether the file
314objects should be opened in binary or text mode. The default value
315for \var{mode} is \code{'t'}.
316
Fred Drake046f4d82001-06-11 15:21:48 +0000317\begin{funcdesc}{popen2}{cmd\optional{, mode\optional{, bufsize}}}
Fred Drake8a9db992000-09-28 20:27:51 +0000318Executes \var{cmd} as a sub-process. Returns the file objects
319\code{(\var{child_stdin}, \var{child_stdout})}.
Fred Drake0b9bc202001-06-11 18:25:34 +0000320Availability: \UNIX{}, Windows.
Fred Drake8a9db992000-09-28 20:27:51 +0000321\versionadded{2.0}
322\end{funcdesc}
323
Fred Drake046f4d82001-06-11 15:21:48 +0000324\begin{funcdesc}{popen3}{cmd\optional{, mode\optional{, bufsize}}}
Fred Drake8a9db992000-09-28 20:27:51 +0000325Executes \var{cmd} as a sub-process. Returns the file objects
326\code{(\var{child_stdin}, \var{child_stdout}, \var{child_stderr})}.
Fred Drake0b9bc202001-06-11 18:25:34 +0000327Availability: \UNIX{}, Windows.
Fred Drake8a9db992000-09-28 20:27:51 +0000328\versionadded{2.0}
329\end{funcdesc}
330
Fred Drake046f4d82001-06-11 15:21:48 +0000331\begin{funcdesc}{popen4}{cmd\optional{, mode\optional{, bufsize}}}
Fred Drake8a9db992000-09-28 20:27:51 +0000332Executes \var{cmd} as a sub-process. Returns the file objects
333\code{(\var{child_stdin}, \var{child_stdout_and_stderr})}.
Fred Drake0b9bc202001-06-11 18:25:34 +0000334Availability: \UNIX{}, Windows.
Fred Drake8a9db992000-09-28 20:27:51 +0000335\versionadded{2.0}
336\end{funcdesc}
337
338This functionality is also available in the \refmodule{popen2} module
339using functions of the same names, but the return values of those
340functions have a different order.
341
342
Fred Drake215fe2f1999-02-02 19:02:35 +0000343\subsection{File Descriptor Operations \label{os-fd-ops}}
344
345These functions operate on I/O streams referred to
346using file descriptors.
347
348
349\begin{funcdesc}{close}{fd}
350Close file descriptor \var{fd}.
351Availability: Macintosh, \UNIX{}, Windows.
352
353Note: this function is intended for low-level I/O and must be applied
354to a file descriptor as returned by \function{open()} or
355\function{pipe()}. To close a ``file object'' returned by the
356built-in function \function{open()} or by \function{popen()} or
357\function{fdopen()}, use its \method{close()} method.
358\end{funcdesc}
359
360\begin{funcdesc}{dup}{fd}
361Return a duplicate of file descriptor \var{fd}.
362Availability: Macintosh, \UNIX{}, Windows.
363\end{funcdesc}
364
365\begin{funcdesc}{dup2}{fd, fd2}
366Duplicate file descriptor \var{fd} to \var{fd2}, closing the latter
367first if necessary.
368Availability: \UNIX{}, Windows.
369\end{funcdesc}
370
Fred Drake88f6ca21999-12-15 19:39:04 +0000371\begin{funcdesc}{fpathconf}{fd, name}
Thomas Woutersf8316632000-07-16 19:01:10 +0000372Return system configuration information relevant to an open file.
Fred Drake88f6ca21999-12-15 19:39:04 +0000373\var{name} specifies the configuration value to retrieve; it may be a
374string which is the name of a defined system value; these names are
375specified in a number of standards (\POSIX.1, Unix95, Unix98, and
376others). Some platforms define additional names as well. The names
377known to the host operating system are given in the
378\code{pathconf_names} dictionary. For configuration variables not
379included in that mapping, passing an integer for \var{name} is also
380accepted.
381Availability: \UNIX{}.
382
383If \var{name} is a string and is not known, \exception{ValueError} is
384raised. If a specific value for \var{name} is not supported by the
385host system, even if it is included in \code{pathconf_names}, an
386\exception{OSError} is raised with \constant{errno.EINVAL} for the
387error number.
388\end{funcdesc}
389
Fred Drake215fe2f1999-02-02 19:02:35 +0000390\begin{funcdesc}{fstat}{fd}
391Return status for file descriptor \var{fd}, like \function{stat()}.
392Availability: \UNIX{}, Windows.
393\end{funcdesc}
394
395\begin{funcdesc}{fstatvfs}{fd}
396Return information about the filesystem containing the file associated
397with file descriptor \var{fd}, like \function{statvfs()}.
398Availability: \UNIX{}.
399\end{funcdesc}
400
401\begin{funcdesc}{ftruncate}{fd, length}
402Truncate the file corresponding to file descriptor \var{fd},
403so that it is at most \var{length} bytes in size.
404Availability: \UNIX{}.
405\end{funcdesc}
406
Skip Montanarod3725212000-07-19 17:30:58 +0000407\begin{funcdesc}{isatty}{fd}
408Return \code{1} if the file descriptor \var{fd} is open and connected to a
409tty(-like) device, else \code{0}.
410Availability: \UNIX{}
411\end{funcdesc}
412
Fred Drake215fe2f1999-02-02 19:02:35 +0000413\begin{funcdesc}{lseek}{fd, pos, how}
414Set the current position of file descriptor \var{fd} to position
415\var{pos}, modified by \var{how}: \code{0} to set the position
416relative to the beginning of the file; \code{1} to set it relative to
417the current position; \code{2} to set it relative to the end of the
418file.
419Availability: Macintosh, \UNIX{}, Windows.
420\end{funcdesc}
421
422\begin{funcdesc}{open}{file, flags\optional{, mode}}
423Open the file \var{file} and set various flags according to
424\var{flags} and possibly its mode according to \var{mode}.
425The default \var{mode} is \code{0777} (octal), and the current umask
426value is first masked out. Return the file descriptor for the newly
427opened file.
428Availability: Macintosh, \UNIX{}, Windows.
429
430For a description of the flag and mode values, see the C run-time
431documentation; flag constants (like \constant{O_RDONLY} and
432\constant{O_WRONLY}) are defined in this module too (see below).
433
434Note: this function is intended for low-level I/O. For normal usage,
435use the built-in function \function{open()}, which returns a ``file
436object'' with \method{read()} and \method{write()} methods (and many
437more).
438\end{funcdesc}
439
Fred Drakec82634c2000-06-28 17:27:48 +0000440\begin{funcdesc}{openpty}{}
441Open a new pseudo-terminal pair. Return a pair of file descriptors
442\code{(\var{master}, \var{slave})} for the pty and the tty,
443respectively. For a (slightly) more portable approach, use the
444\refmodule{pty}\refstmodindex{pty} module.
445Availability: Some flavors of \UNIX{}
446\end{funcdesc}
447
Fred Drake215fe2f1999-02-02 19:02:35 +0000448\begin{funcdesc}{pipe}{}
449Create a pipe. Return a pair of file descriptors \code{(\var{r},
450\var{w})} usable for reading and writing, respectively.
451Availability: \UNIX{}, Windows.
452\end{funcdesc}
453
454\begin{funcdesc}{read}{fd, n}
455Read at most \var{n} bytes from file descriptor \var{fd}.
456Return a string containing the bytes read.
457Availability: Macintosh, \UNIX{}, Windows.
458
459Note: this function is intended for low-level I/O and must be applied
460to a file descriptor as returned by \function{open()} or
461\function{pipe()}. To read a ``file object'' returned by the
462built-in function \function{open()} or by \function{popen()} or
463\function{fdopen()}, or \code{sys.stdin}, use its
464\method{read()} or \method{readline()} methods.
465\end{funcdesc}
466
467\begin{funcdesc}{tcgetpgrp}{fd}
468Return the process group associated with the terminal given by
469\var{fd} (an open file descriptor as returned by \function{open()}).
470Availability: \UNIX{}.
471\end{funcdesc}
472
473\begin{funcdesc}{tcsetpgrp}{fd, pg}
474Set the process group associated with the terminal given by
475\var{fd} (an open file descriptor as returned by \function{open()})
476to \var{pg}.
477Availability: \UNIX{}.
478\end{funcdesc}
479
480\begin{funcdesc}{ttyname}{fd}
481Return a string which specifies the terminal device associated with
482file-descriptor \var{fd}. If \var{fd} is not associated with a terminal
483device, an exception is raised.
484Availability: \UNIX{}.
485\end{funcdesc}
486
487\begin{funcdesc}{write}{fd, str}
488Write the string \var{str} to file descriptor \var{fd}.
489Return the number of bytes actually written.
490Availability: Macintosh, \UNIX{}, Windows.
491
492Note: this function is intended for low-level I/O and must be applied
493to a file descriptor as returned by \function{open()} or
494\function{pipe()}. To write a ``file object'' returned by the
495built-in function \function{open()} or by \function{popen()} or
496\function{fdopen()}, or \code{sys.stdout} or \code{sys.stderr}, use
497its \method{write()} method.
498\end{funcdesc}
499
500
501The following data items are available for use in constructing the
502\var{flags} parameter to the \function{open()} function.
503
504\begin{datadesc}{O_RDONLY}
505\dataline{O_WRONLY}
506\dataline{O_RDWR}
507\dataline{O_NDELAY}
508\dataline{O_NONBLOCK}
509\dataline{O_APPEND}
510\dataline{O_DSYNC}
511\dataline{O_RSYNC}
512\dataline{O_SYNC}
513\dataline{O_NOCTTY}
514\dataline{O_CREAT}
515\dataline{O_EXCL}
516\dataline{O_TRUNC}
517Options for the \var{flag} argument to the \function{open()} function.
518These can be bit-wise OR'd together.
519Availability: Macintosh, \UNIX{}, Windows.
520\end{datadesc}
521
Fred Drake3ac977e2000-08-11 20:19:51 +0000522\begin{datadesc}{O_BINARY}
523Option for the \var{flag} argument to the \function{open()} function.
524This can be bit-wise OR'd together with those listed above.
525Availability: Macintosh, Windows.
526% XXX need to check on the availability of this one.
527\end{datadesc}
528
Fred Drake215fe2f1999-02-02 19:02:35 +0000529
530\subsection{Files and Directories \label{os-file-dir}}
531
532\begin{funcdesc}{access}{path, mode}
Fred Drake38e5d272000-04-03 20:13:55 +0000533Check read/write/execute permissions for this process or existence of
534file \var{path}. \var{mode} should be \constant{F_OK} to test the
535existence of \var{path}, or it can be the inclusive OR of one or more
536of \constant{R_OK}, \constant{W_OK}, and \constant{X_OK} to test
537permissions. Return \code{1} if access is allowed, \code{0} if not.
538See the \UNIX{} man page \manpage{access}{2} for more information.
Fred Drake3ac977e2000-08-11 20:19:51 +0000539Availability: \UNIX{}, Windows.
Fred Drake215fe2f1999-02-02 19:02:35 +0000540\end{funcdesc}
541
Fred Drake38e5d272000-04-03 20:13:55 +0000542\begin{datadesc}{F_OK}
543 Value to pass as the \var{mode} parameter of \function{access()} to
544 test the existence of \var{path}.
545\end{datadesc}
546
547\begin{datadesc}{R_OK}
548 Value to include in the \var{mode} parameter of \function{access()}
549 to test the readability of \var{path}.
550\end{datadesc}
551
552\begin{datadesc}{W_OK}
553 Value to include in the \var{mode} parameter of \function{access()}
554 to test the writability of \var{path}.
555\end{datadesc}
556
557\begin{datadesc}{X_OK}
558 Value to include in the \var{mode} parameter of \function{access()}
559 to determine if \var{path} can be executed.
560\end{datadesc}
561
Fred Drake6db897c1999-07-12 16:49:30 +0000562\begin{funcdesc}{chdir}{path}
563\index{directory!changing}
564Change the current working directory to \var{path}.
565Availability: Macintosh, \UNIX{}, Windows.
566\end{funcdesc}
567
568\begin{funcdesc}{getcwd}{}
569Return a string representing the current working directory.
570Availability: Macintosh, \UNIX{}, Windows.
571\end{funcdesc}
572
Fred Drake215fe2f1999-02-02 19:02:35 +0000573\begin{funcdesc}{chmod}{path, mode}
574Change the mode of \var{path} to the numeric \var{mode}.
575Availability: \UNIX{}, Windows.
576\end{funcdesc}
577
578\begin{funcdesc}{chown}{path, uid, gid}
579Change the owner and group id of \var{path} to the numeric \var{uid}
580and \var{gid}.
581Availability: \UNIX{}.
582\end{funcdesc}
583
584\begin{funcdesc}{link}{src, dst}
585Create a hard link pointing to \var{src} named \var{dst}.
586Availability: \UNIX{}.
587\end{funcdesc}
588
589\begin{funcdesc}{listdir}{path}
590Return a list containing the names of the entries in the directory.
591The list is in arbitrary order. It does not include the special
592entries \code{'.'} and \code{'..'} even if they are present in the
593directory.
594Availability: Macintosh, \UNIX{}, Windows.
595\end{funcdesc}
596
597\begin{funcdesc}{lstat}{path}
598Like \function{stat()}, but do not follow symbolic links.
599Availability: \UNIX{}.
600\end{funcdesc}
601
602\begin{funcdesc}{mkfifo}{path\optional{, mode}}
603Create a FIFO (a named pipe) named \var{path} with numeric mode
604\var{mode}. The default \var{mode} is \code{0666} (octal). The current
605umask value is first masked out from the mode.
606Availability: \UNIX{}.
607
608FIFOs are pipes that can be accessed like regular files. FIFOs exist
609until they are deleted (for example with \function{os.unlink()}).
610Generally, FIFOs are used as rendezvous between ``client'' and
611``server'' type processes: the server opens the FIFO for reading, and
612the client opens it for writing. Note that \function{mkfifo()}
613doesn't open the FIFO --- it just creates the rendezvous point.
614\end{funcdesc}
615
616\begin{funcdesc}{mkdir}{path\optional{, mode}}
617Create a directory named \var{path} with numeric mode \var{mode}.
618The default \var{mode} is \code{0777} (octal). On some systems,
619\var{mode} is ignored. Where it is used, the current umask value is
620first masked out.
621Availability: Macintosh, \UNIX{}, Windows.
622\end{funcdesc}
623
624\begin{funcdesc}{makedirs}{path\optional{, mode}}
625\index{directory!creating}
626Recursive directory creation function. Like \function{mkdir()},
627but makes all intermediate-level directories needed to contain the
628leaf directory. Throws an \exception{error} exception if the leaf
629directory already exists or cannot be created. The default \var{mode}
630is \code{0777} (octal).
631\versionadded{1.5.2}
632\end{funcdesc}
633
Fred Drake88f6ca21999-12-15 19:39:04 +0000634\begin{funcdesc}{pathconf}{path, name}
Thomas Woutersf8316632000-07-16 19:01:10 +0000635Return system configuration information relevant to a named file.
Fred Drake88f6ca21999-12-15 19:39:04 +0000636\var{name} specifies the configuration value to retrieve; it may be a
637string which is the name of a defined system value; these names are
638specified in a number of standards (\POSIX.1, Unix95, Unix98, and
639others). Some platforms define additional names as well. The names
640known to the host operating system are given in the
641\code{pathconf_names} dictionary. For configuration variables not
642included in that mapping, passing an integer for \var{name} is also
643accepted.
644Availability: \UNIX{}.
645
646If \var{name} is a string and is not known, \exception{ValueError} is
647raised. If a specific value for \var{name} is not supported by the
648host system, even if it is included in \code{pathconf_names}, an
649\exception{OSError} is raised with \constant{errno.EINVAL} for the
650error number.
651\end{funcdesc}
652
653\begin{datadesc}{pathconf_names}
654Dictionary mapping names accepted by \function{pathconf()} and
655\function{fpathconf()} to the integer values defined for those names
656by the host operating system. This can be used to determine the set
657of names known to the system.
658Availability: \UNIX.
659\end{datadesc}
660
Fred Drake215fe2f1999-02-02 19:02:35 +0000661\begin{funcdesc}{readlink}{path}
662Return a string representing the path to which the symbolic link
Fred Drakedc9e7e42001-05-29 18:13:06 +0000663points. The result may be either an absolute or relative pathname; if
664it is relative, it may be converted to an absolute pathname using
665\code{os.path.join(os.path.dirname(\var{path}), \var{result})}.
Fred Drake215fe2f1999-02-02 19:02:35 +0000666Availability: \UNIX{}.
667\end{funcdesc}
668
669\begin{funcdesc}{remove}{path}
Fred Drakedc9e7e42001-05-29 18:13:06 +0000670Remove the file \var{path}. If \var{path} is a directory,
671\exception{OSError} is raised; see \function{rmdir()} below to remove
672a directory. This is identical to the \function{unlink()} function
673documented below. On Windows, attempting to remove a file that is in
674use causes an exception to be raised; on \UNIX, the directory entry is
675removed but the storage allocated to the file is not made available
676until the original file is no longer in use.
Fred Drake215fe2f1999-02-02 19:02:35 +0000677Availability: Macintosh, \UNIX{}, Windows.
678\end{funcdesc}
679
680\begin{funcdesc}{removedirs}{path}
681\index{directory!deleting}
682Recursive directory removal function. Works like
683\function{rmdir()} except that, if the leaf directory is
684successfully removed, directories corresponding to rightmost path
685segments will be pruned way until either the whole path is consumed or
686an error is raised (which is ignored, because it generally means that
687a parent directory is not empty). Throws an \exception{error}
688exception if the leaf directory could not be successfully removed.
689\versionadded{1.5.2}
690\end{funcdesc}
691
692\begin{funcdesc}{rename}{src, dst}
Fred Drakedc9e7e42001-05-29 18:13:06 +0000693Rename the file or directory \var{src} to \var{dst}. If \var{dst} is
694a directory, \exception{OSError} will be raised. On \UNIX, if
695\var{dst} exists and is a file, it will be removed silently if the
696user has permission. The operation may fail on some \UNIX{} flavors
Skip Montanarob9d973d2001-06-04 15:31:17 +0000697if \var{src} and \var{dst} are on different filesystems. If
Fred Drakedc9e7e42001-05-29 18:13:06 +0000698successful, the renaming will be an atomic operation (this is a
699\POSIX{} requirement). On Windows, if \var{dst} already exists,
700\exception{OSError} will be raised even if it is a file; there may be
701no way to implement an atomic rename when \var{dst} names an existing
702file.
Fred Drake215fe2f1999-02-02 19:02:35 +0000703Availability: Macintosh, \UNIX{}, Windows.
704\end{funcdesc}
705
706\begin{funcdesc}{renames}{old, new}
707Recursive directory or file renaming function.
708Works like \function{rename()}, except creation of any intermediate
709directories needed to make the new pathname good is attempted first.
710After the rename, directories corresponding to rightmost path segments
711of the old name will be pruned away using \function{removedirs()}.
712
713Note: this function can fail with the new directory structure made if
714you lack permissions needed to remove the leaf directory or file.
715\versionadded{1.5.2}
716\end{funcdesc}
717
718\begin{funcdesc}{rmdir}{path}
719Remove the directory \var{path}.
720Availability: Macintosh, \UNIX{}, Windows.
721\end{funcdesc}
722
723\begin{funcdesc}{stat}{path}
724Perform a \cfunction{stat()} system call on the given path. The
725return value is a tuple of at least 10 integers giving the most
726important (and portable) members of the \emph{stat} structure, in the
727order
728\code{st_mode},
729\code{st_ino},
730\code{st_dev},
731\code{st_nlink},
732\code{st_uid},
733\code{st_gid},
734\code{st_size},
735\code{st_atime},
736\code{st_mtime},
737\code{st_ctime}.
Fred Drake21c9df72000-10-14 05:46:11 +0000738More items may be added at the end by some implementations. Note that
739on the Macintosh, the time values are floating point values, like all
740time values on the Macintosh.
Fred Drake215fe2f1999-02-02 19:02:35 +0000741(On MS Windows, some items are filled with dummy values.)
742Availability: Macintosh, \UNIX{}, Windows.
743
744Note: The standard module \refmodule{stat}\refstmodindex{stat} defines
745functions and constants that are useful for extracting information
746from a \ctype{stat} structure.
747\end{funcdesc}
748
749\begin{funcdesc}{statvfs}{path}
750Perform a \cfunction{statvfs()} system call on the given path. The
Guido van Rossum0c9608c1999-02-03 16:32:37 +0000751return value is a tuple of 10 integers giving the most common
Fred Drake215fe2f1999-02-02 19:02:35 +0000752members of the \ctype{statvfs} structure, in the order
753\code{f_bsize},
754\code{f_frsize},
755\code{f_blocks},
756\code{f_bfree},
757\code{f_bavail},
758\code{f_files},
759\code{f_ffree},
760\code{f_favail},
Fred Drake215fe2f1999-02-02 19:02:35 +0000761\code{f_flag},
762\code{f_namemax}.
763Availability: \UNIX{}.
764
765Note: The standard module \module{statvfs}\refstmodindex{statvfs}
766defines constants that are useful for extracting information
767from a \ctype{statvfs} structure.
768\end{funcdesc}
769
770\begin{funcdesc}{symlink}{src, dst}
771Create a symbolic link pointing to \var{src} named \var{dst}.
772Availability: \UNIX{}.
773\end{funcdesc}
774
Fred Drake18f7a451999-12-09 22:11:43 +0000775\begin{funcdesc}{tempnam}{\optional{dir\optional{, prefix}}}
776Return a unique path name that is reasonable for creating a temporary
777file. This will be an absolute path that names a potential directory
778entry in the directory \var{dir} or a common location for temporary
779files if \var{dir} is omitted or \code{None}. If given and not
780\code{None}, \var{prefix} is used to provide a short prefix to the
781filename. Applications are responsible for properly creating and
782managing files created using paths returned by \function{tempnam()};
783no automatic cleanup is provided.
784\end{funcdesc}
785
786\begin{funcdesc}{tmpnam}{}
787Return a unique path name that is reasonable for creating a temporary
788file. This will be an absolute path that names a potential directory
789entry in a common location for temporary files. Applications are
790responsible for properly creating and managing files created using
791paths returned by \function{tmpnam()}; no automatic cleanup is
792provided.
793\end{funcdesc}
794
795\begin{datadesc}{TMP_MAX}
796The maximum number of unique names that \function{tmpnam()} will
797generate before reusing names.
798\end{datadesc}
799
Fred Drake215fe2f1999-02-02 19:02:35 +0000800\begin{funcdesc}{unlink}{path}
801Remove the file \var{path}. This is the same function as
802\function{remove()}; the \function{unlink()} name is its traditional
803\UNIX{} name.
804Availability: Macintosh, \UNIX{}, Windows.
805\end{funcdesc}
806
Barry Warsaw93a8eac2000-05-01 16:18:22 +0000807\begin{funcdesc}{utime}{path, times}
808Set the access and modified times of the file specified by \var{path}.
809If \var{times} is \code{None}, then the file's access and modified
810times are set to the current time. Otherwise, \var{times} must be a
Fred Drakee06d0252000-05-02 17:29:35 +00008112-tuple of numbers, of the form \code{(\var{atime}, \var{mtime})}
812which is used to set the access and modified times, respectively.
Fred Drake4a152632000-10-19 05:33:46 +0000813\versionchanged[Added support for \code{None} for \var{times}]{2.0}
Fred Drake215fe2f1999-02-02 19:02:35 +0000814Availability: Macintosh, \UNIX{}, Windows.
815\end{funcdesc}
816
817
818\subsection{Process Management \label{os-process}}
819
Fred Drake18f7a451999-12-09 22:11:43 +0000820These functions may be used to create and manage processes.
Fred Drake215fe2f1999-02-02 19:02:35 +0000821
Fred Drake7be31152000-09-23 05:22:07 +0000822The various \function{exec*()} functions take a list of arguments for
823the new program loaded into the process. In each case, the first of
824these arguments is passed to the new program as its own name rather
825than as an argument a user may have typed on a command line. For the
826C programmer, this is the \code{argv[0]} passed to a program's
827\cfunction{main()}. For example, \samp{os.execv('/bin/echo', ['foo',
828'bar'])} will only print \samp{bar} on standard output; \samp{foo}
829will seem to be ignored.
830
Fred Drake215fe2f1999-02-02 19:02:35 +0000831
Fred Drake18f7a451999-12-09 22:11:43 +0000832\begin{funcdesc}{abort}{}
833Generate a \constant{SIGABRT} signal to the current process. On
834\UNIX, the default behavior is to produce a core dump; on Windows, the
835process immediately returns an exit code of \code{3}. Be aware that
836programs which use \function{signal.signal()} to register a handler
837for \constant{SIGABRT} will behave differently.
838Availability: \UNIX, Windows.
839\end{funcdesc}
840
Fred Drake215fe2f1999-02-02 19:02:35 +0000841\begin{funcdesc}{execl}{path, arg0, arg1, ...}
842This is equivalent to
843\samp{execv(\var{path}, (\var{arg0}, \var{arg1}, ...))}.
844Availability: \UNIX{}, Windows.
845\end{funcdesc}
846
847\begin{funcdesc}{execle}{path, arg0, arg1, ..., env}
848This is equivalent to
849\samp{execve(\var{path}, (\var{arg0}, \var{arg1}, ...), \var{env})}.
850Availability: \UNIX{}, Windows.
851\end{funcdesc}
852
853\begin{funcdesc}{execlp}{path, arg0, arg1, ...}
854This is equivalent to
855\samp{execvp(\var{path}, (\var{arg0}, \var{arg1}, ...))}.
856Availability: \UNIX{}, Windows.
857\end{funcdesc}
858
859\begin{funcdesc}{execv}{path, args}
860Execute the executable \var{path} with argument list \var{args},
861replacing the current process (i.e., the Python interpreter).
862The argument list may be a tuple or list of strings.
863Availability: \UNIX{}, Windows.
864\end{funcdesc}
865
866\begin{funcdesc}{execve}{path, args, env}
867Execute the executable \var{path} with argument list \var{args},
868and environment \var{env},
869replacing the current process (i.e., the Python interpreter).
870The argument list may be a tuple or list of strings.
871The environment must be a dictionary mapping strings to strings.
872Availability: \UNIX{}, Windows.
873\end{funcdesc}
874
875\begin{funcdesc}{execvp}{path, args}
876This is like \samp{execv(\var{path}, \var{args})} but duplicates
877the shell's actions in searching for an executable file in a list of
878directories. The directory list is obtained from
879\code{environ['PATH']}.
880Availability: \UNIX{}, Windows.
881\end{funcdesc}
882
883\begin{funcdesc}{execvpe}{path, args, env}
884This is a cross between \function{execve()} and \function{execvp()}.
885The directory list is obtained from \code{\var{env}['PATH']}.
886Availability: \UNIX{}, Windows.
887\end{funcdesc}
888
889\begin{funcdesc}{_exit}{n}
890Exit to the system with status \var{n}, without calling cleanup
891handlers, flushing stdio buffers, etc.
892Availability: \UNIX{}, Windows.
893
894Note: the standard way to exit is \code{sys.exit(\var{n})}.
895\function{_exit()} should normally only be used in the child process
896after a \function{fork()}.
897\end{funcdesc}
898
899\begin{funcdesc}{fork}{}
900Fork a child process. Return \code{0} in the child, the child's
901process id in the parent.
902Availability: \UNIX{}.
903\end{funcdesc}
904
Fred Drakec82634c2000-06-28 17:27:48 +0000905\begin{funcdesc}{forkpty}{}
906Fork a child process, using a new pseudo-terminal as the child's
907controlling terminal. Return a pair of \code{(\var{pid}, \var{fd})},
908where \var{pid} is \code{0} in the child, the new child's process id
909in the parent, and \code{fd} is the file descriptor of the master end
910of the pseudo-terminal. For a more portable approach, use the
911\refmodule{pty} module.
912Availability: Some flavors of \UNIX{}
913\end{funcdesc}
914
Fred Drake215fe2f1999-02-02 19:02:35 +0000915\begin{funcdesc}{kill}{pid, sig}
916\index{process!killing}
917\index{process!signalling}
918Kill the process \var{pid} with signal \var{sig}.
919Availability: \UNIX{}.
920\end{funcdesc}
921
922\begin{funcdesc}{nice}{increment}
923Add \var{increment} to the process's ``niceness''. Return the new
924niceness.
925Availability: \UNIX{}.
926\end{funcdesc}
927
928\begin{funcdesc}{plock}{op}
929Lock program segments into memory. The value of \var{op}
930(defined in \code{<sys/lock.h>}) determines which segments are locked.
Fred Drake39063631999-02-26 14:05:02 +0000931Availability: \UNIX{}.
Fred Drake215fe2f1999-02-02 19:02:35 +0000932\end{funcdesc}
933
Fred Drake046f4d82001-06-11 15:21:48 +0000934\begin{funcdescni}{popen}{\unspecified}
935\funclineni{popen2}{\unspecified}
936\funclineni{popen3}{\unspecified}
937\funclineni{popen4}{\unspecified}
938Run child processes, returning opened pipes for communications. These
939functions are described in section \ref{os-newstreams}.
940\end{funcdescni}
941
Fred Drake215fe2f1999-02-02 19:02:35 +0000942\begin{funcdesc}{spawnv}{mode, path, args}
943Execute the program \var{path} in a new process, passing the arguments
944specified in \var{args} as command-line parameters. \var{args} may be
945a list or a tuple. \var{mode} is a magic operational constant. See
946the Visual \Cpp{} Runtime Library documentation for further
Fred Drake22702081999-07-02 14:01:03 +0000947information; the constants are exposed to the Python programmer as
948listed below.
Fred Drake15861b22000-02-29 05:19:38 +0000949Availability: \UNIX{}, Windows.
Fred Drake0b9bc202001-06-11 18:25:34 +0000950\versionadded{1.6}
Fred Drake215fe2f1999-02-02 19:02:35 +0000951\end{funcdesc}
952
953\begin{funcdesc}{spawnve}{mode, path, args, env}
954Execute the program \var{path} in a new process, passing the arguments
955specified in \var{args} as command-line parameters and the contents of
956the mapping \var{env} as the environment. \var{args} may be a list or
957a tuple. \var{mode} is a magic operational constant. See the Visual
Fred Drake22702081999-07-02 14:01:03 +0000958\Cpp{} Runtime Library documentation for further information; the
959constants are exposed to the Python programmer as listed below.
Fred Drake15861b22000-02-29 05:19:38 +0000960Availability: \UNIX{}, Windows.
Fred Drake0b9bc202001-06-11 18:25:34 +0000961\versionadded{1.6}
Fred Drake215fe2f1999-02-02 19:02:35 +0000962\end{funcdesc}
963
Fred Drake9329e5e1999-02-16 19:40:19 +0000964\begin{datadesc}{P_WAIT}
965\dataline{P_NOWAIT}
966\dataline{P_NOWAITO}
Fred Drake215fe2f1999-02-02 19:02:35 +0000967Possible values for the \var{mode} parameter to \function{spawnv()}
968and \function{spawnve()}.
Fred Drake15861b22000-02-29 05:19:38 +0000969Availability: \UNIX{}, Windows.
Fred Drake0b9bc202001-06-11 18:25:34 +0000970\versionadded{1.6}
Fred Drake15861b22000-02-29 05:19:38 +0000971\end{datadesc}
972
973\begin{datadesc}{P_OVERLAY}
974\dataline{P_DETACH}
975Possible values for the \var{mode} parameter to \function{spawnv()}
976and \function{spawnve()}. These are less portable than those listed
977above.
Fred Drake215fe2f1999-02-02 19:02:35 +0000978Availability: Windows.
Fred Drake0b9bc202001-06-11 18:25:34 +0000979\versionadded{1.6}
Fred Drake215fe2f1999-02-02 19:02:35 +0000980\end{datadesc}
981
Fred Drake4ce4f2e2000-09-29 04:15:19 +0000982\begin{funcdesc}{startfile}{path}
983Start a file with its associated application. This acts like
984double-clicking the file in Windows Explorer, or giving the file name
985as an argument to the DOS \program{start} command: the file is opened
986with whatever application (if any) its extension is associated.
987
988\function{startfile()} returns as soon as the associated application
989is launched. There is no option to wait for the application to close,
990and no way to retrieve the application's exit status. The \var{path}
991parameter is relative to the current directory. If you want to use an
992absolute path, make sure the first character is not a slash
993(\character{/}); the underlying Win32 \cfunction{ShellExecute()}
994function doesn't work it is. Use the \function{os.path.normpath()}
995function to ensure that the path is properly encoded for Win32.
996Availability: Windows.
997\versionadded{2.0}
998\end{funcdesc}
999
Fred Drake215fe2f1999-02-02 19:02:35 +00001000\begin{funcdesc}{system}{command}
1001Execute the command (a string) in a subshell. This is implemented by
1002calling the Standard C function \cfunction{system()}, and has the
Fred Drakeec6baaf1999-04-21 18:13:31 +00001003same limitations. Changes to \code{posix.environ}, \code{sys.stdin},
Fred Drake215fe2f1999-02-02 19:02:35 +00001004etc.\ are not reflected in the environment of the executed command.
1005The return value is the exit status of the process encoded in the
Fred Drake7a621281999-06-10 15:07:05 +00001006format specified for \function{wait()}, except on Windows 95 and 98,
Fred Drakea88ef001999-06-18 19:11:25 +00001007where it is always \code{0}. Note that \POSIX{} does not specify the
1008meaning of the return value of the C \cfunction{system()} function,
1009so the return value of the Python function is system-dependent.
Fred Drake215fe2f1999-02-02 19:02:35 +00001010Availability: \UNIX{}, Windows.
1011\end{funcdesc}
1012
1013\begin{funcdesc}{times}{}
1014Return a 5-tuple of floating point numbers indicating accumulated (CPU
1015or other)
1016times, in seconds. The items are: user time, system time, children's
1017user time, children's system time, and elapsed real time since a fixed
Fred Drakeec6baaf1999-04-21 18:13:31 +00001018point in the past, in that order. See the \UNIX{} manual page
1019\manpage{times}{2} or the corresponding Windows Platform API
1020documentation.
Fred Drake215fe2f1999-02-02 19:02:35 +00001021Availability: \UNIX{}, Windows.
1022\end{funcdesc}
1023
1024\begin{funcdesc}{wait}{}
1025Wait for completion of a child process, and return a tuple containing
1026its pid and exit status indication: a 16-bit number, whose low byte is
1027the signal number that killed the process, and whose high byte is the
1028exit status (if the signal number is zero); the high bit of the low
1029byte is set if a core file was produced.
1030Availability: \UNIX{}.
1031\end{funcdesc}
1032
1033\begin{funcdesc}{waitpid}{pid, options}
Fred Drake31e5e371999-08-13 13:36:33 +00001034Wait for completion of a child process given by process id \var{pid},
1035and return a tuple containing its process id and exit status
1036indication (encoded as for \function{wait()}). The semantics of the
1037call are affected by the value of the integer \var{options}, which
1038should be \code{0} for normal operation.
Fred Drake215fe2f1999-02-02 19:02:35 +00001039Availability: \UNIX{}.
Fred Drake31e5e371999-08-13 13:36:33 +00001040
1041If \var{pid} is greater than \code{0}, \function{waitpid()} requests
1042status information for that specific process. If \var{pid} is
1043\code{0}, the request is for the status of any child in the process
1044group of the current process. If \var{pid} is \code{-1}, the request
1045pertains to any child of the current process. If \var{pid} is less
1046than \code{-1}, status is requested for any process in the process
1047group \code{-\var{pid}} (the absolute value of \var{pid}).
Fred Drake215fe2f1999-02-02 19:02:35 +00001048\end{funcdesc}
1049
1050\begin{datadesc}{WNOHANG}
1051The option for \function{waitpid()} to avoid hanging if no child
1052process status is available immediately.
1053Availability: \UNIX{}.
1054\end{datadesc}
1055
Fred Drake38e5d272000-04-03 20:13:55 +00001056The following functions take a process status code as returned by
1057\function{system()}, \function{wait()}, or \function{waitpid()} as a
1058parameter. They may be used to determine the disposition of a
1059process.
Fred Drake215fe2f1999-02-02 19:02:35 +00001060
1061\begin{funcdesc}{WIFSTOPPED}{status}
1062Return true if the process has been stopped.
1063Availability: \UNIX{}.
1064\end{funcdesc}
1065
1066\begin{funcdesc}{WIFSIGNALED}{status}
1067Return true if the process exited due to a signal.
1068Availability: \UNIX{}.
1069\end{funcdesc}
1070
1071\begin{funcdesc}{WIFEXITED}{status}
1072Return true if the process exited using the \manpage{exit}{2} system
1073call.
1074Availability: \UNIX{}.
1075\end{funcdesc}
1076
1077\begin{funcdesc}{WEXITSTATUS}{status}
1078If \code{WIFEXITED(\var{status})} is true, return the integer
1079parameter to the \manpage{exit}{2} system call. Otherwise, the return
1080value is meaningless.
1081Availability: \UNIX{}.
1082\end{funcdesc}
1083
1084\begin{funcdesc}{WSTOPSIG}{status}
Fred Drake35c3ffd1999-03-04 14:08:10 +00001085Return the signal which caused the process to stop.
1086Availability: \UNIX{}.
1087\end{funcdesc}
1088
1089\begin{funcdesc}{WTERMSIG}{status}
Fred Drake215fe2f1999-02-02 19:02:35 +00001090Return the signal which caused the process to exit.
1091Availability: \UNIX{}.
1092\end{funcdesc}
1093
1094
Thomas Woutersf8316632000-07-16 19:01:10 +00001095\subsection{Miscellaneous System Information \label{os-path}}
Fred Drake88f6ca21999-12-15 19:39:04 +00001096
1097
1098\begin{funcdesc}{confstr}{name}
1099Return string-valued system configuration values.
1100\var{name} specifies the configuration value to retrieve; it may be a
1101string which is the name of a defined system value; these names are
1102specified in a number of standards (\POSIX, Unix95, Unix98, and
1103others). Some platforms define additional names as well. The names
1104known to the host operating system are given in the
1105\code{confstr_names} dictionary. For configuration variables not
1106included in that mapping, passing an integer for \var{name} is also
1107accepted.
1108Availability: \UNIX{}.
1109
1110If the configuration value specified by \var{name} isn't defined, the
1111empty string is returned.
1112
1113If \var{name} is a string and is not known, \exception{ValueError} is
1114raised. If a specific value for \var{name} is not supported by the
1115host system, even if it is included in \code{confstr_names}, an
1116\exception{OSError} is raised with \constant{errno.EINVAL} for the
1117error number.
1118\end{funcdesc}
1119
1120\begin{datadesc}{confstr_names}
1121Dictionary mapping names accepted by \function{confstr()} to the
1122integer values defined for those names by the host operating system.
1123This can be used to determine the set of names known to the system.
1124Availability: \UNIX.
1125\end{datadesc}
1126
1127\begin{funcdesc}{sysconf}{name}
1128Return integer-valued system configuration values.
1129If the configuration value specified by \var{name} isn't defined,
1130\code{-1} is returned. The comments regarding the \var{name}
1131parameter for \function{confstr()} apply here as well; the dictionary
1132that provides information on the known names is given by
1133\code{sysconf_names}.
1134Availability: \UNIX{}.
1135\end{funcdesc}
1136
1137\begin{datadesc}{sysconf_names}
1138Dictionary mapping names accepted by \function{sysconf()} to the
1139integer values defined for those names by the host operating system.
1140This can be used to determine the set of names known to the system.
1141Availability: \UNIX.
1142\end{datadesc}
1143
Fred Drake215fe2f1999-02-02 19:02:35 +00001144
1145The follow data values are used to support path manipulation
1146operations. These are defined for all platforms.
1147
1148Higher-level operations on pathnames are defined in the
1149\refmodule{os.path} module.
1150
1151
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00001152\begin{datadesc}{curdir}
1153The constant string used by the OS to refer to the current directory,
Fred Drake1a3c2a01998-08-06 15:18:23 +00001154e.g.\ \code{'.'} for \POSIX{} or \code{':'} for the Macintosh.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00001155\end{datadesc}
1156
1157\begin{datadesc}{pardir}
1158The constant string used by the OS to refer to the parent directory,
Fred Drake1a3c2a01998-08-06 15:18:23 +00001159e.g.\ \code{'..'} for \POSIX{} or \code{'::'} for the Macintosh.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00001160\end{datadesc}
1161
1162\begin{datadesc}{sep}
Guido van Rossumb2afc811997-08-29 22:37:44 +00001163The character used by the OS to separate pathname components,
Fred Drake1a3c2a01998-08-06 15:18:23 +00001164e.g.\ \character{/} for \POSIX{} or \character{:} for the Macintosh.
1165Note that knowing this is not sufficient to be able to parse or
1166concatenate pathnames --- use \function{os.path.split()} and
1167\function{os.path.join()} --- but it is occasionally useful.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00001168\end{datadesc}
1169
Guido van Rossumb2afc811997-08-29 22:37:44 +00001170\begin{datadesc}{altsep}
1171An alternative character used by the OS to separate pathname components,
1172or \code{None} if only one separator character exists. This is set to
Fred Drake215fe2f1999-02-02 19:02:35 +00001173\character{/} on DOS and Windows systems where \code{sep} is a backslash.
Guido van Rossumb2afc811997-08-29 22:37:44 +00001174\end{datadesc}
1175
Guido van Rossum470be141995-03-17 16:07:09 +00001176\begin{datadesc}{pathsep}
1177The character conventionally used by the OS to separate search patch
Fred Drake1a3c2a01998-08-06 15:18:23 +00001178components (as in \envvar{PATH}), e.g.\ \character{:} for \POSIX{} or
Fred Drake215fe2f1999-02-02 19:02:35 +00001179\character{;} for DOS and Windows.
Guido van Rossum9c59ce91998-06-30 15:54:27 +00001180\end{datadesc}
1181
Guido van Rossum470be141995-03-17 16:07:09 +00001182\begin{datadesc}{defpath}
Fred Drake1a3c2a01998-08-06 15:18:23 +00001183The default search path used by \function{exec*p*()} if the environment
Guido van Rossum470be141995-03-17 16:07:09 +00001184doesn't have a \code{'PATH'} key.
1185\end{datadesc}
1186
Fred Drake215fe2f1999-02-02 19:02:35 +00001187\begin{datadesc}{linesep}
1188The string used to separate (or, rather, terminate) lines on the
Fred Drakeec6baaf1999-04-21 18:13:31 +00001189current platform. This may be a single character,
1190e.g.\ \code{'\e n'} for \POSIX{} or \code{'\e r'} for MacOS, or multiple
1191characters, e.g.\ \code{'\e r\e n'} for MS-DOS and MS Windows.
Fred Drake215fe2f1999-02-02 19:02:35 +00001192\end{datadesc}