📄 os-process.html
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>6.1.5 Process Management </title>
<META NAME="description" CONTENT="6.1.5 Process Management ">
<META NAME="keywords" CONTENT="lib">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="STYLESHEET" href="lib.css" tppabs="http://www.python.org/doc/current/lib/lib.css">
<LINK REL="next" href="os-path.html" tppabs="http://www.python.org/doc/current/lib/os-path.html">
<LINK REL="previous" href="os-file-dir.html" tppabs="http://www.python.org/doc/current/lib/os-file-dir.html">
<LINK REL="up" href="module-os.html" tppabs="http://www.python.org/doc/current/lib/module-os.html">
<LINK REL="next" href="os-path.html" tppabs="http://www.python.org/doc/current/lib/os-path.html">
</head>
<body>
<DIV CLASS="navigation"><table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A href="os-file-dir.html" tppabs="http://www.python.org/doc/current/lib/os-file-dir.html"><img src="previous.gif" tppabs="http://www.python.org/doc/current/icons/previous.gif" border="0" height="32"
alt="Previous Page" width="32"></A></td>
<td><A href="module-os.html" tppabs="http://www.python.org/doc/current/lib/module-os.html"><img src="up.gif" tppabs="http://www.python.org/doc/current/icons/up.gif" border="0" height="32"
alt="Up One Level" width="32"></A></td>
<td><A href="os-path.html" tppabs="http://www.python.org/doc/current/lib/os-path.html"><img src="next.gif" tppabs="http://www.python.org/doc/current/icons/next.gif" border="0" height="32"
alt="Next Page" width="32"></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td><A href="contents.html" tppabs="http://www.python.org/doc/current/lib/contents.html"><img src="contents.gif" tppabs="http://www.python.org/doc/current/icons/contents.gif" border="0" height="32"
alt="Contents" width="32"></A></td>
<td><a href="modindex.html" tppabs="http://www.python.org/doc/current/lib/modindex.html" title="Module Index"><img src="modules.gif" tppabs="http://www.python.org/doc/current/icons/modules.gif" border="0" height="32"
alt="Module Index" width="32"></a></td>
<td><A href="genindex.html" tppabs="http://www.python.org/doc/current/lib/genindex.html"><img src="index.gif" tppabs="http://www.python.org/doc/current/icons/index.gif" border="0" height="32"
alt="Index" width="32"></A></td>
</tr></table>
<b class="navlabel">Previous:</b> <a class="sectref" href="os-file-dir.html" tppabs="http://www.python.org/doc/current/lib/os-file-dir.html">6.1.4 Files and Directories</A>
<b class="navlabel">Up:</b> <a class="sectref" href="module-os.html" tppabs="http://www.python.org/doc/current/lib/module-os.html">6.1 os </A>
<b class="navlabel">Next:</b> <a class="sectref" href="os-path.html" tppabs="http://www.python.org/doc/current/lib/os-path.html">6.1.6 Miscellaneous System Information</A>
<br><hr></DIV>
<!--End of Navigation Panel-->
<H2>
<BR>
6.1.5 Process Management
</H2>
<P>
These functions may be used to create and manage processes.
<P>
The various <tt class="function">exec*()</tt> functions take a list of arguments for
the new program loaded into the process. In each case, the first of
these arguments is passed to the new program as its own name rather
than as an argument a user may have typed on a command line. For the
C programmer, this is the <code>argv[0]</code> passed to a program's
<tt class="cfunction">main()</tt>. For example, "<tt class="samp">os.execv('/bin/echo', ['foo',
'bar'])</tt>" will only print "<tt class="samp">bar</tt>" on standard output; "<tt class="samp">foo</tt>"will seem to be ignored.
<P>
<dl><dt><b><a name='l2h-981'><tt class='function'>abort</tt></a></b> ()
<dd>
Generate a <tt class="constant">SIGABRT</tt> signal to the current process. On
Unix, the default behavior is to produce a core dump; on Windows, the
process immediately returns an exit code of <code>3</code>. Be aware that
programs which use <tt class="function">signal.signal()</tt> to register a handler
for <tt class="constant">SIGABRT</tt> will behave differently.
Availability: Unix, Windows.
</dl>
<P>
<dl><dt><b><a name='l2h-982'><tt class='function'>execl</tt></a></b> (<var>path, arg0, arg1, ...</var>)
<dd>
This is equivalent to
"<tt class="samp">execv(<var>path</var>, (<var>arg0</var>, <var>arg1</var>, ...))</tt>".
Availability: Unix, Windows.
</dl>
<P>
<dl><dt><b><a name='l2h-983'><tt class='function'>execle</tt></a></b> (<var>path, arg0, arg1, ..., env</var>)
<dd>
This is equivalent to
"<tt class="samp">execve(<var>path</var>, (<var>arg0</var>, <var>arg1</var>, ...), <var>env</var>)</tt>".
Availability: Unix, Windows.
</dl>
<P>
<dl><dt><b><a name='l2h-984'><tt class='function'>execlp</tt></a></b> (<var>path, arg0, arg1, ...</var>)
<dd>
This is equivalent to
"<tt class="samp">execvp(<var>path</var>, (<var>arg0</var>, <var>arg1</var>, ...))</tt>".
Availability: Unix, Windows.
</dl>
<P>
<dl><dt><b><a name='l2h-985'><tt class='function'>execv</tt></a></b> (<var>path, args</var>)
<dd>
Execute the executable <var>path</var> with argument list <var>args</var>,
replacing the current process (i.e., the Python interpreter).
The argument list may be a tuple or list of strings.
Availability: Unix, Windows.
</dl>
<P>
<dl><dt><b><a name='l2h-986'><tt class='function'>execve</tt></a></b> (<var>path, args, env</var>)
<dd>
Execute the executable <var>path</var> with argument list <var>args</var>,
and environment <var>env</var>,
replacing the current process (i.e., the Python interpreter).
The argument list may be a tuple or list of strings.
The environment must be a dictionary mapping strings to strings.
Availability: Unix, Windows.
</dl>
<P>
<dl><dt><b><a name='l2h-987'><tt class='function'>execvp</tt></a></b> (<var>path, args</var>)
<dd>
This is like "<tt class="samp">execv(<var>path</var>, <var>args</var>)</tt>" but duplicates
the shell's actions in searching for an executable file in a list of
directories. The directory list is obtained from
<code>environ['PATH']</code>.
Availability: Unix, Windows.
</dl>
<P>
<dl><dt><b><a name='l2h-988'><tt class='function'>execvpe</tt></a></b> (<var>path, args, env</var>)
<dd>
This is a cross between <tt class="function">execve()</tt> and <tt class="function">execvp()</tt>.
The directory list is obtained from <code><var>env</var>['PATH']</code>.
Availability: Unix, Windows.
</dl>
<P>
<dl><dt><b><a name='l2h-989'><tt class='function'>_exit</tt></a></b> (<var>n</var>)
<dd>
Exit to the system with status <var>n</var>, without calling cleanup
handlers, flushing stdio buffers, etc.
Availability: Unix, Windows.
<P>
Note: the standard way to exit is <code>sys.exit(<var>n</var>)</code>.
<tt class="function">_exit()</tt> should normally only be used in the child process
after a <tt class="function">fork()</tt>.
</dl>
<P>
<dl><dt><b><a name='l2h-990'><tt class='function'>fork</tt></a></b> ()
<dd>
Fork a child process. Return <code>0</code> in the child, the child's
process id in the parent.
Availability: Unix.
</dl>
<P>
<dl><dt><b><a name='l2h-991'><tt class='function'>forkpty</tt></a></b> ()
<dd>
Fork a child process, using a new pseudo-terminal as the child's
controlling terminal. Return a pair of <code>(<var>pid</var>, <var>fd</var>)</code>,
where <var>pid</var> is <code>0</code> in the child, the new child's process id
in the parent, and <code>fd</code> is the file descriptor of the master end
of the pseudo-terminal. For a more portable approach, use the
<tt class='module'><a href="module-pty.html" tppabs="http://www.python.org/doc/current/lib/module-pty.html">pty</a></tt> module.
Availability: Some flavors of Unix
</dl>
<P>
<dl><dt><b><a name='l2h-992'><tt class='function'>kill</tt></a></b> (<var>pid, sig</var>)
<dd>
Kill the process <var>pid</var> with signal <var>sig</var>.
Availability: Unix.
</dl>
<P>
<dl><dt><b><a name='l2h-993'><tt class='function'>nice</tt></a></b> (<var>increment</var>)
<dd>
Add <var>increment</var> to the process's ``niceness''. Return the new
niceness.
Availability: Unix.
</dl>
<P>
<dl><dt><b><a name='l2h-994'><tt class='function'>plock</tt></a></b> (<var>op</var>)
<dd>
Lock program segments into memory. The value of <var>op</var>
(defined in <code><sys/lock.h></code>) determines which segments are locked.
Availability: Unix.
</dl>
<P>
<dl><dt><b><a name='l2h-995'><tt class='function'>spawnv</tt></a></b> (<var>mode, path, args</var>)
<dd>
Execute the program <var>path</var> in a new process, passing the arguments
specified in <var>args</var> as command-line parameters. <var>args</var> may be
a list or a tuple. <var>mode</var> is a magic operational constant. See
the Visual C++ Runtime Library documentation for further
information; the constants are exposed to the Python programmer as
listed below.
Availability: Unix, Windows.
New in version 1.5.2.
</dl>
<P>
<dl><dt><b><a name='l2h-996'><tt class='function'>spawnve</tt></a></b> (<var>mode, path, args, env</var>)
<dd>
Execute the program <var>path</var> in a new process, passing the arguments
specified in <var>args</var> as command-line parameters and the contents of
the mapping <var>env</var> as the environment. <var>args</var> may be a list or
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -