blob: d17c9115ae943a9072b62b9ca76b8e71fb73a5bc [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 Drake2f979011999-06-11 18:28:37 +000070\code{'dos'}, \code{'mac'}, \code{'os2'}, \code{'ce'}.
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
89\begin{funcdesc}{chdir}{path}
Fred Drake859dc531999-07-01 13:54:40 +000090\index{directory!changing}
Fred Drake215fe2f1999-02-02 19:02:35 +000091Change the current working directory to \var{path}.
92Availability: Macintosh, \UNIX{}, Windows.
93\end{funcdesc}
94
95\begin{datadesc}{environ}
Fred Drake0e1de8b1999-04-29 12:57:32 +000096A mapping object representing the string environment. For example,
97\code{environ['HOME']} is the pathname of your home directory (on some
98platforms), and is equivalent to \code{getenv("HOME")} in C.
Fred Drake215fe2f1999-02-02 19:02:35 +000099
100If the platform supports the \function{putenv()} function, this
101mapping may be used to modify the environment as well as query the
102environment. \function{putenv()} will be called automatically when
103the mapping is modified.
104
105If \function{putenv()} is not provided, this mapping may be passed to
106the appropriate process-creation functions to cause child processes to
107use a modified environment.
108\end{datadesc}
109
110\begin{funcdesc}{getcwd}{}
111Return a string representing the current working directory.
112Availability: Macintosh, \UNIX{}, Windows.
113\end{funcdesc}
114
115\begin{funcdesc}{getegid}{}
116Return the current process' effective group id.
117Availability: \UNIX{}.
118\end{funcdesc}
119
120\begin{funcdesc}{geteuid}{}
Fred Drake6b330ba81999-05-25 13:42:26 +0000121\index{user!effective id}
Fred Drake215fe2f1999-02-02 19:02:35 +0000122Return the current process' effective user id.
123Availability: \UNIX{}.
124\end{funcdesc}
125
126\begin{funcdesc}{getgid}{}
Fred Drake6b330ba81999-05-25 13:42:26 +0000127\index{process!group}
Fred Drake215fe2f1999-02-02 19:02:35 +0000128Return the current process' group id.
129Availability: \UNIX{}.
130\end{funcdesc}
131
132\begin{funcdesc}{getpgrp}{}
133\index{process!group}
134Return the current process group id.
135Availability: \UNIX{}.
136\end{funcdesc}
137
138\begin{funcdesc}{getpid}{}
139\index{process!id}
140Return the current process id.
141Availability: \UNIX{}, Windows.
142\end{funcdesc}
143
144\begin{funcdesc}{getppid}{}
145\index{process!id of parent}
146Return the parent's process id.
147Availability: \UNIX{}.
148\end{funcdesc}
149
150\begin{funcdesc}{getuid}{}
Fred Drake6b330ba81999-05-25 13:42:26 +0000151\index{user!id}
Fred Drake215fe2f1999-02-02 19:02:35 +0000152Return the current process' user id.
153Availability: \UNIX{}.
154\end{funcdesc}
155
156\begin{funcdesc}{putenv}{varname, value}
157\index{environment variables!setting}
158Set the environment variable named \var{varname} to the string
159\var{value}. Such changes to the environment affect subprocesses
160started with \function{os.system()}, \function{popen()} or
161\function{fork()} and \function{execv()}.
162Availability: most flavors of \UNIX{}, Windows.
163
164When \function{putenv()} is
165supported, assignments to items in \code{os.environ} are automatically
166translated into corresponding calls to \function{putenv()}; however,
167calls to \function{putenv()} don't update \code{os.environ}, so it is
168actually preferable to assign to items of \code{os.environ}.
169\end{funcdesc}
170
171\begin{funcdesc}{setgid}{gid}
172Set the current process' group id.
173Availability: \UNIX{}.
174\end{funcdesc}
175
176\begin{funcdesc}{setpgrp}{}
177Calls the system call \cfunction{setpgrp()} or \cfunction{setpgrp(0,
1780)} depending on which version is implemented (if any). See the
179\UNIX{} manual for the semantics.
180Availability: \UNIX{}.
181\end{funcdesc}
182
183\begin{funcdesc}{setpgid}{pid, pgrp}
184Calls the system call \cfunction{setpgid()}. See the \UNIX{} manual
185for the semantics.
186Availability: \UNIX{}.
187\end{funcdesc}
188
189\begin{funcdesc}{setsid}{}
190Calls the system call \cfunction{setsid()}. See the \UNIX{} manual
191for the semantics.
192Availability: \UNIX{}.
193\end{funcdesc}
194
195\begin{funcdesc}{setuid}{uid}
Fred Drake6b330ba81999-05-25 13:42:26 +0000196\index{user!id, setting}
Fred Drake215fe2f1999-02-02 19:02:35 +0000197Set the current process' user id.
198Availability: \UNIX{}.
199\end{funcdesc}
200
201% placed in this section since it relates to errno.... a little weak ;-(
202\begin{funcdesc}{strerror}{code}
203Return the error message corresponding to the error code in
204\var{code}.
205Availability: \UNIX{}, Windows.
206\end{funcdesc}
207
208\begin{funcdesc}{umask}{mask}
209Set the current numeric umask and returns the previous umask.
210Availability: \UNIX{}, Windows.
211\end{funcdesc}
212
213\begin{funcdesc}{uname}{}
214Return a 5-tuple containing information identifying the current
215operating system. The tuple contains 5 strings:
216\code{(\var{sysname}, \var{nodename}, \var{release}, \var{version},
217\var{machine})}. Some systems truncate the nodename to 8
218characters or to the leading component; a better way to get the
219hostname is \function{socket.gethostname()}
220\withsubitem{(in module socket)}{\ttindex{gethostname()}}
221or even
222\withsubitem{(in module socket)}{\ttindex{gethostbyaddr()}}
223\code{socket.gethostbyaddr(socket.gethostname())}.
224Availability: recent flavors of \UNIX{}.
225\end{funcdesc}
226
227
228
229\subsection{File Object Creation \label{os-newstreams}}
230
231These functions create new file objects.
232
233
234\begin{funcdesc}{fdopen}{fd\optional{, mode\optional{, bufsize}}}
235Return an open file object connected to the file descriptor \var{fd}.
236The \var{mode} and \var{bufsize} arguments have the same meaning as
237the corresponding arguments to the built-in \function{open()}
238function.
239Availability: Macintosh, \UNIX{}, Windows.
240\end{funcdesc}
241
242\begin{funcdesc}{popen}{command\optional{, mode\optional{, bufsize}}}
243Open a pipe to or from \var{command}. The return value is an open
244file object connected to the pipe, which can be read or written
245depending on whether \var{mode} is \code{'r'} (default) or \code{'w'}.
246The \var{bufsize} argument has the same meaning as the corresponding
247argument to the built-in \function{open()} function. The exit status of
248the command (encoded in the format specified for \function{wait()}) is
249available as the return value of the \method{close()} method of the file
250object, except that when the exit status is zero (termination without
251errors), \code{None} is returned.
252Availability: \UNIX{}, Windows.
253\end{funcdesc}
254
255
256
257\subsection{File Descriptor Operations \label{os-fd-ops}}
258
259These functions operate on I/O streams referred to
260using file descriptors.
261
262
263\begin{funcdesc}{close}{fd}
264Close file descriptor \var{fd}.
265Availability: Macintosh, \UNIX{}, Windows.
266
267Note: this function is intended for low-level I/O and must be applied
268to a file descriptor as returned by \function{open()} or
269\function{pipe()}. To close a ``file object'' returned by the
270built-in function \function{open()} or by \function{popen()} or
271\function{fdopen()}, use its \method{close()} method.
272\end{funcdesc}
273
274\begin{funcdesc}{dup}{fd}
275Return a duplicate of file descriptor \var{fd}.
276Availability: Macintosh, \UNIX{}, Windows.
277\end{funcdesc}
278
279\begin{funcdesc}{dup2}{fd, fd2}
280Duplicate file descriptor \var{fd} to \var{fd2}, closing the latter
281first if necessary.
282Availability: \UNIX{}, Windows.
283\end{funcdesc}
284
285\begin{funcdesc}{fstat}{fd}
286Return status for file descriptor \var{fd}, like \function{stat()}.
287Availability: \UNIX{}, Windows.
288\end{funcdesc}
289
290\begin{funcdesc}{fstatvfs}{fd}
291Return information about the filesystem containing the file associated
292with file descriptor \var{fd}, like \function{statvfs()}.
293Availability: \UNIX{}.
294\end{funcdesc}
295
296\begin{funcdesc}{ftruncate}{fd, length}
297Truncate the file corresponding to file descriptor \var{fd},
298so that it is at most \var{length} bytes in size.
299Availability: \UNIX{}.
300\end{funcdesc}
301
302\begin{funcdesc}{lseek}{fd, pos, how}
303Set the current position of file descriptor \var{fd} to position
304\var{pos}, modified by \var{how}: \code{0} to set the position
305relative to the beginning of the file; \code{1} to set it relative to
306the current position; \code{2} to set it relative to the end of the
307file.
308Availability: Macintosh, \UNIX{}, Windows.
309\end{funcdesc}
310
311\begin{funcdesc}{open}{file, flags\optional{, mode}}
312Open the file \var{file} and set various flags according to
313\var{flags} and possibly its mode according to \var{mode}.
314The default \var{mode} is \code{0777} (octal), and the current umask
315value is first masked out. Return the file descriptor for the newly
316opened file.
317Availability: Macintosh, \UNIX{}, Windows.
318
319For a description of the flag and mode values, see the C run-time
320documentation; flag constants (like \constant{O_RDONLY} and
321\constant{O_WRONLY}) are defined in this module too (see below).
322
323Note: this function is intended for low-level I/O. For normal usage,
324use the built-in function \function{open()}, which returns a ``file
325object'' with \method{read()} and \method{write()} methods (and many
326more).
327\end{funcdesc}
328
329\begin{funcdesc}{pipe}{}
330Create a pipe. Return a pair of file descriptors \code{(\var{r},
331\var{w})} usable for reading and writing, respectively.
332Availability: \UNIX{}, Windows.
333\end{funcdesc}
334
335\begin{funcdesc}{read}{fd, n}
336Read at most \var{n} bytes from file descriptor \var{fd}.
337Return a string containing the bytes read.
338Availability: Macintosh, \UNIX{}, Windows.
339
340Note: this function is intended for low-level I/O and must be applied
341to a file descriptor as returned by \function{open()} or
342\function{pipe()}. To read a ``file object'' returned by the
343built-in function \function{open()} or by \function{popen()} or
344\function{fdopen()}, or \code{sys.stdin}, use its
345\method{read()} or \method{readline()} methods.
346\end{funcdesc}
347
348\begin{funcdesc}{tcgetpgrp}{fd}
349Return the process group associated with the terminal given by
350\var{fd} (an open file descriptor as returned by \function{open()}).
351Availability: \UNIX{}.
352\end{funcdesc}
353
354\begin{funcdesc}{tcsetpgrp}{fd, pg}
355Set the process group associated with the terminal given by
356\var{fd} (an open file descriptor as returned by \function{open()})
357to \var{pg}.
358Availability: \UNIX{}.
359\end{funcdesc}
360
361\begin{funcdesc}{ttyname}{fd}
362Return a string which specifies the terminal device associated with
363file-descriptor \var{fd}. If \var{fd} is not associated with a terminal
364device, an exception is raised.
365Availability: \UNIX{}.
366\end{funcdesc}
367
368\begin{funcdesc}{write}{fd, str}
369Write the string \var{str} to file descriptor \var{fd}.
370Return the number of bytes actually written.
371Availability: Macintosh, \UNIX{}, Windows.
372
373Note: this function is intended for low-level I/O and must be applied
374to a file descriptor as returned by \function{open()} or
375\function{pipe()}. To write a ``file object'' returned by the
376built-in function \function{open()} or by \function{popen()} or
377\function{fdopen()}, or \code{sys.stdout} or \code{sys.stderr}, use
378its \method{write()} method.
379\end{funcdesc}
380
381
382The following data items are available for use in constructing the
383\var{flags} parameter to the \function{open()} function.
384
385\begin{datadesc}{O_RDONLY}
386\dataline{O_WRONLY}
387\dataline{O_RDWR}
388\dataline{O_NDELAY}
389\dataline{O_NONBLOCK}
390\dataline{O_APPEND}
391\dataline{O_DSYNC}
392\dataline{O_RSYNC}
393\dataline{O_SYNC}
394\dataline{O_NOCTTY}
395\dataline{O_CREAT}
396\dataline{O_EXCL}
397\dataline{O_TRUNC}
398Options for the \var{flag} argument to the \function{open()} function.
399These can be bit-wise OR'd together.
400Availability: Macintosh, \UNIX{}, Windows.
401\end{datadesc}
402
403
404\subsection{Files and Directories \label{os-file-dir}}
405
406\begin{funcdesc}{access}{path, mode}
407Check read/write/execute permissions for this process or extance of file
408\var{path}. Return \code{1} if access is granted, \code{0} if not.
409See the \UNIX{} manual for the semantics.
410Availability: \UNIX{}.
411\end{funcdesc}
412
413\begin{funcdesc}{chmod}{path, mode}
414Change the mode of \var{path} to the numeric \var{mode}.
415Availability: \UNIX{}, Windows.
416\end{funcdesc}
417
418\begin{funcdesc}{chown}{path, uid, gid}
419Change the owner and group id of \var{path} to the numeric \var{uid}
420and \var{gid}.
421Availability: \UNIX{}.
422\end{funcdesc}
423
424\begin{funcdesc}{link}{src, dst}
425Create a hard link pointing to \var{src} named \var{dst}.
426Availability: \UNIX{}.
427\end{funcdesc}
428
429\begin{funcdesc}{listdir}{path}
430Return a list containing the names of the entries in the directory.
431The list is in arbitrary order. It does not include the special
432entries \code{'.'} and \code{'..'} even if they are present in the
433directory.
434Availability: Macintosh, \UNIX{}, Windows.
435\end{funcdesc}
436
437\begin{funcdesc}{lstat}{path}
438Like \function{stat()}, but do not follow symbolic links.
439Availability: \UNIX{}.
440\end{funcdesc}
441
442\begin{funcdesc}{mkfifo}{path\optional{, mode}}
443Create a FIFO (a named pipe) named \var{path} with numeric mode
444\var{mode}. The default \var{mode} is \code{0666} (octal). The current
445umask value is first masked out from the mode.
446Availability: \UNIX{}.
447
448FIFOs are pipes that can be accessed like regular files. FIFOs exist
449until they are deleted (for example with \function{os.unlink()}).
450Generally, FIFOs are used as rendezvous between ``client'' and
451``server'' type processes: the server opens the FIFO for reading, and
452the client opens it for writing. Note that \function{mkfifo()}
453doesn't open the FIFO --- it just creates the rendezvous point.
454\end{funcdesc}
455
456\begin{funcdesc}{mkdir}{path\optional{, mode}}
457Create a directory named \var{path} with numeric mode \var{mode}.
458The default \var{mode} is \code{0777} (octal). On some systems,
459\var{mode} is ignored. Where it is used, the current umask value is
460first masked out.
461Availability: Macintosh, \UNIX{}, Windows.
462\end{funcdesc}
463
464\begin{funcdesc}{makedirs}{path\optional{, mode}}
465\index{directory!creating}
466Recursive directory creation function. Like \function{mkdir()},
467but makes all intermediate-level directories needed to contain the
468leaf directory. Throws an \exception{error} exception if the leaf
469directory already exists or cannot be created. The default \var{mode}
470is \code{0777} (octal).
471\versionadded{1.5.2}
472\end{funcdesc}
473
474\begin{funcdesc}{readlink}{path}
475Return a string representing the path to which the symbolic link
476points.
477Availability: \UNIX{}.
478\end{funcdesc}
479
480\begin{funcdesc}{remove}{path}
481Remove the file \var{path}. See \function{rmdir()} below to remove a
482directory. This is identical to the \function{unlink()} function
483documented below.
484Availability: Macintosh, \UNIX{}, Windows.
485\end{funcdesc}
486
487\begin{funcdesc}{removedirs}{path}
488\index{directory!deleting}
489Recursive directory removal function. Works like
490\function{rmdir()} except that, if the leaf directory is
491successfully removed, directories corresponding to rightmost path
492segments will be pruned way until either the whole path is consumed or
493an error is raised (which is ignored, because it generally means that
494a parent directory is not empty). Throws an \exception{error}
495exception if the leaf directory could not be successfully removed.
496\versionadded{1.5.2}
497\end{funcdesc}
498
499\begin{funcdesc}{rename}{src, dst}
500Rename the file or directory \var{src} to \var{dst}.
501Availability: Macintosh, \UNIX{}, Windows.
502\end{funcdesc}
503
504\begin{funcdesc}{renames}{old, new}
505Recursive directory or file renaming function.
506Works like \function{rename()}, except creation of any intermediate
507directories needed to make the new pathname good is attempted first.
508After the rename, directories corresponding to rightmost path segments
509of the old name will be pruned away using \function{removedirs()}.
510
511Note: this function can fail with the new directory structure made if
512you lack permissions needed to remove the leaf directory or file.
513\versionadded{1.5.2}
514\end{funcdesc}
515
516\begin{funcdesc}{rmdir}{path}
517Remove the directory \var{path}.
518Availability: Macintosh, \UNIX{}, Windows.
519\end{funcdesc}
520
521\begin{funcdesc}{stat}{path}
522Perform a \cfunction{stat()} system call on the given path. The
523return value is a tuple of at least 10 integers giving the most
524important (and portable) members of the \emph{stat} structure, in the
525order
526\code{st_mode},
527\code{st_ino},
528\code{st_dev},
529\code{st_nlink},
530\code{st_uid},
531\code{st_gid},
532\code{st_size},
533\code{st_atime},
534\code{st_mtime},
535\code{st_ctime}.
536More items may be added at the end by some implementations.
537(On MS Windows, some items are filled with dummy values.)
538Availability: Macintosh, \UNIX{}, Windows.
539
540Note: The standard module \refmodule{stat}\refstmodindex{stat} defines
541functions and constants that are useful for extracting information
542from a \ctype{stat} structure.
543\end{funcdesc}
544
545\begin{funcdesc}{statvfs}{path}
546Perform a \cfunction{statvfs()} system call on the given path. The
Guido van Rossum0c9608c1999-02-03 16:32:37 +0000547return value is a tuple of 10 integers giving the most common
Fred Drake215fe2f1999-02-02 19:02:35 +0000548members of the \ctype{statvfs} structure, in the order
549\code{f_bsize},
550\code{f_frsize},
551\code{f_blocks},
552\code{f_bfree},
553\code{f_bavail},
554\code{f_files},
555\code{f_ffree},
556\code{f_favail},
Fred Drake215fe2f1999-02-02 19:02:35 +0000557\code{f_flag},
558\code{f_namemax}.
559Availability: \UNIX{}.
560
561Note: The standard module \module{statvfs}\refstmodindex{statvfs}
562defines constants that are useful for extracting information
563from a \ctype{statvfs} structure.
564\end{funcdesc}
565
566\begin{funcdesc}{symlink}{src, dst}
567Create a symbolic link pointing to \var{src} named \var{dst}.
568Availability: \UNIX{}.
569\end{funcdesc}
570
571\begin{funcdesc}{unlink}{path}
572Remove the file \var{path}. This is the same function as
573\function{remove()}; the \function{unlink()} name is its traditional
574\UNIX{} name.
575Availability: Macintosh, \UNIX{}, Windows.
576\end{funcdesc}
577
578\begin{funcdesc}{utime}{path, (atime, mtime)}
579Set the access and modified time of the file to the given values.
580(The second argument is a tuple of two items.)
581Availability: Macintosh, \UNIX{}, Windows.
582\end{funcdesc}
583
584
585\subsection{Process Management \label{os-process}}
586
587These functions may be used to create and manage additional
588processes.
589
590
591\begin{funcdesc}{execl}{path, arg0, arg1, ...}
592This is equivalent to
593\samp{execv(\var{path}, (\var{arg0}, \var{arg1}, ...))}.
594Availability: \UNIX{}, Windows.
595\end{funcdesc}
596
597\begin{funcdesc}{execle}{path, arg0, arg1, ..., env}
598This is equivalent to
599\samp{execve(\var{path}, (\var{arg0}, \var{arg1}, ...), \var{env})}.
600Availability: \UNIX{}, Windows.
601\end{funcdesc}
602
603\begin{funcdesc}{execlp}{path, arg0, arg1, ...}
604This is equivalent to
605\samp{execvp(\var{path}, (\var{arg0}, \var{arg1}, ...))}.
606Availability: \UNIX{}, Windows.
607\end{funcdesc}
608
609\begin{funcdesc}{execv}{path, args}
610Execute the executable \var{path} with argument list \var{args},
611replacing the current process (i.e., the Python interpreter).
612The argument list may be a tuple or list of strings.
613Availability: \UNIX{}, Windows.
614\end{funcdesc}
615
616\begin{funcdesc}{execve}{path, args, env}
617Execute the executable \var{path} with argument list \var{args},
618and environment \var{env},
619replacing the current process (i.e., the Python interpreter).
620The argument list may be a tuple or list of strings.
621The environment must be a dictionary mapping strings to strings.
622Availability: \UNIX{}, Windows.
623\end{funcdesc}
624
625\begin{funcdesc}{execvp}{path, args}
626This is like \samp{execv(\var{path}, \var{args})} but duplicates
627the shell's actions in searching for an executable file in a list of
628directories. The directory list is obtained from
629\code{environ['PATH']}.
630Availability: \UNIX{}, Windows.
631\end{funcdesc}
632
633\begin{funcdesc}{execvpe}{path, args, env}
634This is a cross between \function{execve()} and \function{execvp()}.
635The directory list is obtained from \code{\var{env}['PATH']}.
636Availability: \UNIX{}, Windows.
637\end{funcdesc}
638
639\begin{funcdesc}{_exit}{n}
640Exit to the system with status \var{n}, without calling cleanup
641handlers, flushing stdio buffers, etc.
642Availability: \UNIX{}, Windows.
643
644Note: the standard way to exit is \code{sys.exit(\var{n})}.
645\function{_exit()} should normally only be used in the child process
646after a \function{fork()}.
647\end{funcdesc}
648
649\begin{funcdesc}{fork}{}
650Fork a child process. Return \code{0} in the child, the child's
651process id in the parent.
652Availability: \UNIX{}.
653\end{funcdesc}
654
655\begin{funcdesc}{kill}{pid, sig}
656\index{process!killing}
657\index{process!signalling}
658Kill the process \var{pid} with signal \var{sig}.
659Availability: \UNIX{}.
660\end{funcdesc}
661
662\begin{funcdesc}{nice}{increment}
663Add \var{increment} to the process's ``niceness''. Return the new
664niceness.
665Availability: \UNIX{}.
666\end{funcdesc}
667
668\begin{funcdesc}{plock}{op}
669Lock program segments into memory. The value of \var{op}
670(defined in \code{<sys/lock.h>}) determines which segments are locked.
Fred Drake39063631999-02-26 14:05:02 +0000671Availability: \UNIX{}.
Fred Drake215fe2f1999-02-02 19:02:35 +0000672\end{funcdesc}
673
674\begin{funcdesc}{spawnv}{mode, path, args}
675Execute the program \var{path} in a new process, passing the arguments
676specified in \var{args} as command-line parameters. \var{args} may be
677a list or a tuple. \var{mode} is a magic operational constant. See
678the Visual \Cpp{} Runtime Library documentation for further
679information.
680Availability: Windows.
681\versionadded{1.5.2}
682\end{funcdesc}
683
684\begin{funcdesc}{spawnve}{mode, path, args, env}
685Execute the program \var{path} in a new process, passing the arguments
686specified in \var{args} as command-line parameters and the contents of
687the mapping \var{env} as the environment. \var{args} may be a list or
688a tuple. \var{mode} is a magic operational constant. See the Visual
689\Cpp{} Runtime Library documentation for further information.
690Availability: Windows.
691\versionadded{1.5.2}
692\end{funcdesc}
693
Fred Drake9329e5e1999-02-16 19:40:19 +0000694\begin{datadesc}{P_WAIT}
695\dataline{P_NOWAIT}
696\dataline{P_NOWAITO}
697\dataline{P_OVERLAY}
698\dataline{P_DETACH}
Fred Drake215fe2f1999-02-02 19:02:35 +0000699Possible values for the \var{mode} parameter to \function{spawnv()}
700and \function{spawnve()}.
701Availability: Windows.
702\versionadded{1.5.2}
703\end{datadesc}
704
705\begin{funcdesc}{system}{command}
706Execute the command (a string) in a subshell. This is implemented by
707calling the Standard C function \cfunction{system()}, and has the
Fred Drakeec6baaf1999-04-21 18:13:31 +0000708same limitations. Changes to \code{posix.environ}, \code{sys.stdin},
Fred Drake215fe2f1999-02-02 19:02:35 +0000709etc.\ are not reflected in the environment of the executed command.
710The return value is the exit status of the process encoded in the
Fred Drake7a621281999-06-10 15:07:05 +0000711format specified for \function{wait()}, except on Windows 95 and 98,
Fred Drakea88ef001999-06-18 19:11:25 +0000712where it is always \code{0}. Note that \POSIX{} does not specify the
713meaning of the return value of the C \cfunction{system()} function,
714so the return value of the Python function is system-dependent.
Fred Drake215fe2f1999-02-02 19:02:35 +0000715Availability: \UNIX{}, Windows.
716\end{funcdesc}
717
718\begin{funcdesc}{times}{}
719Return a 5-tuple of floating point numbers indicating accumulated (CPU
720or other)
721times, in seconds. The items are: user time, system time, children's
722user time, children's system time, and elapsed real time since a fixed
Fred Drakeec6baaf1999-04-21 18:13:31 +0000723point in the past, in that order. See the \UNIX{} manual page
724\manpage{times}{2} or the corresponding Windows Platform API
725documentation.
Fred Drake215fe2f1999-02-02 19:02:35 +0000726Availability: \UNIX{}, Windows.
727\end{funcdesc}
728
729\begin{funcdesc}{wait}{}
730Wait for completion of a child process, and return a tuple containing
731its pid and exit status indication: a 16-bit number, whose low byte is
732the signal number that killed the process, and whose high byte is the
733exit status (if the signal number is zero); the high bit of the low
734byte is set if a core file was produced.
735Availability: \UNIX{}.
736\end{funcdesc}
737
738\begin{funcdesc}{waitpid}{pid, options}
Fred Drake6b330ba81999-05-25 13:42:26 +0000739Wait for completion of a child process given by process id, and return
Fred Drake215fe2f1999-02-02 19:02:35 +0000740a tuple containing its process id and exit status indication (encoded
741as for \function{wait()}). The semantics of the call are affected by
742the value of the integer \var{options}, which should be \code{0} for
743normal operation.
744Availability: \UNIX{}.
745\end{funcdesc}
746
747\begin{datadesc}{WNOHANG}
748The option for \function{waitpid()} to avoid hanging if no child
749process status is available immediately.
750Availability: \UNIX{}.
751\end{datadesc}
752
753The following functions take a process stats code as returned by
754\function{waitpid()} as a parameter. They may be used to determine
755the disposition of a process.
756
757\begin{funcdesc}{WIFSTOPPED}{status}
758Return true if the process has been stopped.
759Availability: \UNIX{}.
760\end{funcdesc}
761
762\begin{funcdesc}{WIFSIGNALED}{status}
763Return true if the process exited due to a signal.
764Availability: \UNIX{}.
765\end{funcdesc}
766
767\begin{funcdesc}{WIFEXITED}{status}
768Return true if the process exited using the \manpage{exit}{2} system
769call.
770Availability: \UNIX{}.
771\end{funcdesc}
772
773\begin{funcdesc}{WEXITSTATUS}{status}
774If \code{WIFEXITED(\var{status})} is true, return the integer
775parameter to the \manpage{exit}{2} system call. Otherwise, the return
776value is meaningless.
777Availability: \UNIX{}.
778\end{funcdesc}
779
780\begin{funcdesc}{WSTOPSIG}{status}
Fred Drake35c3ffd1999-03-04 14:08:10 +0000781Return the signal which caused the process to stop.
782Availability: \UNIX{}.
783\end{funcdesc}
784
785\begin{funcdesc}{WTERMSIG}{status}
Fred Drake215fe2f1999-02-02 19:02:35 +0000786Return the signal which caused the process to exit.
787Availability: \UNIX{}.
788\end{funcdesc}
789
790
791\subsection{Miscellanenous System Data \label{os-path}}
792
793The follow data values are used to support path manipulation
794operations. These are defined for all platforms.
795
796Higher-level operations on pathnames are defined in the
797\refmodule{os.path} module.
798
799
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000800\begin{datadesc}{curdir}
801The constant string used by the OS to refer to the current directory,
Fred Drake1a3c2a01998-08-06 15:18:23 +0000802e.g.\ \code{'.'} for \POSIX{} or \code{':'} for the Macintosh.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000803\end{datadesc}
804
805\begin{datadesc}{pardir}
806The constant string used by the OS to refer to the parent directory,
Fred Drake1a3c2a01998-08-06 15:18:23 +0000807e.g.\ \code{'..'} for \POSIX{} or \code{'::'} for the Macintosh.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000808\end{datadesc}
809
810\begin{datadesc}{sep}
Guido van Rossumb2afc811997-08-29 22:37:44 +0000811The character used by the OS to separate pathname components,
Fred Drake1a3c2a01998-08-06 15:18:23 +0000812e.g.\ \character{/} for \POSIX{} or \character{:} for the Macintosh.
813Note that knowing this is not sufficient to be able to parse or
814concatenate pathnames --- use \function{os.path.split()} and
815\function{os.path.join()} --- but it is occasionally useful.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000816\end{datadesc}
817
Guido van Rossumb2afc811997-08-29 22:37:44 +0000818\begin{datadesc}{altsep}
819An alternative character used by the OS to separate pathname components,
820or \code{None} if only one separator character exists. This is set to
Fred Drake215fe2f1999-02-02 19:02:35 +0000821\character{/} on DOS and Windows systems where \code{sep} is a backslash.
Guido van Rossumb2afc811997-08-29 22:37:44 +0000822\end{datadesc}
823
Guido van Rossum470be141995-03-17 16:07:09 +0000824\begin{datadesc}{pathsep}
825The character conventionally used by the OS to separate search patch
Fred Drake1a3c2a01998-08-06 15:18:23 +0000826components (as in \envvar{PATH}), e.g.\ \character{:} for \POSIX{} or
Fred Drake215fe2f1999-02-02 19:02:35 +0000827\character{;} for DOS and Windows.
Guido van Rossum9c59ce91998-06-30 15:54:27 +0000828\end{datadesc}
829
Guido van Rossum470be141995-03-17 16:07:09 +0000830\begin{datadesc}{defpath}
Fred Drake1a3c2a01998-08-06 15:18:23 +0000831The default search path used by \function{exec*p*()} if the environment
Guido van Rossum470be141995-03-17 16:07:09 +0000832doesn't have a \code{'PATH'} key.
833\end{datadesc}
834
Fred Drake215fe2f1999-02-02 19:02:35 +0000835\begin{datadesc}{linesep}
836The string used to separate (or, rather, terminate) lines on the
Fred Drakeec6baaf1999-04-21 18:13:31 +0000837current platform. This may be a single character,
838e.g.\ \code{'\e n'} for \POSIX{} or \code{'\e r'} for MacOS, or multiple
839characters, e.g.\ \code{'\e r\e n'} for MS-DOS and MS Windows.
Fred Drake215fe2f1999-02-02 19:02:35 +0000840\end{datadesc}