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