Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / v9 / html / python / lib / os-process.html
CommitLineData
920dae64
AT
1<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
2<html>
3<head>
4<link rel="STYLESHEET" href="lib.css" type='text/css' />
5<link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" />
6<link rel='start' href='../index.html' title='Python Documentation Index' />
7<link rel="first" href="lib.html" title='Python Library Reference' />
8<link rel='contents' href='contents.html' title="Contents" />
9<link rel='index' href='genindex.html' title='Index' />
10<link rel='last' href='about.html' title='About this document...' />
11<link rel='help' href='about.html' title='About this document...' />
12<link rel="next" href="os-path.html" />
13<link rel="prev" href="os-file-dir.html" />
14<link rel="parent" href="module-os.html" />
15<link rel="next" href="os-path.html" />
16<meta name='aesop' content='information' />
17<title>6.1.5 Process Management </title>
18</head>
19<body>
20<DIV CLASS="navigation">
21<div id='top-navigation-panel' xml:id='top-navigation-panel'>
22<table align="center" width="100%" cellpadding="0" cellspacing="2">
23<tr>
24<td class='online-navigation'><a rel="prev" title="6.1.4 Files and Directories"
25 href="os-file-dir.html"><img src='../icons/previous.png'
26 border='0' height='32' alt='Previous Page' width='32' /></A></td>
27<td class='online-navigation'><a rel="parent" title="6.1 os "
28 href="module-os.html"><img src='../icons/up.png'
29 border='0' height='32' alt='Up One Level' width='32' /></A></td>
30<td class='online-navigation'><a rel="next" title="6.1.6 Miscellaneous System Information"
31 href="os-path.html"><img src='../icons/next.png'
32 border='0' height='32' alt='Next Page' width='32' /></A></td>
33<td align="center" width="100%">Python Library Reference</td>
34<td class='online-navigation'><a rel="contents" title="Table of Contents"
35 href="contents.html"><img src='../icons/contents.png'
36 border='0' height='32' alt='Contents' width='32' /></A></td>
37<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
38 border='0' height='32' alt='Module Index' width='32' /></a></td>
39<td class='online-navigation'><a rel="index" title="Index"
40 href="genindex.html"><img src='../icons/index.png'
41 border='0' height='32' alt='Index' width='32' /></A></td>
42</tr></table>
43<div class='online-navigation'>
44<b class="navlabel">Previous:</b>
45<a class="sectref" rel="prev" href="os-file-dir.html">6.1.4 Files and Directories</A>
46<b class="navlabel">Up:</b>
47<a class="sectref" rel="parent" href="module-os.html">6.1 os </A>
48<b class="navlabel">Next:</b>
49<a class="sectref" rel="next" href="os-path.html">6.1.6 Miscellaneous System Information</A>
50</div>
51<hr /></div>
52</DIV>
53<!--End of Navigation Panel-->
54
55<H2><A NAME="SECTION008150000000000000000"></A><A NAME="os-process"></A>
56<BR>
576.1.5 Process Management
58</H2>
59
60<P>
61These functions may be used to create and manage processes.
62
63<P>
64The various <tt class="function">exec*()</tt> functions take a list of arguments for
65the new program loaded into the process. In each case, the first of
66these arguments is passed to the new program as its own name rather
67than as an argument a user may have typed on a command line. For the
68C programmer, this is the <code>argv[0]</code> passed to a program's
69<tt class="cfunction">main()</tt>. For example, "<tt class="samp">os.execv('/bin/echo', ['foo',
70'bar'])</tt>" will only print "<tt class="samp">bar</tt>" on standard output; "<tt class="samp">foo</tt>"will seem to be ignored.
71
72<P>
73<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
74 <td><nobr><b><tt id='l2h-1647' xml:id='l2h-1647' class="function">abort</tt></b>(</nobr></td>
75 <td><var></var>)</td></tr></table></dt>
76<dd>
77Generate a <tt class="constant">SIGABRT</tt> signal to the current process. On
78<span class="Unix">Unix</span>, the default behavior is to produce a core dump; on Windows, the
79process immediately returns an exit code of <code>3</code>. Be aware that
80programs which use <tt class="function">signal.signal()</tt> to register a handler
81for <tt class="constant">SIGABRT</tt> will behave differently.
82Availability: Macintosh, <span class="Unix">Unix</span>, Windows.
83</dl>
84
85<P>
86<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
87 <td><nobr><b><tt id='l2h-1648' xml:id='l2h-1648' class="function">execl</tt></b>(</nobr></td>
88 <td><var>path, arg0, arg1, ...</var>)</td></tr></table></dt>
89<dd>
90<dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
91 <td><nobr><b><tt class="function">execle</tt></b>(</nobr></td>
92 <td><var>path, arg0, arg1, ..., env</var>)</td></tr></table></dt>
93<dd><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
94 <td><nobr><b><tt class="function">execlp</tt></b>(</nobr></td>
95 <td><var>file, arg0, arg1, ...</var>)</td></tr></table></dt>
96<dd><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
97 <td><nobr><b><tt class="function">execlpe</tt></b>(</nobr></td>
98 <td><var>file, arg0, arg1, ..., env</var>)</td></tr></table></dt>
99<dd><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
100 <td><nobr><b><tt class="function">execv</tt></b>(</nobr></td>
101 <td><var>path, args</var>)</td></tr></table></dt>
102<dd><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
103 <td><nobr><b><tt class="function">execve</tt></b>(</nobr></td>
104 <td><var>path, args, env</var>)</td></tr></table></dt>
105<dd><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
106 <td><nobr><b><tt class="function">execvp</tt></b>(</nobr></td>
107 <td><var>file, args</var>)</td></tr></table></dt>
108<dd><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
109 <td><nobr><b><tt class="function">execvpe</tt></b>(</nobr></td>
110 <td><var>file, args, env</var>)</td></tr></table></dt>
111<dd>These functions all execute a new program, replacing the current
112process; they do not return. On <span class="Unix">Unix</span>, the new executable is loaded
113into the current process, and will have the same process ID as the
114caller. Errors will be reported as <tt class="exception">OSError</tt> exceptions.
115
116<P>
117The "<tt class="character">l</tt>" and "<tt class="character">v</tt>" variants of the
118<tt class="function">exec*()</tt> functions differ in how command-line arguments are
119passed. The "<tt class="character">l</tt>" variants are perhaps the easiest to work
120with if the number of parameters is fixed when the code is written;
121the individual parameters simply become additional parameters to the
122<tt class="function">execl*()</tt> functions. The "<tt class="character">v</tt>" variants are good
123when the number of parameters is variable, with the arguments being
124passed in a list or tuple as the <var>args</var> parameter. In either
125case, the arguments to the child process should start with the name of
126the command being run, but this is not enforced.
127
128<P>
129The variants which include a "<tt class="character">p</tt>" near the end
130(<tt class="function">execlp()</tt>, <tt class="function">execlpe()</tt>, <tt class="function">execvp()</tt>,
131and <tt class="function">execvpe()</tt>) will use the <a class="envvar" id='l2h-1707' xml:id='l2h-1707'>PATH</a> environment
132variable to locate the program <var>file</var>. When the environment is
133being replaced (using one of the <tt class="function">exec*e()</tt> variants,
134discussed in the next paragraph), the
135new environment is used as the source of the <a class="envvar" id='l2h-1708' xml:id='l2h-1708'>PATH</a> variable.
136The other variants, <tt class="function">execl()</tt>, <tt class="function">execle()</tt>,
137<tt class="function">execv()</tt>, and <tt class="function">execve()</tt>, will not use the
138<a class="envvar" id='l2h-1709' xml:id='l2h-1709'>PATH</a> variable to locate the executable; <var>path</var> must
139contain an appropriate absolute or relative path.
140
141<P>
142For <tt class="function">execle()</tt>, <tt class="function">execlpe()</tt>, <tt class="function">execve()</tt>,
143and <tt class="function">execvpe()</tt> (note that these all end in "<tt class="character">e</tt>"),
144the <var>env</var> parameter must be a mapping which is used to define the
145environment variables for the new process; the <tt class="function">execl()</tt>,
146<tt class="function">execlp()</tt>, <tt class="function">execv()</tt>, and <tt class="function">execvp()</tt>
147all cause the new process to inherit the environment of the current
148process.
149Availability: Macintosh, <span class="Unix">Unix</span>, Windows.
150</dl>
151
152<P>
153<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
154 <td><nobr><b><tt id='l2h-1656' xml:id='l2h-1656' class="function">_exit</tt></b>(</nobr></td>
155 <td><var>n</var>)</td></tr></table></dt>
156<dd>
157Exit to the system with status <var>n</var>, without calling cleanup
158handlers, flushing stdio buffers, etc.
159Availability: Macintosh, <span class="Unix">Unix</span>, Windows.
160
161<P>
162<div class="note"><b class="label">Note:</b>
163The standard way to exit is <code>sys.exit(<var>n</var>)</code>.
164<tt class="function">_exit()</tt> should normally only be used in the child process
165after a <tt class="function">fork()</tt>.
166</div>
167</dl>
168
169<P>
170The following exit codes are a defined, and can be used with
171<tt class="function">_exit()</tt>, although they are not required. These are
172typically used for system programs written in Python, such as a
173mail server's external command delivery program.
174<span class="note"><b class="label">Note:</b>
175Some of these may not be available on all <span class="Unix">Unix</span> platforms,
176since there is some variation. These constants are defined where they
177are defined by the underlying platform.</span>
178
179<P>
180<dl><dt><b><tt id='l2h-1657' xml:id='l2h-1657'>EX_OK</tt></b></dt>
181<dd>
182Exit code that means no error occurred.
183Availability: Macintosh, <span class="Unix">Unix</span>.
184
185<span class="versionnote">New in version 2.3.</span>
186
187</dd></dl>
188
189<P>
190<dl><dt><b><tt id='l2h-1658' xml:id='l2h-1658'>EX_USAGE</tt></b></dt>
191<dd>
192Exit code that means the command was used incorrectly, such as when
193the wrong number of arguments are given.
194Availability: Macintosh, <span class="Unix">Unix</span>.
195
196<span class="versionnote">New in version 2.3.</span>
197
198</dd></dl>
199
200<P>
201<dl><dt><b><tt id='l2h-1659' xml:id='l2h-1659'>EX_DATAERR</tt></b></dt>
202<dd>
203Exit code that means the input data was incorrect.
204Availability: Macintosh, <span class="Unix">Unix</span>.
205
206<span class="versionnote">New in version 2.3.</span>
207
208</dd></dl>
209
210<P>
211<dl><dt><b><tt id='l2h-1660' xml:id='l2h-1660'>EX_NOINPUT</tt></b></dt>
212<dd>
213Exit code that means an input file did not exist or was not readable.
214Availability: Macintosh, <span class="Unix">Unix</span>.
215
216<span class="versionnote">New in version 2.3.</span>
217
218</dd></dl>
219
220<P>
221<dl><dt><b><tt id='l2h-1661' xml:id='l2h-1661'>EX_NOUSER</tt></b></dt>
222<dd>
223Exit code that means a specified user did not exist.
224Availability: Macintosh, <span class="Unix">Unix</span>.
225
226<span class="versionnote">New in version 2.3.</span>
227
228</dd></dl>
229
230<P>
231<dl><dt><b><tt id='l2h-1662' xml:id='l2h-1662'>EX_NOHOST</tt></b></dt>
232<dd>
233Exit code that means a specified host did not exist.
234Availability: Macintosh, <span class="Unix">Unix</span>.
235
236<span class="versionnote">New in version 2.3.</span>
237
238</dd></dl>
239
240<P>
241<dl><dt><b><tt id='l2h-1663' xml:id='l2h-1663'>EX_UNAVAILABLE</tt></b></dt>
242<dd>
243Exit code that means that a required service is unavailable.
244Availability: Macintosh, <span class="Unix">Unix</span>.
245
246<span class="versionnote">New in version 2.3.</span>
247
248</dd></dl>
249
250<P>
251<dl><dt><b><tt id='l2h-1664' xml:id='l2h-1664'>EX_SOFTWARE</tt></b></dt>
252<dd>
253Exit code that means an internal software error was detected.
254Availability: Macintosh, <span class="Unix">Unix</span>.
255
256<span class="versionnote">New in version 2.3.</span>
257
258</dd></dl>
259
260<P>
261<dl><dt><b><tt id='l2h-1665' xml:id='l2h-1665'>EX_OSERR</tt></b></dt>
262<dd>
263Exit code that means an operating system error was detected, such as
264the inability to fork or create a pipe.
265Availability: Macintosh, <span class="Unix">Unix</span>.
266
267<span class="versionnote">New in version 2.3.</span>
268
269</dd></dl>
270
271<P>
272<dl><dt><b><tt id='l2h-1666' xml:id='l2h-1666'>EX_OSFILE</tt></b></dt>
273<dd>
274Exit code that means some system file did not exist, could not be
275opened, or had some other kind of error.
276Availability: Macintosh, <span class="Unix">Unix</span>.
277
278<span class="versionnote">New in version 2.3.</span>
279
280</dd></dl>
281
282<P>
283<dl><dt><b><tt id='l2h-1667' xml:id='l2h-1667'>EX_CANTCREAT</tt></b></dt>
284<dd>
285Exit code that means a user specified output file could not be created.
286Availability: Macintosh, <span class="Unix">Unix</span>.
287
288<span class="versionnote">New in version 2.3.</span>
289
290</dd></dl>
291
292<P>
293<dl><dt><b><tt id='l2h-1668' xml:id='l2h-1668'>EX_IOERR</tt></b></dt>
294<dd>
295Exit code that means that an error occurred while doing I/O on some file.
296Availability: Macintosh, <span class="Unix">Unix</span>.
297
298<span class="versionnote">New in version 2.3.</span>
299
300</dd></dl>
301
302<P>
303<dl><dt><b><tt id='l2h-1669' xml:id='l2h-1669'>EX_TEMPFAIL</tt></b></dt>
304<dd>
305Exit code that means a temporary failure occurred. This indicates
306something that may not really be an error, such as a network
307connection that couldn't be made during a retryable operation.
308Availability: Macintosh, <span class="Unix">Unix</span>.
309
310<span class="versionnote">New in version 2.3.</span>
311
312</dd></dl>
313
314<P>
315<dl><dt><b><tt id='l2h-1670' xml:id='l2h-1670'>EX_PROTOCOL</tt></b></dt>
316<dd>
317Exit code that means that a protocol exchange was illegal, invalid, or
318not understood.
319Availability: Macintosh, <span class="Unix">Unix</span>.
320
321<span class="versionnote">New in version 2.3.</span>
322
323</dd></dl>
324
325<P>
326<dl><dt><b><tt id='l2h-1671' xml:id='l2h-1671'>EX_NOPERM</tt></b></dt>
327<dd>
328Exit code that means that there were insufficient permissions to
329perform the operation (but not intended for file system problems).
330Availability: Macintosh, <span class="Unix">Unix</span>.
331
332<span class="versionnote">New in version 2.3.</span>
333
334</dd></dl>
335
336<P>
337<dl><dt><b><tt id='l2h-1672' xml:id='l2h-1672'>EX_CONFIG</tt></b></dt>
338<dd>
339Exit code that means that some kind of configuration error occurred.
340Availability: Macintosh, <span class="Unix">Unix</span>.
341
342<span class="versionnote">New in version 2.3.</span>
343
344</dd></dl>
345
346<P>
347<dl><dt><b><tt id='l2h-1673' xml:id='l2h-1673'>EX_NOTFOUND</tt></b></dt>
348<dd>
349Exit code that means something like ``an entry was not found''.
350Availability: Macintosh, <span class="Unix">Unix</span>.
351
352<span class="versionnote">New in version 2.3.</span>
353
354</dd></dl>
355
356<P>
357<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
358 <td><nobr><b><tt id='l2h-1674' xml:id='l2h-1674' class="function">fork</tt></b>(</nobr></td>
359 <td><var></var>)</td></tr></table></dt>
360<dd>
361Fork a child process. Return <code>0</code> in the child, the child's
362process id in the parent.
363Availability: Macintosh, <span class="Unix">Unix</span>.
364</dl>
365
366<P>
367<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
368 <td><nobr><b><tt id='l2h-1675' xml:id='l2h-1675' class="function">forkpty</tt></b>(</nobr></td>
369 <td><var></var>)</td></tr></table></dt>
370<dd>
371Fork a child process, using a new pseudo-terminal as the child's
372controlling terminal. Return a pair of <code>(<var>pid</var>, <var>fd</var>)</code>,
373where <var>pid</var> is <code>0</code> in the child, the new child's process id
374in the parent, and <var>fd</var> is the file descriptor of the master end
375of the pseudo-terminal. For a more portable approach, use the
376<tt class="module"><a href="module-pty.html">pty</a></tt> module.
377Availability: Macintosh, Some flavors of <span class="Unix">Unix</span>.
378</dl>
379
380<P>
381<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
382 <td><nobr><b><tt id='l2h-1676' xml:id='l2h-1676' class="function">kill</tt></b>(</nobr></td>
383 <td><var>pid, sig</var>)</td></tr></table></dt>
384<dd>
385<a id='l2h-1710' xml:id='l2h-1710'></a>
386Kill the process <var>pid</var> with signal <var>sig</var>. Constants for the
387specific signals available on the host platform are defined in the
388<tt class="module"><a href="module-signal.html">signal</a></tt> module.
389Availability: Macintosh, <span class="Unix">Unix</span>.
390</dl>
391
392<P>
393<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
394 <td><nobr><b><tt id='l2h-1677' xml:id='l2h-1677' class="function">killpg</tt></b>(</nobr></td>
395 <td><var>pgid, sig</var>)</td></tr></table></dt>
396<dd>
397<a id='l2h-1711' xml:id='l2h-1711'></a>
398Kill the process group <var>pgid</var> with the signal <var>sig</var>.
399Availability: Macintosh, <span class="Unix">Unix</span>.
400
401<span class="versionnote">New in version 2.3.</span>
402
403</dl>
404
405<P>
406<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
407 <td><nobr><b><tt id='l2h-1678' xml:id='l2h-1678' class="function">nice</tt></b>(</nobr></td>
408 <td><var>increment</var>)</td></tr></table></dt>
409<dd>
410Add <var>increment</var> to the process's ``niceness''. Return the new
411niceness.
412Availability: Macintosh, <span class="Unix">Unix</span>.
413</dl>
414
415<P>
416<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
417 <td><nobr><b><tt id='l2h-1679' xml:id='l2h-1679' class="function">plock</tt></b>(</nobr></td>
418 <td><var>op</var>)</td></tr></table></dt>
419<dd>
420Lock program segments into memory. The value of <var>op</var>
421(defined in <code>&lt;sys/lock.h&gt;</code>) determines which segments are locked.
422Availability: Macintosh, <span class="Unix">Unix</span>.
423</dl>
424
425<P>
426<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
427 <td><nobr><b><tt class="function">popen</tt></b>(</nobr></td>
428 <td><var>...</var>)</td></tr></table></dt>
429<dd>
430<dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
431 <td><nobr><b><tt class="function">popen2</tt></b>(</nobr></td>
432 <td><var>...</var>)</td></tr></table></dt>
433<dd><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
434 <td><nobr><b><tt class="function">popen3</tt></b>(</nobr></td>
435 <td><var>...</var>)</td></tr></table></dt>
436<dd><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
437 <td><nobr><b><tt class="function">popen4</tt></b>(</nobr></td>
438 <td><var>...</var>)</td></tr></table></dt>
439<dd>Run child processes, returning opened pipes for communications. These
440functions are described in section <A href="os-newstreams.html#os-newstreams">6.1.2</A>.
441</dl>
442
443<P>
444<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
445 <td><nobr><b><tt id='l2h-1680' xml:id='l2h-1680' class="function">spawnl</tt></b>(</nobr></td>
446 <td><var>mode, path, ...</var>)</td></tr></table></dt>
447<dd>
448<dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
449 <td><nobr><b><tt class="function">spawnle</tt></b>(</nobr></td>
450 <td><var>mode, path, ..., env</var>)</td></tr></table></dt>
451<dd><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
452 <td><nobr><b><tt class="function">spawnlp</tt></b>(</nobr></td>
453 <td><var>mode, file, ...</var>)</td></tr></table></dt>
454<dd><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
455 <td><nobr><b><tt class="function">spawnlpe</tt></b>(</nobr></td>
456 <td><var>mode, file, ..., env</var>)</td></tr></table></dt>
457<dd><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
458 <td><nobr><b><tt class="function">spawnv</tt></b>(</nobr></td>
459 <td><var>mode, path, args</var>)</td></tr></table></dt>
460<dd><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
461 <td><nobr><b><tt class="function">spawnve</tt></b>(</nobr></td>
462 <td><var>mode, path, args, env</var>)</td></tr></table></dt>
463<dd><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
464 <td><nobr><b><tt class="function">spawnvp</tt></b>(</nobr></td>
465 <td><var>mode, file, args</var>)</td></tr></table></dt>
466<dd><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
467 <td><nobr><b><tt class="function">spawnvpe</tt></b>(</nobr></td>
468 <td><var>mode, file, args, env</var>)</td></tr></table></dt>
469<dd>Execute the program <var>path</var> in a new process. If <var>mode</var> is
470<tt class="constant">P_NOWAIT</tt>, this function returns the process ID of the new
471process; if <var>mode</var> is <tt class="constant">P_WAIT</tt>, returns the process's
472exit code if it exits normally, or <code>-<var>signal</var></code>, where
473<var>signal</var> is the signal that killed the process. On Windows, the
474process ID will actually be the process handle, so can be used with
475the <tt class="function">waitpid()</tt> function.
476
477<P>
478The "<tt class="character">l</tt>" and "<tt class="character">v</tt>" variants of the
479<tt class="function">spawn*()</tt> functions differ in how command-line arguments are
480passed. The "<tt class="character">l</tt>" variants are perhaps the easiest to work
481with if the number of parameters is fixed when the code is written;
482the individual parameters simply become additional parameters to the
483<tt class="function">spawnl*()</tt> functions. The "<tt class="character">v</tt>" variants are good
484when the number of parameters is variable, with the arguments being
485passed in a list or tuple as the <var>args</var> parameter. In either
486case, the arguments to the child process must start with the name of
487the command being run.
488
489<P>
490The variants which include a second "<tt class="character">p</tt>" near the end
491(<tt class="function">spawnlp()</tt>, <tt class="function">spawnlpe()</tt>, <tt class="function">spawnvp()</tt>,
492and <tt class="function">spawnvpe()</tt>) will use the <a class="envvar" id='l2h-1712' xml:id='l2h-1712'>PATH</a> environment
493variable to locate the program <var>file</var>. When the environment is
494being replaced (using one of the <tt class="function">spawn*e()</tt> variants,
495discussed in the next paragraph), the new environment is used as the
496source of the <a class="envvar" id='l2h-1713' xml:id='l2h-1713'>PATH</a> variable. The other variants,
497<tt class="function">spawnl()</tt>, <tt class="function">spawnle()</tt>, <tt class="function">spawnv()</tt>, and
498<tt class="function">spawnve()</tt>, will not use the <a class="envvar" id='l2h-1714' xml:id='l2h-1714'>PATH</a> variable to
499locate the executable; <var>path</var> must contain an appropriate absolute
500or relative path.
501
502<P>
503For <tt class="function">spawnle()</tt>, <tt class="function">spawnlpe()</tt>, <tt class="function">spawnve()</tt>,
504and <tt class="function">spawnvpe()</tt> (note that these all end in "<tt class="character">e</tt>"),
505the <var>env</var> parameter must be a mapping which is used to define the
506environment variables for the new process; the <tt class="function">spawnl()</tt>,
507<tt class="function">spawnlp()</tt>, <tt class="function">spawnv()</tt>, and <tt class="function">spawnvp()</tt>
508all cause the new process to inherit the environment of the current
509process.
510
511<P>
512As an example, the following calls to <tt class="function">spawnlp()</tt> and
513<tt class="function">spawnvpe()</tt> are equivalent:
514
515<P>
516<div class="verbatim"><pre>
517import os
518os.spawnlp(os.P_WAIT, 'cp', 'cp', 'index.html', '/dev/null')
519
520L = ['cp', 'index.html', '/dev/null']
521os.spawnvpe(os.P_WAIT, 'cp', L, os.environ)
522</pre></div>
523
524<P>
525Availability: <span class="Unix">Unix</span>, Windows. <tt class="function">spawnlp()</tt>,
526<tt class="function">spawnlpe()</tt>, <tt class="function">spawnvp()</tt> and <tt class="function">spawnvpe()</tt>
527are not available on Windows.
528
529<span class="versionnote">New in version 1.6.</span>
530
531</dl>
532
533<P>
534<dl><dt><b><tt id='l2h-1688' xml:id='l2h-1688'>P_NOWAIT</tt></b></dt>
535<dd>
536<dt><b><tt id='l2h-1715' xml:id='l2h-1715'>P_NOWAITO</tt></b></dt><dd>
537Possible values for the <var>mode</var> parameter to the <tt class="function">spawn*()</tt>
538family of functions. If either of these values is given, the
539<tt class="function">spawn*()</tt> functions will return as soon as the new process
540has been created, with the process ID as the return value.
541Availability: Macintosh, <span class="Unix">Unix</span>, Windows.
542
543<span class="versionnote">New in version 1.6.</span>
544
545</dd></dl>
546
547<P>
548<dl><dt><b><tt id='l2h-1689' xml:id='l2h-1689'>P_WAIT</tt></b></dt>
549<dd>
550Possible value for the <var>mode</var> parameter to the <tt class="function">spawn*()</tt>
551family of functions. If this is given as <var>mode</var>, the
552<tt class="function">spawn*()</tt> functions will not return until the new process
553has run to completion and will return the exit code of the process the
554run is successful, or <code>-<var>signal</var></code> if a signal kills the
555process.
556Availability: Macintosh, <span class="Unix">Unix</span>, Windows.
557
558<span class="versionnote">New in version 1.6.</span>
559
560</dd></dl>
561
562<P>
563<dl><dt><b><tt id='l2h-1690' xml:id='l2h-1690'>P_DETACH</tt></b></dt>
564<dd>
565<dt><b><tt id='l2h-1716' xml:id='l2h-1716'>P_OVERLAY</tt></b></dt><dd>
566Possible values for the <var>mode</var> parameter to the
567<tt class="function">spawn*()</tt> family of functions. These are less portable than
568those listed above.
569<tt class="constant">P_DETACH</tt> is similar to <tt class="constant">P_NOWAIT</tt>, but the new
570process is detached from the console of the calling process.
571If <tt class="constant">P_OVERLAY</tt> is used, the current process will be replaced;
572the <tt class="function">spawn*()</tt> function will not return.
573Availability: Windows.
574
575<span class="versionnote">New in version 1.6.</span>
576
577</dd></dl>
578
579<P>
580<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
581 <td><nobr><b><tt id='l2h-1691' xml:id='l2h-1691' class="function">startfile</tt></b>(</nobr></td>
582 <td><var>path</var>)</td></tr></table></dt>
583<dd>
584Start a file with its associated application. This acts like
585double-clicking the file in Windows Explorer, or giving the file name
586as an argument to the <b class="program">start</b> command from the interactive
587command shell: the file is opened with whatever application (if any)
588its extension is associated.
589
590<P>
591<tt class="function">startfile()</tt> returns as soon as the associated application
592is launched. There is no option to wait for the application to close,
593and no way to retrieve the application's exit status. The <var>path</var>
594parameter is relative to the current directory. If you want to use an
595absolute path, make sure the first character is not a slash
596("<tt class="character">/</tt>"); the underlying Win32 <tt class="cfunction">ShellExecute()</tt>
597function doesn't work if it is. Use the <tt class="function">os.path.normpath()</tt>
598function to ensure that the path is properly encoded for Win32.
599Availability: Windows.
600
601<span class="versionnote">New in version 2.0.</span>
602
603</dl>
604
605<P>
606<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
607 <td><nobr><b><tt id='l2h-1692' xml:id='l2h-1692' class="function">system</tt></b>(</nobr></td>
608 <td><var>command</var>)</td></tr></table></dt>
609<dd>
610Execute the command (a string) in a subshell. This is implemented by
611calling the Standard C function <tt class="cfunction">system()</tt>, and has the
612same limitations. Changes to <code>posix.environ</code>, <code>sys.stdin</code>,
613etc. are not reflected in the environment of the executed command.
614
615<P>
616On <span class="Unix">Unix</span>, the return value is the exit status of the process encoded in the
617format specified for <tt class="function">wait()</tt>. Note that POSIX does not
618specify the meaning of the return value of the C <tt class="cfunction">system()</tt>
619function, so the return value of the Python function is system-dependent.
620
621<P>
622On Windows, the return value is that returned by the system shell after
623running <var>command</var>, given by the Windows environment variable
624<a class="envvar" id='l2h-1717' xml:id='l2h-1717'>COMSPEC</a>: on <b class="program">command.com</b> systems (Windows 95, 98 and ME)
625this is always <code>0</code>; on <b class="program">cmd.exe</b> systems (Windows NT, 2000
626and XP) this is the exit status of the command run; on systems using
627a non-native shell, consult your shell documentation.
628
629<P>
630Availability: Macintosh, <span class="Unix">Unix</span>, Windows.
631</dl>
632
633<P>
634<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
635 <td><nobr><b><tt id='l2h-1693' xml:id='l2h-1693' class="function">times</tt></b>(</nobr></td>
636 <td><var></var>)</td></tr></table></dt>
637<dd>
638Return a 5-tuple of floating point numbers indicating accumulated
639(processor or other)
640times, in seconds. The items are: user time, system time, children's
641user time, children's system time, and elapsed real time since a fixed
642point in the past, in that order. See the <span class="Unix">Unix</span> manual page
643<span class="manpage"><i>times</i>(2)</span> or the corresponding Windows Platform API
644documentation.
645Availability: Macintosh, <span class="Unix">Unix</span>, Windows.
646</dl>
647
648<P>
649<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
650 <td><nobr><b><tt id='l2h-1694' xml:id='l2h-1694' class="function">wait</tt></b>(</nobr></td>
651 <td><var></var>)</td></tr></table></dt>
652<dd>
653Wait for completion of a child process, and return a tuple containing
654its pid and exit status indication: a 16-bit number, whose low byte is
655the signal number that killed the process, and whose high byte is the
656exit status (if the signal number is zero); the high bit of the low
657byte is set if a core file was produced.
658Availability: Macintosh, <span class="Unix">Unix</span>.
659</dl>
660
661<P>
662<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
663 <td><nobr><b><tt id='l2h-1695' xml:id='l2h-1695' class="function">waitpid</tt></b>(</nobr></td>
664 <td><var>pid, options</var>)</td></tr></table></dt>
665<dd>
666The details of this function differ on <span class="Unix">Unix</span> and Windows.
667
668<P>
669On <span class="Unix">Unix</span>:
670Wait for completion of a child process given by process id <var>pid</var>,
671and return a tuple containing its process id and exit status
672indication (encoded as for <tt class="function">wait()</tt>). The semantics of the
673call are affected by the value of the integer <var>options</var>, which
674should be <code>0</code> for normal operation.
675
676<P>
677If <var>pid</var> is greater than <code>0</code>, <tt class="function">waitpid()</tt> requests
678status information for that specific process. If <var>pid</var> is
679<code>0</code>, the request is for the status of any child in the process
680group of the current process. If <var>pid</var> is <code>-1</code>, the request
681pertains to any child of the current process. If <var>pid</var> is less
682than <code>-1</code>, status is requested for any process in the process
683group <code>-<var>pid</var></code> (the absolute value of <var>pid</var>).
684
685<P>
686On Windows:
687Wait for completion of a process given by process handle <var>pid</var>,
688and return a tuple containing <var>pid</var>,
689and its exit status shifted left by 8 bits (shifting makes cross-platform
690use of the function easier).
691A <var>pid</var> less than or equal to <code>0</code> has no special meaning on
692Windows, and raises an exception.
693The value of integer <var>options</var> has no effect.
694<var>pid</var> can refer to any process whose id is known, not necessarily a
695child process.
696The <tt class="function">spawn()</tt> functions called with <tt class="constant">P_NOWAIT</tt>
697return suitable process handles.
698</dl>
699
700<P>
701<dl><dt><b><tt id='l2h-1696' xml:id='l2h-1696'>WNOHANG</tt></b></dt>
702<dd>
703The option for <tt class="function">waitpid()</tt> to return immediately if no child
704process status is available immediately. The function returns
705<code>(0, 0)</code> in this case.
706Availability: Macintosh, <span class="Unix">Unix</span>.
707</dd></dl>
708
709<P>
710<dl><dt><b><tt id='l2h-1697' xml:id='l2h-1697'>WCONTINUED</tt></b></dt>
711<dd>
712This option causes child processes to be reported if they have been
713continued from a job control stop since their status was last
714reported.
715Availability: Some <span class="Unix">Unix</span> systems.
716
717<span class="versionnote">New in version 2.3.</span>
718
719</dd></dl>
720
721<P>
722<dl><dt><b><tt id='l2h-1698' xml:id='l2h-1698'>WUNTRACED</tt></b></dt>
723<dd>
724This option causes child processes to be reported if they have been
725stopped but their current state has not been reported since they were
726stopped.
727Availability: Macintosh, <span class="Unix">Unix</span>.
728
729<span class="versionnote">New in version 2.3.</span>
730
731</dd></dl>
732
733<P>
734The following functions take a process status code as returned by
735<tt class="function">system()</tt>, <tt class="function">wait()</tt>, or <tt class="function">waitpid()</tt> as a
736parameter. They may be used to determine the disposition of a
737process.
738
739<P>
740<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
741 <td><nobr><b><tt id='l2h-1699' xml:id='l2h-1699' class="function">WCOREDUMP</tt></b>(</nobr></td>
742 <td><var>status</var>)</td></tr></table></dt>
743<dd>
744Returns <code>True</code> if a core dump was generated for the process,
745otherwise it returns <code>False</code>.
746Availability: Macintosh, <span class="Unix">Unix</span>.
747
748<span class="versionnote">New in version 2.3.</span>
749
750</dl>
751
752<P>
753<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
754 <td><nobr><b><tt id='l2h-1700' xml:id='l2h-1700' class="function">WIFCONTINUED</tt></b>(</nobr></td>
755 <td><var>status</var>)</td></tr></table></dt>
756<dd>
757Returns <code>True</code> if the process has been continued from a job
758control stop, otherwise it returns <code>False</code>.
759Availability: <span class="Unix">Unix</span>.
760
761<span class="versionnote">New in version 2.3.</span>
762
763</dl>
764
765<P>
766<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
767 <td><nobr><b><tt id='l2h-1701' xml:id='l2h-1701' class="function">WIFSTOPPED</tt></b>(</nobr></td>
768 <td><var>status</var>)</td></tr></table></dt>
769<dd>
770Returns <code>True</code> if the process has been stopped, otherwise it
771returns <code>False</code>.
772Availability: <span class="Unix">Unix</span>.
773</dl>
774
775<P>
776<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
777 <td><nobr><b><tt id='l2h-1702' xml:id='l2h-1702' class="function">WIFSIGNALED</tt></b>(</nobr></td>
778 <td><var>status</var>)</td></tr></table></dt>
779<dd>
780Returns <code>True</code> if the process exited due to a signal, otherwise
781it returns <code>False</code>.
782Availability: Macintosh, <span class="Unix">Unix</span>.
783</dl>
784
785<P>
786<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
787 <td><nobr><b><tt id='l2h-1703' xml:id='l2h-1703' class="function">WIFEXITED</tt></b>(</nobr></td>
788 <td><var>status</var>)</td></tr></table></dt>
789<dd>
790Returns <code>True</code> if the process exited using the <span class="manpage"><i>exit</i>(2)</span>
791system call, otherwise it returns <code>False</code>.
792Availability: Macintosh, <span class="Unix">Unix</span>.
793</dl>
794
795<P>
796<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
797 <td><nobr><b><tt id='l2h-1704' xml:id='l2h-1704' class="function">WEXITSTATUS</tt></b>(</nobr></td>
798 <td><var>status</var>)</td></tr></table></dt>
799<dd>
800If <code>WIFEXITED(<var>status</var>)</code> is true, return the integer
801parameter to the <span class="manpage"><i>exit</i>(2)</span> system call. Otherwise, the return
802value is meaningless.
803Availability: Macintosh, <span class="Unix">Unix</span>.
804</dl>
805
806<P>
807<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
808 <td><nobr><b><tt id='l2h-1705' xml:id='l2h-1705' class="function">WSTOPSIG</tt></b>(</nobr></td>
809 <td><var>status</var>)</td></tr></table></dt>
810<dd>
811Return the signal which caused the process to stop.
812Availability: Macintosh, <span class="Unix">Unix</span>.
813</dl>
814
815<P>
816<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
817 <td><nobr><b><tt id='l2h-1706' xml:id='l2h-1706' class="function">WTERMSIG</tt></b>(</nobr></td>
818 <td><var>status</var>)</td></tr></table></dt>
819<dd>
820Return the signal which caused the process to exit.
821Availability: Macintosh, <span class="Unix">Unix</span>.
822</dl>
823
824<P>
825
826<DIV CLASS="navigation">
827<div class='online-navigation'>
828<p></p><hr />
829<table align="center" width="100%" cellpadding="0" cellspacing="2">
830<tr>
831<td class='online-navigation'><a rel="prev" title="6.1.4 Files and Directories"
832 href="os-file-dir.html"><img src='../icons/previous.png'
833 border='0' height='32' alt='Previous Page' width='32' /></A></td>
834<td class='online-navigation'><a rel="parent" title="6.1 os "
835 href="module-os.html"><img src='../icons/up.png'
836 border='0' height='32' alt='Up One Level' width='32' /></A></td>
837<td class='online-navigation'><a rel="next" title="6.1.6 Miscellaneous System Information"
838 href="os-path.html"><img src='../icons/next.png'
839 border='0' height='32' alt='Next Page' width='32' /></A></td>
840<td align="center" width="100%">Python Library Reference</td>
841<td class='online-navigation'><a rel="contents" title="Table of Contents"
842 href="contents.html"><img src='../icons/contents.png'
843 border='0' height='32' alt='Contents' width='32' /></A></td>
844<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
845 border='0' height='32' alt='Module Index' width='32' /></a></td>
846<td class='online-navigation'><a rel="index" title="Index"
847 href="genindex.html"><img src='../icons/index.png'
848 border='0' height='32' alt='Index' width='32' /></A></td>
849</tr></table>
850<div class='online-navigation'>
851<b class="navlabel">Previous:</b>
852<a class="sectref" rel="prev" href="os-file-dir.html">6.1.4 Files and Directories</A>
853<b class="navlabel">Up:</b>
854<a class="sectref" rel="parent" href="module-os.html">6.1 os </A>
855<b class="navlabel">Next:</b>
856<a class="sectref" rel="next" href="os-path.html">6.1.6 Miscellaneous System Information</A>
857</div>
858</div>
859<hr />
860<span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span>
861</DIV>
862<!--End of Navigation Panel-->
863<ADDRESS>
864See <i><a href="about.html">About this document...</a></i> for information on suggesting changes.
865</ADDRESS>
866</BODY>
867</HTML>