blob: 90c5f08af6cf3cc4e48fa42b91440b3fdef91903 [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})}.
320\versionadded{2.0}
321\end{funcdesc}
322
Fred Drake046f4d82001-06-11 15:21:48 +0000323\begin{funcdesc}{popen3}{cmd\optional{, mode\optional{, bufsize}}}
Fred Drake8a9db992000-09-28 20:27:51 +0000324Executes \var{cmd} as a sub-process. Returns the file objects
325\code{(\var{child_stdin}, \var{child_stdout}, \var{child_stderr})}.
326\versionadded{2.0}
327\end{funcdesc}
328
Fred Drake046f4d82001-06-11 15:21:48 +0000329\begin{funcdesc}{popen4}{cmd\optional{, mode\optional{, bufsize}}}
Fred Drake8a9db992000-09-28 20:27:51 +0000330Executes \var{cmd} as a sub-process. Returns the file objects
331\code{(\var{child_stdin}, \var{child_stdout_and_stderr})}.
332\versionadded{2.0}
333\end{funcdesc}
334
335This functionality is also available in the \refmodule{popen2} module
336using functions of the same names, but the return values of those
337functions have a different order.
338
339
Fred Drake215fe2f1999-02-02 19:02:35 +0000340\subsection{File Descriptor Operations \label{os-fd-ops}}
341
342These functions operate on I/O streams referred to
343using file descriptors.
344
345
346\begin{funcdesc}{close}{fd}
347Close file descriptor \var{fd}.
348Availability: Macintosh, \UNIX{}, Windows.
349
350Note: this function is intended for low-level I/O and must be applied
351to a file descriptor as returned by \function{open()} or
352\function{pipe()}. To close a ``file object'' returned by the
353built-in function \function{open()} or by \function{popen()} or
354\function{fdopen()}, use its \method{close()} method.
355\end{funcdesc}
356
357\begin{funcdesc}{dup}{fd}
358Return a duplicate of file descriptor \var{fd}.
359Availability: Macintosh, \UNIX{}, Windows.
360\end{funcdesc}
361
362\begin{funcdesc}{dup2}{fd, fd2}
363Duplicate file descriptor \var{fd} to \var{fd2}, closing the latter
364first if necessary.
365Availability: \UNIX{}, Windows.
366\end{funcdesc}
367
Fred Drake88f6ca21999-12-15 19:39:04 +0000368\begin{funcdesc}{fpathconf}{fd, name}
Thomas Woutersf8316632000-07-16 19:01:10 +0000369Return system configuration information relevant to an open file.
Fred Drake88f6ca21999-12-15 19:39:04 +0000370\var{name} specifies the configuration value to retrieve; it may be a
371string which is the name of a defined system value; these names are
372specified in a number of standards (\POSIX.1, Unix95, Unix98, and
373others). Some platforms define additional names as well. The names
374known to the host operating system are given in the
375\code{pathconf_names} dictionary. For configuration variables not
376included in that mapping, passing an integer for \var{name} is also
377accepted.
378Availability: \UNIX{}.
379
380If \var{name} is a string and is not known, \exception{ValueError} is
381raised. If a specific value for \var{name} is not supported by the
382host system, even if it is included in \code{pathconf_names}, an
383\exception{OSError} is raised with \constant{errno.EINVAL} for the
384error number.
385\end{funcdesc}
386
Fred Drake215fe2f1999-02-02 19:02:35 +0000387\begin{funcdesc}{fstat}{fd}
388Return status for file descriptor \var{fd}, like \function{stat()}.
389Availability: \UNIX{}, Windows.
390\end{funcdesc}
391
392\begin{funcdesc}{fstatvfs}{fd}
393Return information about the filesystem containing the file associated
394with file descriptor \var{fd}, like \function{statvfs()}.
395Availability: \UNIX{}.
396\end{funcdesc}
397
398\begin{funcdesc}{ftruncate}{fd, length}
399Truncate the file corresponding to file descriptor \var{fd},
400so that it is at most \var{length} bytes in size.
401Availability: \UNIX{}.
402\end{funcdesc}
403
Skip Montanarod3725212000-07-19 17:30:58 +0000404\begin{funcdesc}{isatty}{fd}
405Return \code{1} if the file descriptor \var{fd} is open and connected to a
406tty(-like) device, else \code{0}.
407Availability: \UNIX{}
408\end{funcdesc}
409
Fred Drake215fe2f1999-02-02 19:02:35 +0000410\begin{funcdesc}{lseek}{fd, pos, how}
411Set the current position of file descriptor \var{fd} to position
412\var{pos}, modified by \var{how}: \code{0} to set the position
413relative to the beginning of the file; \code{1} to set it relative to
414the current position; \code{2} to set it relative to the end of the
415file.
416Availability: Macintosh, \UNIX{}, Windows.
417\end{funcdesc}
418
419\begin{funcdesc}{open}{file, flags\optional{, mode}}
420Open the file \var{file} and set various flags according to
421\var{flags} and possibly its mode according to \var{mode}.
422The default \var{mode} is \code{0777} (octal), and the current umask
423value is first masked out. Return the file descriptor for the newly
424opened file.
425Availability: Macintosh, \UNIX{}, Windows.
426
427For a description of the flag and mode values, see the C run-time
428documentation; flag constants (like \constant{O_RDONLY} and
429\constant{O_WRONLY}) are defined in this module too (see below).
430
431Note: this function is intended for low-level I/O. For normal usage,
432use the built-in function \function{open()}, which returns a ``file
433object'' with \method{read()} and \method{write()} methods (and many
434more).
435\end{funcdesc}
436
Fred Drakec82634c2000-06-28 17:27:48 +0000437\begin{funcdesc}{openpty}{}
438Open a new pseudo-terminal pair. Return a pair of file descriptors
439\code{(\var{master}, \var{slave})} for the pty and the tty,
440respectively. For a (slightly) more portable approach, use the
441\refmodule{pty}\refstmodindex{pty} module.
442Availability: Some flavors of \UNIX{}
443\end{funcdesc}
444
Fred Drake215fe2f1999-02-02 19:02:35 +0000445\begin{funcdesc}{pipe}{}
446Create a pipe. Return a pair of file descriptors \code{(\var{r},
447\var{w})} usable for reading and writing, respectively.
448Availability: \UNIX{}, Windows.
449\end{funcdesc}
450
451\begin{funcdesc}{read}{fd, n}
452Read at most \var{n} bytes from file descriptor \var{fd}.
453Return a string containing the bytes read.
454Availability: Macintosh, \UNIX{}, Windows.
455
456Note: this function is intended for low-level I/O and must be applied
457to a file descriptor as returned by \function{open()} or
458\function{pipe()}. To read a ``file object'' returned by the
459built-in function \function{open()} or by \function{popen()} or
460\function{fdopen()}, or \code{sys.stdin}, use its
461\method{read()} or \method{readline()} methods.
462\end{funcdesc}
463
464\begin{funcdesc}{tcgetpgrp}{fd}
465Return the process group associated with the terminal given by
466\var{fd} (an open file descriptor as returned by \function{open()}).
467Availability: \UNIX{}.
468\end{funcdesc}
469
470\begin{funcdesc}{tcsetpgrp}{fd, pg}
471Set the process group associated with the terminal given by
472\var{fd} (an open file descriptor as returned by \function{open()})
473to \var{pg}.
474Availability: \UNIX{}.
475\end{funcdesc}
476
477\begin{funcdesc}{ttyname}{fd}
478Return a string which specifies the terminal device associated with
479file-descriptor \var{fd}. If \var{fd} is not associated with a terminal
480device, an exception is raised.
481Availability: \UNIX{}.
482\end{funcdesc}
483
484\begin{funcdesc}{write}{fd, str}
485Write the string \var{str} to file descriptor \var{fd}.
486Return the number of bytes actually written.
487Availability: Macintosh, \UNIX{}, Windows.
488
489Note: this function is intended for low-level I/O and must be applied
490to a file descriptor as returned by \function{open()} or
491\function{pipe()}. To write a ``file object'' returned by the
492built-in function \function{open()} or by \function{popen()} or
493\function{fdopen()}, or \code{sys.stdout} or \code{sys.stderr}, use
494its \method{write()} method.
495\end{funcdesc}
496
497
498The following data items are available for use in constructing the
499\var{flags} parameter to the \function{open()} function.
500
501\begin{datadesc}{O_RDONLY}
502\dataline{O_WRONLY}
503\dataline{O_RDWR}
504\dataline{O_NDELAY}
505\dataline{O_NONBLOCK}
506\dataline{O_APPEND}
507\dataline{O_DSYNC}
508\dataline{O_RSYNC}
509\dataline{O_SYNC}
510\dataline{O_NOCTTY}
511\dataline{O_CREAT}
512\dataline{O_EXCL}
513\dataline{O_TRUNC}
514Options for the \var{flag} argument to the \function{open()} function.
515These can be bit-wise OR'd together.
516Availability: Macintosh, \UNIX{}, Windows.
517\end{datadesc}
518
Fred Drake3ac977e2000-08-11 20:19:51 +0000519\begin{datadesc}{O_BINARY}
520Option for the \var{flag} argument to the \function{open()} function.
521This can be bit-wise OR'd together with those listed above.
522Availability: Macintosh, Windows.
523% XXX need to check on the availability of this one.
524\end{datadesc}
525
Fred Drake215fe2f1999-02-02 19:02:35 +0000526
527\subsection{Files and Directories \label{os-file-dir}}
528
529\begin{funcdesc}{access}{path, mode}
Fred Drake38e5d272000-04-03 20:13:55 +0000530Check read/write/execute permissions for this process or existence of
531file \var{path}. \var{mode} should be \constant{F_OK} to test the
532existence of \var{path}, or it can be the inclusive OR of one or more
533of \constant{R_OK}, \constant{W_OK}, and \constant{X_OK} to test
534permissions. Return \code{1} if access is allowed, \code{0} if not.
535See the \UNIX{} man page \manpage{access}{2} for more information.
Fred Drake3ac977e2000-08-11 20:19:51 +0000536Availability: \UNIX{}, Windows.
Fred Drake215fe2f1999-02-02 19:02:35 +0000537\end{funcdesc}
538
Fred Drake38e5d272000-04-03 20:13:55 +0000539\begin{datadesc}{F_OK}
540 Value to pass as the \var{mode} parameter of \function{access()} to
541 test the existence of \var{path}.
542\end{datadesc}
543
544\begin{datadesc}{R_OK}
545 Value to include in the \var{mode} parameter of \function{access()}
546 to test the readability of \var{path}.
547\end{datadesc}
548
549\begin{datadesc}{W_OK}
550 Value to include in the \var{mode} parameter of \function{access()}
551 to test the writability of \var{path}.
552\end{datadesc}
553
554\begin{datadesc}{X_OK}
555 Value to include in the \var{mode} parameter of \function{access()}
556 to determine if \var{path} can be executed.
557\end{datadesc}
558
Fred Drake6db897c1999-07-12 16:49:30 +0000559\begin{funcdesc}{chdir}{path}
560\index{directory!changing}
561Change the current working directory to \var{path}.
562Availability: Macintosh, \UNIX{}, Windows.
563\end{funcdesc}
564
565\begin{funcdesc}{getcwd}{}
566Return a string representing the current working directory.
567Availability: Macintosh, \UNIX{}, Windows.
568\end{funcdesc}
569
Fred Drake215fe2f1999-02-02 19:02:35 +0000570\begin{funcdesc}{chmod}{path, mode}
571Change the mode of \var{path} to the numeric \var{mode}.
572Availability: \UNIX{}, Windows.
573\end{funcdesc}
574
575\begin{funcdesc}{chown}{path, uid, gid}
576Change the owner and group id of \var{path} to the numeric \var{uid}
577and \var{gid}.
578Availability: \UNIX{}.
579\end{funcdesc}
580
581\begin{funcdesc}{link}{src, dst}
582Create a hard link pointing to \var{src} named \var{dst}.
583Availability: \UNIX{}.
584\end{funcdesc}
585
586\begin{funcdesc}{listdir}{path}
587Return a list containing the names of the entries in the directory.
588The list is in arbitrary order. It does not include the special
589entries \code{'.'} and \code{'..'} even if they are present in the
590directory.
591Availability: Macintosh, \UNIX{}, Windows.
592\end{funcdesc}
593
594\begin{funcdesc}{lstat}{path}
595Like \function{stat()}, but do not follow symbolic links.
596Availability: \UNIX{}.
597\end{funcdesc}
598
599\begin{funcdesc}{mkfifo}{path\optional{, mode}}
600Create a FIFO (a named pipe) named \var{path} with numeric mode
601\var{mode}. The default \var{mode} is \code{0666} (octal). The current
602umask value is first masked out from the mode.
603Availability: \UNIX{}.
604
605FIFOs are pipes that can be accessed like regular files. FIFOs exist
606until they are deleted (for example with \function{os.unlink()}).
607Generally, FIFOs are used as rendezvous between ``client'' and
608``server'' type processes: the server opens the FIFO for reading, and
609the client opens it for writing. Note that \function{mkfifo()}
610doesn't open the FIFO --- it just creates the rendezvous point.
611\end{funcdesc}
612
613\begin{funcdesc}{mkdir}{path\optional{, mode}}
614Create a directory named \var{path} with numeric mode \var{mode}.
615The default \var{mode} is \code{0777} (octal). On some systems,
616\var{mode} is ignored. Where it is used, the current umask value is
617first masked out.
618Availability: Macintosh, \UNIX{}, Windows.
619\end{funcdesc}
620
621\begin{funcdesc}{makedirs}{path\optional{, mode}}
622\index{directory!creating}
623Recursive directory creation function. Like \function{mkdir()},
624but makes all intermediate-level directories needed to contain the
625leaf directory. Throws an \exception{error} exception if the leaf
626directory already exists or cannot be created. The default \var{mode}
627is \code{0777} (octal).
628\versionadded{1.5.2}
629\end{funcdesc}
630
Fred Drake88f6ca21999-12-15 19:39:04 +0000631\begin{funcdesc}{pathconf}{path, name}
Thomas Woutersf8316632000-07-16 19:01:10 +0000632Return system configuration information relevant to a named file.
Fred Drake88f6ca21999-12-15 19:39:04 +0000633\var{name} specifies the configuration value to retrieve; it may be a
634string which is the name of a defined system value; these names are
635specified in a number of standards (\POSIX.1, Unix95, Unix98, and
636others). Some platforms define additional names as well. The names
637known to the host operating system are given in the
638\code{pathconf_names} dictionary. For configuration variables not
639included in that mapping, passing an integer for \var{name} is also
640accepted.
641Availability: \UNIX{}.
642
643If \var{name} is a string and is not known, \exception{ValueError} is
644raised. If a specific value for \var{name} is not supported by the
645host system, even if it is included in \code{pathconf_names}, an
646\exception{OSError} is raised with \constant{errno.EINVAL} for the
647error number.
648\end{funcdesc}
649
650\begin{datadesc}{pathconf_names}
651Dictionary mapping names accepted by \function{pathconf()} and
652\function{fpathconf()} to the integer values defined for those names
653by the host operating system. This can be used to determine the set
654of names known to the system.
655Availability: \UNIX.
656\end{datadesc}
657
Fred Drake215fe2f1999-02-02 19:02:35 +0000658\begin{funcdesc}{readlink}{path}
659Return a string representing the path to which the symbolic link
Fred Drakedc9e7e42001-05-29 18:13:06 +0000660points. The result may be either an absolute or relative pathname; if
661it is relative, it may be converted to an absolute pathname using
662\code{os.path.join(os.path.dirname(\var{path}), \var{result})}.
Fred Drake215fe2f1999-02-02 19:02:35 +0000663Availability: \UNIX{}.
664\end{funcdesc}
665
666\begin{funcdesc}{remove}{path}
Fred Drakedc9e7e42001-05-29 18:13:06 +0000667Remove the file \var{path}. If \var{path} is a directory,
668\exception{OSError} is raised; see \function{rmdir()} below to remove
669a directory. This is identical to the \function{unlink()} function
670documented below. On Windows, attempting to remove a file that is in
671use causes an exception to be raised; on \UNIX, the directory entry is
672removed but the storage allocated to the file is not made available
673until the original file is no longer in use.
Fred Drake215fe2f1999-02-02 19:02:35 +0000674Availability: Macintosh, \UNIX{}, Windows.
675\end{funcdesc}
676
677\begin{funcdesc}{removedirs}{path}
678\index{directory!deleting}
679Recursive directory removal function. Works like
680\function{rmdir()} except that, if the leaf directory is
681successfully removed, directories corresponding to rightmost path
682segments will be pruned way until either the whole path is consumed or
683an error is raised (which is ignored, because it generally means that
684a parent directory is not empty). Throws an \exception{error}
685exception if the leaf directory could not be successfully removed.
686\versionadded{1.5.2}
687\end{funcdesc}
688
689\begin{funcdesc}{rename}{src, dst}
Fred Drakedc9e7e42001-05-29 18:13:06 +0000690Rename the file or directory \var{src} to \var{dst}. If \var{dst} is
691a directory, \exception{OSError} will be raised. On \UNIX, if
692\var{dst} exists and is a file, it will be removed silently if the
693user has permission. The operation may fail on some \UNIX{} flavors
Skip Montanarob9d973d2001-06-04 15:31:17 +0000694if \var{src} and \var{dst} are on different filesystems. If
Fred Drakedc9e7e42001-05-29 18:13:06 +0000695successful, the renaming will be an atomic operation (this is a
696\POSIX{} requirement). On Windows, if \var{dst} already exists,
697\exception{OSError} will be raised even if it is a file; there may be
698no way to implement an atomic rename when \var{dst} names an existing
699file.
Fred Drake215fe2f1999-02-02 19:02:35 +0000700Availability: Macintosh, \UNIX{}, Windows.
701\end{funcdesc}
702
703\begin{funcdesc}{renames}{old, new}
704Recursive directory or file renaming function.
705Works like \function{rename()}, except creation of any intermediate
706directories needed to make the new pathname good is attempted first.
707After the rename, directories corresponding to rightmost path segments
708of the old name will be pruned away using \function{removedirs()}.
709
710Note: this function can fail with the new directory structure made if
711you lack permissions needed to remove the leaf directory or file.
712\versionadded{1.5.2}
713\end{funcdesc}
714
715\begin{funcdesc}{rmdir}{path}
716Remove the directory \var{path}.
717Availability: Macintosh, \UNIX{}, Windows.
718\end{funcdesc}
719
720\begin{funcdesc}{stat}{path}
721Perform a \cfunction{stat()} system call on the given path. The
722return value is a tuple of at least 10 integers giving the most
723important (and portable) members of the \emph{stat} structure, in the
724order
725\code{st_mode},
726\code{st_ino},
727\code{st_dev},
728\code{st_nlink},
729\code{st_uid},
730\code{st_gid},
731\code{st_size},
732\code{st_atime},
733\code{st_mtime},
734\code{st_ctime}.
Fred Drake21c9df72000-10-14 05:46:11 +0000735More items may be added at the end by some implementations. Note that
736on the Macintosh, the time values are floating point values, like all
737time values on the Macintosh.
Fred Drake215fe2f1999-02-02 19:02:35 +0000738(On MS Windows, some items are filled with dummy values.)
739Availability: Macintosh, \UNIX{}, Windows.
740
741Note: The standard module \refmodule{stat}\refstmodindex{stat} defines
742functions and constants that are useful for extracting information
743from a \ctype{stat} structure.
744\end{funcdesc}
745
746\begin{funcdesc}{statvfs}{path}
747Perform a \cfunction{statvfs()} system call on the given path. The
Guido van Rossum0c9608c1999-02-03 16:32:37 +0000748return value is a tuple of 10 integers giving the most common
Fred Drake215fe2f1999-02-02 19:02:35 +0000749members of the \ctype{statvfs} structure, in the order
750\code{f_bsize},
751\code{f_frsize},
752\code{f_blocks},
753\code{f_bfree},
754\code{f_bavail},
755\code{f_files},
756\code{f_ffree},
757\code{f_favail},
Fred Drake215fe2f1999-02-02 19:02:35 +0000758\code{f_flag},
759\code{f_namemax}.
760Availability: \UNIX{}.
761
762Note: The standard module \module{statvfs}\refstmodindex{statvfs}
763defines constants that are useful for extracting information
764from a \ctype{statvfs} structure.
765\end{funcdesc}
766
767\begin{funcdesc}{symlink}{src, dst}
768Create a symbolic link pointing to \var{src} named \var{dst}.
769Availability: \UNIX{}.
770\end{funcdesc}
771
Fred Drake18f7a451999-12-09 22:11:43 +0000772\begin{funcdesc}{tempnam}{\optional{dir\optional{, prefix}}}
773Return a unique path name that is reasonable for creating a temporary
774file. This will be an absolute path that names a potential directory
775entry in the directory \var{dir} or a common location for temporary
776files if \var{dir} is omitted or \code{None}. If given and not
777\code{None}, \var{prefix} is used to provide a short prefix to the
778filename. Applications are responsible for properly creating and
779managing files created using paths returned by \function{tempnam()};
780no automatic cleanup is provided.
781\end{funcdesc}
782
783\begin{funcdesc}{tmpnam}{}
784Return a unique path name that is reasonable for creating a temporary
785file. This will be an absolute path that names a potential directory
786entry in a common location for temporary files. Applications are
787responsible for properly creating and managing files created using
788paths returned by \function{tmpnam()}; no automatic cleanup is
789provided.
790\end{funcdesc}
791
792\begin{datadesc}{TMP_MAX}
793The maximum number of unique names that \function{tmpnam()} will
794generate before reusing names.
795\end{datadesc}
796
Fred Drake215fe2f1999-02-02 19:02:35 +0000797\begin{funcdesc}{unlink}{path}
798Remove the file \var{path}. This is the same function as
799\function{remove()}; the \function{unlink()} name is its traditional
800\UNIX{} name.
801Availability: Macintosh, \UNIX{}, Windows.
802\end{funcdesc}
803
Barry Warsaw93a8eac2000-05-01 16:18:22 +0000804\begin{funcdesc}{utime}{path, times}
805Set the access and modified times of the file specified by \var{path}.
806If \var{times} is \code{None}, then the file's access and modified
807times are set to the current time. Otherwise, \var{times} must be a
Fred Drakee06d0252000-05-02 17:29:35 +00008082-tuple of numbers, of the form \code{(\var{atime}, \var{mtime})}
809which is used to set the access and modified times, respectively.
Fred Drake4a152632000-10-19 05:33:46 +0000810\versionchanged[Added support for \code{None} for \var{times}]{2.0}
Fred Drake215fe2f1999-02-02 19:02:35 +0000811Availability: Macintosh, \UNIX{}, Windows.
812\end{funcdesc}
813
814
815\subsection{Process Management \label{os-process}}
816
Fred Drake18f7a451999-12-09 22:11:43 +0000817These functions may be used to create and manage processes.
Fred Drake215fe2f1999-02-02 19:02:35 +0000818
Fred Drake7be31152000-09-23 05:22:07 +0000819The various \function{exec*()} functions take a list of arguments for
820the new program loaded into the process. In each case, the first of
821these arguments is passed to the new program as its own name rather
822than as an argument a user may have typed on a command line. For the
823C programmer, this is the \code{argv[0]} passed to a program's
824\cfunction{main()}. For example, \samp{os.execv('/bin/echo', ['foo',
825'bar'])} will only print \samp{bar} on standard output; \samp{foo}
826will seem to be ignored.
827
Fred Drake215fe2f1999-02-02 19:02:35 +0000828
Fred Drake18f7a451999-12-09 22:11:43 +0000829\begin{funcdesc}{abort}{}
830Generate a \constant{SIGABRT} signal to the current process. On
831\UNIX, the default behavior is to produce a core dump; on Windows, the
832process immediately returns an exit code of \code{3}. Be aware that
833programs which use \function{signal.signal()} to register a handler
834for \constant{SIGABRT} will behave differently.
835Availability: \UNIX, Windows.
836\end{funcdesc}
837
Fred Drake215fe2f1999-02-02 19:02:35 +0000838\begin{funcdesc}{execl}{path, arg0, arg1, ...}
839This is equivalent to
840\samp{execv(\var{path}, (\var{arg0}, \var{arg1}, ...))}.
841Availability: \UNIX{}, Windows.
842\end{funcdesc}
843
844\begin{funcdesc}{execle}{path, arg0, arg1, ..., env}
845This is equivalent to
846\samp{execve(\var{path}, (\var{arg0}, \var{arg1}, ...), \var{env})}.
847Availability: \UNIX{}, Windows.
848\end{funcdesc}
849
850\begin{funcdesc}{execlp}{path, arg0, arg1, ...}
851This is equivalent to
852\samp{execvp(\var{path}, (\var{arg0}, \var{arg1}, ...))}.
853Availability: \UNIX{}, Windows.
854\end{funcdesc}
855
856\begin{funcdesc}{execv}{path, args}
857Execute the executable \var{path} with argument list \var{args},
858replacing the current process (i.e., the Python interpreter).
859The argument list may be a tuple or list of strings.
860Availability: \UNIX{}, Windows.
861\end{funcdesc}
862
863\begin{funcdesc}{execve}{path, args, env}
864Execute the executable \var{path} with argument list \var{args},
865and environment \var{env},
866replacing the current process (i.e., the Python interpreter).
867The argument list may be a tuple or list of strings.
868The environment must be a dictionary mapping strings to strings.
869Availability: \UNIX{}, Windows.
870\end{funcdesc}
871
872\begin{funcdesc}{execvp}{path, args}
873This is like \samp{execv(\var{path}, \var{args})} but duplicates
874the shell's actions in searching for an executable file in a list of
875directories. The directory list is obtained from
876\code{environ['PATH']}.
877Availability: \UNIX{}, Windows.
878\end{funcdesc}
879
880\begin{funcdesc}{execvpe}{path, args, env}
881This is a cross between \function{execve()} and \function{execvp()}.
882The directory list is obtained from \code{\var{env}['PATH']}.
883Availability: \UNIX{}, Windows.
884\end{funcdesc}
885
886\begin{funcdesc}{_exit}{n}
887Exit to the system with status \var{n}, without calling cleanup
888handlers, flushing stdio buffers, etc.
889Availability: \UNIX{}, Windows.
890
891Note: the standard way to exit is \code{sys.exit(\var{n})}.
892\function{_exit()} should normally only be used in the child process
893after a \function{fork()}.
894\end{funcdesc}
895
896\begin{funcdesc}{fork}{}
897Fork a child process. Return \code{0} in the child, the child's
898process id in the parent.
899Availability: \UNIX{}.
900\end{funcdesc}
901
Fred Drakec82634c2000-06-28 17:27:48 +0000902\begin{funcdesc}{forkpty}{}
903Fork a child process, using a new pseudo-terminal as the child's
904controlling terminal. Return a pair of \code{(\var{pid}, \var{fd})},
905where \var{pid} is \code{0} in the child, the new child's process id
906in the parent, and \code{fd} is the file descriptor of the master end
907of the pseudo-terminal. For a more portable approach, use the
908\refmodule{pty} module.
909Availability: Some flavors of \UNIX{}
910\end{funcdesc}
911
Fred Drake215fe2f1999-02-02 19:02:35 +0000912\begin{funcdesc}{kill}{pid, sig}
913\index{process!killing}
914\index{process!signalling}
915Kill the process \var{pid} with signal \var{sig}.
916Availability: \UNIX{}.
917\end{funcdesc}
918
919\begin{funcdesc}{nice}{increment}
920Add \var{increment} to the process's ``niceness''. Return the new
921niceness.
922Availability: \UNIX{}.
923\end{funcdesc}
924
925\begin{funcdesc}{plock}{op}
926Lock program segments into memory. The value of \var{op}
927(defined in \code{<sys/lock.h>}) determines which segments are locked.
Fred Drake39063631999-02-26 14:05:02 +0000928Availability: \UNIX{}.
Fred Drake215fe2f1999-02-02 19:02:35 +0000929\end{funcdesc}
930
Fred Drake046f4d82001-06-11 15:21:48 +0000931\begin{funcdescni}{popen}{\unspecified}
932\funclineni{popen2}{\unspecified}
933\funclineni{popen3}{\unspecified}
934\funclineni{popen4}{\unspecified}
935Run child processes, returning opened pipes for communications. These
936functions are described in section \ref{os-newstreams}.
937\end{funcdescni}
938
Fred Drake215fe2f1999-02-02 19:02:35 +0000939\begin{funcdesc}{spawnv}{mode, path, args}
940Execute the program \var{path} in a new process, passing the arguments
941specified in \var{args} as command-line parameters. \var{args} may be
942a list or a tuple. \var{mode} is a magic operational constant. See
943the Visual \Cpp{} Runtime Library documentation for further
Fred Drake22702081999-07-02 14:01:03 +0000944information; the constants are exposed to the Python programmer as
945listed below.
Fred Drake15861b22000-02-29 05:19:38 +0000946Availability: \UNIX{}, Windows.
Fred Drake215fe2f1999-02-02 19:02:35 +0000947\versionadded{1.5.2}
948\end{funcdesc}
949
950\begin{funcdesc}{spawnve}{mode, path, args, env}
951Execute the program \var{path} in a new process, passing the arguments
952specified in \var{args} as command-line parameters and the contents of
953the mapping \var{env} as the environment. \var{args} may be a list or
954a tuple. \var{mode} is a magic operational constant. See the Visual
Fred Drake22702081999-07-02 14:01:03 +0000955\Cpp{} Runtime Library documentation for further information; the
956constants are exposed to the Python programmer as listed below.
Fred Drake15861b22000-02-29 05:19:38 +0000957Availability: \UNIX{}, Windows.
Fred Drake215fe2f1999-02-02 19:02:35 +0000958\versionadded{1.5.2}
959\end{funcdesc}
960
Fred Drake9329e5e1999-02-16 19:40:19 +0000961\begin{datadesc}{P_WAIT}
962\dataline{P_NOWAIT}
963\dataline{P_NOWAITO}
Fred Drake215fe2f1999-02-02 19:02:35 +0000964Possible values for the \var{mode} parameter to \function{spawnv()}
965and \function{spawnve()}.
Fred Drake15861b22000-02-29 05:19:38 +0000966Availability: \UNIX{}, Windows.
967\versionadded{1.5.2}
968\end{datadesc}
969
970\begin{datadesc}{P_OVERLAY}
971\dataline{P_DETACH}
972Possible values for the \var{mode} parameter to \function{spawnv()}
973and \function{spawnve()}. These are less portable than those listed
974above.
Fred Drake215fe2f1999-02-02 19:02:35 +0000975Availability: Windows.
976\versionadded{1.5.2}
977\end{datadesc}
978
Fred Drake4ce4f2e2000-09-29 04:15:19 +0000979\begin{funcdesc}{startfile}{path}
980Start a file with its associated application. This acts like
981double-clicking the file in Windows Explorer, or giving the file name
982as an argument to the DOS \program{start} command: the file is opened
983with whatever application (if any) its extension is associated.
984
985\function{startfile()} returns as soon as the associated application
986is launched. There is no option to wait for the application to close,
987and no way to retrieve the application's exit status. The \var{path}
988parameter is relative to the current directory. If you want to use an
989absolute path, make sure the first character is not a slash
990(\character{/}); the underlying Win32 \cfunction{ShellExecute()}
991function doesn't work it is. Use the \function{os.path.normpath()}
992function to ensure that the path is properly encoded for Win32.
993Availability: Windows.
994\versionadded{2.0}
995\end{funcdesc}
996
Fred Drake215fe2f1999-02-02 19:02:35 +0000997\begin{funcdesc}{system}{command}
998Execute the command (a string) in a subshell. This is implemented by
999calling the Standard C function \cfunction{system()}, and has the
Fred Drakeec6baaf1999-04-21 18:13:31 +00001000same limitations. Changes to \code{posix.environ}, \code{sys.stdin},
Fred Drake215fe2f1999-02-02 19:02:35 +00001001etc.\ are not reflected in the environment of the executed command.
1002The return value is the exit status of the process encoded in the
Fred Drake7a621281999-06-10 15:07:05 +00001003format specified for \function{wait()}, except on Windows 95 and 98,
Fred Drakea88ef001999-06-18 19:11:25 +00001004where it is always \code{0}. Note that \POSIX{} does not specify the
1005meaning of the return value of the C \cfunction{system()} function,
1006so the return value of the Python function is system-dependent.
Fred Drake215fe2f1999-02-02 19:02:35 +00001007Availability: \UNIX{}, Windows.
1008\end{funcdesc}
1009
1010\begin{funcdesc}{times}{}
1011Return a 5-tuple of floating point numbers indicating accumulated (CPU
1012or other)
1013times, in seconds. The items are: user time, system time, children's
1014user time, children's system time, and elapsed real time since a fixed
Fred Drakeec6baaf1999-04-21 18:13:31 +00001015point in the past, in that order. See the \UNIX{} manual page
1016\manpage{times}{2} or the corresponding Windows Platform API
1017documentation.
Fred Drake215fe2f1999-02-02 19:02:35 +00001018Availability: \UNIX{}, Windows.
1019\end{funcdesc}
1020
1021\begin{funcdesc}{wait}{}
1022Wait for completion of a child process, and return a tuple containing
1023its pid and exit status indication: a 16-bit number, whose low byte is
1024the signal number that killed the process, and whose high byte is the
1025exit status (if the signal number is zero); the high bit of the low
1026byte is set if a core file was produced.
1027Availability: \UNIX{}.
1028\end{funcdesc}
1029
1030\begin{funcdesc}{waitpid}{pid, options}
Fred Drake31e5e371999-08-13 13:36:33 +00001031Wait for completion of a child process given by process id \var{pid},
1032and return a tuple containing its process id and exit status
1033indication (encoded as for \function{wait()}). The semantics of the
1034call are affected by the value of the integer \var{options}, which
1035should be \code{0} for normal operation.
Fred Drake215fe2f1999-02-02 19:02:35 +00001036Availability: \UNIX{}.
Fred Drake31e5e371999-08-13 13:36:33 +00001037
1038If \var{pid} is greater than \code{0}, \function{waitpid()} requests
1039status information for that specific process. If \var{pid} is
1040\code{0}, the request is for the status of any child in the process
1041group of the current process. If \var{pid} is \code{-1}, the request
1042pertains to any child of the current process. If \var{pid} is less
1043than \code{-1}, status is requested for any process in the process
1044group \code{-\var{pid}} (the absolute value of \var{pid}).
Fred Drake215fe2f1999-02-02 19:02:35 +00001045\end{funcdesc}
1046
1047\begin{datadesc}{WNOHANG}
1048The option for \function{waitpid()} to avoid hanging if no child
1049process status is available immediately.
1050Availability: \UNIX{}.
1051\end{datadesc}
1052
Fred Drake38e5d272000-04-03 20:13:55 +00001053The following functions take a process status code as returned by
1054\function{system()}, \function{wait()}, or \function{waitpid()} as a
1055parameter. They may be used to determine the disposition of a
1056process.
Fred Drake215fe2f1999-02-02 19:02:35 +00001057
1058\begin{funcdesc}{WIFSTOPPED}{status}
1059Return true if the process has been stopped.
1060Availability: \UNIX{}.
1061\end{funcdesc}
1062
1063\begin{funcdesc}{WIFSIGNALED}{status}
1064Return true if the process exited due to a signal.
1065Availability: \UNIX{}.
1066\end{funcdesc}
1067
1068\begin{funcdesc}{WIFEXITED}{status}
1069Return true if the process exited using the \manpage{exit}{2} system
1070call.
1071Availability: \UNIX{}.
1072\end{funcdesc}
1073
1074\begin{funcdesc}{WEXITSTATUS}{status}
1075If \code{WIFEXITED(\var{status})} is true, return the integer
1076parameter to the \manpage{exit}{2} system call. Otherwise, the return
1077value is meaningless.
1078Availability: \UNIX{}.
1079\end{funcdesc}
1080
1081\begin{funcdesc}{WSTOPSIG}{status}
Fred Drake35c3ffd1999-03-04 14:08:10 +00001082Return the signal which caused the process to stop.
1083Availability: \UNIX{}.
1084\end{funcdesc}
1085
1086\begin{funcdesc}{WTERMSIG}{status}
Fred Drake215fe2f1999-02-02 19:02:35 +00001087Return the signal which caused the process to exit.
1088Availability: \UNIX{}.
1089\end{funcdesc}
1090
1091
Thomas Woutersf8316632000-07-16 19:01:10 +00001092\subsection{Miscellaneous System Information \label{os-path}}
Fred Drake88f6ca21999-12-15 19:39:04 +00001093
1094
1095\begin{funcdesc}{confstr}{name}
1096Return string-valued system configuration values.
1097\var{name} specifies the configuration value to retrieve; it may be a
1098string which is the name of a defined system value; these names are
1099specified in a number of standards (\POSIX, Unix95, Unix98, and
1100others). Some platforms define additional names as well. The names
1101known to the host operating system are given in the
1102\code{confstr_names} dictionary. For configuration variables not
1103included in that mapping, passing an integer for \var{name} is also
1104accepted.
1105Availability: \UNIX{}.
1106
1107If the configuration value specified by \var{name} isn't defined, the
1108empty string is returned.
1109
1110If \var{name} is a string and is not known, \exception{ValueError} is
1111raised. If a specific value for \var{name} is not supported by the
1112host system, even if it is included in \code{confstr_names}, an
1113\exception{OSError} is raised with \constant{errno.EINVAL} for the
1114error number.
1115\end{funcdesc}
1116
1117\begin{datadesc}{confstr_names}
1118Dictionary mapping names accepted by \function{confstr()} to the
1119integer values defined for those names by the host operating system.
1120This can be used to determine the set of names known to the system.
1121Availability: \UNIX.
1122\end{datadesc}
1123
1124\begin{funcdesc}{sysconf}{name}
1125Return integer-valued system configuration values.
1126If the configuration value specified by \var{name} isn't defined,
1127\code{-1} is returned. The comments regarding the \var{name}
1128parameter for \function{confstr()} apply here as well; the dictionary
1129that provides information on the known names is given by
1130\code{sysconf_names}.
1131Availability: \UNIX{}.
1132\end{funcdesc}
1133
1134\begin{datadesc}{sysconf_names}
1135Dictionary mapping names accepted by \function{sysconf()} to the
1136integer values defined for those names by the host operating system.
1137This can be used to determine the set of names known to the system.
1138Availability: \UNIX.
1139\end{datadesc}
1140
Fred Drake215fe2f1999-02-02 19:02:35 +00001141
1142The follow data values are used to support path manipulation
1143operations. These are defined for all platforms.
1144
1145Higher-level operations on pathnames are defined in the
1146\refmodule{os.path} module.
1147
1148
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00001149\begin{datadesc}{curdir}
1150The constant string used by the OS to refer to the current directory,
Fred Drake1a3c2a01998-08-06 15:18:23 +00001151e.g.\ \code{'.'} for \POSIX{} or \code{':'} for the Macintosh.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00001152\end{datadesc}
1153
1154\begin{datadesc}{pardir}
1155The constant string used by the OS to refer to the parent directory,
Fred Drake1a3c2a01998-08-06 15:18:23 +00001156e.g.\ \code{'..'} for \POSIX{} or \code{'::'} for the Macintosh.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00001157\end{datadesc}
1158
1159\begin{datadesc}{sep}
Guido van Rossumb2afc811997-08-29 22:37:44 +00001160The character used by the OS to separate pathname components,
Fred Drake1a3c2a01998-08-06 15:18:23 +00001161e.g.\ \character{/} for \POSIX{} or \character{:} for the Macintosh.
1162Note that knowing this is not sufficient to be able to parse or
1163concatenate pathnames --- use \function{os.path.split()} and
1164\function{os.path.join()} --- but it is occasionally useful.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00001165\end{datadesc}
1166
Guido van Rossumb2afc811997-08-29 22:37:44 +00001167\begin{datadesc}{altsep}
1168An alternative character used by the OS to separate pathname components,
1169or \code{None} if only one separator character exists. This is set to
Fred Drake215fe2f1999-02-02 19:02:35 +00001170\character{/} on DOS and Windows systems where \code{sep} is a backslash.
Guido van Rossumb2afc811997-08-29 22:37:44 +00001171\end{datadesc}
1172
Guido van Rossum470be141995-03-17 16:07:09 +00001173\begin{datadesc}{pathsep}
1174The character conventionally used by the OS to separate search patch
Fred Drake1a3c2a01998-08-06 15:18:23 +00001175components (as in \envvar{PATH}), e.g.\ \character{:} for \POSIX{} or
Fred Drake215fe2f1999-02-02 19:02:35 +00001176\character{;} for DOS and Windows.
Guido van Rossum9c59ce91998-06-30 15:54:27 +00001177\end{datadesc}
1178
Guido van Rossum470be141995-03-17 16:07:09 +00001179\begin{datadesc}{defpath}
Fred Drake1a3c2a01998-08-06 15:18:23 +00001180The default search path used by \function{exec*p*()} if the environment
Guido van Rossum470be141995-03-17 16:07:09 +00001181doesn't have a \code{'PATH'} key.
1182\end{datadesc}
1183
Fred Drake215fe2f1999-02-02 19:02:35 +00001184\begin{datadesc}{linesep}
1185The string used to separate (or, rather, terminate) lines on the
Fred Drakeec6baaf1999-04-21 18:13:31 +00001186current platform. This may be a single character,
1187e.g.\ \code{'\e n'} for \POSIX{} or \code{'\e r'} for MacOS, or multiple
1188characters, e.g.\ \code{'\e r\e n'} for MS-DOS and MS Windows.
Fred Drake215fe2f1999-02-02 19:02:35 +00001189\end{datadesc}