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