620 lines
43 KiB
HTML
620 lines
43 KiB
HTML
|
||
<!DOCTYPE html>
|
||
|
||
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh_CN">
|
||
<head>
|
||
<meta charset="utf-8" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
|
||
|
||
<title>resource --- 资源使用信息 — Python 3.8.20 文档</title><meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
|
||
<link rel="stylesheet" href="../_static/pydoctheme.css" type="text/css" />
|
||
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
|
||
|
||
<script id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
|
||
<script src="../_static/jquery.js"></script>
|
||
<script src="../_static/underscore.js"></script>
|
||
<script src="../_static/doctools.js"></script>
|
||
<script src="../_static/language_data.js"></script>
|
||
<script src="../_static/translations.js"></script>
|
||
|
||
<script src="../_static/sidebar.js"></script>
|
||
|
||
<link rel="search" type="application/opensearchdescription+xml"
|
||
title="在 Python 3.8.20 文档 中搜索"
|
||
href="../_static/opensearch.xml"/>
|
||
<link rel="author" title="关于这些文档" href="../about.html" />
|
||
<link rel="index" title="索引" href="../genindex.html" />
|
||
<link rel="search" title="搜索" href="../search.html" />
|
||
<link rel="copyright" title="版权所有" href="../copyright.html" />
|
||
<link rel="next" title="nis --- Sun 的 NIS (黄页) 接口" href="nis.html" />
|
||
<link rel="prev" title="pipes --- 终端管道接口" href="pipes.html" />
|
||
<link rel="canonical" href="https://docs.python.org/3/library/resource.html" />
|
||
|
||
|
||
|
||
|
||
|
||
<style>
|
||
@media only screen {
|
||
table.full-width-table {
|
||
width: 100%;
|
||
}
|
||
}
|
||
</style>
|
||
<link rel="shortcut icon" type="image/png" href="../_static/py.svg" />
|
||
<script type="text/javascript" src="../_static/copybutton.js"></script>
|
||
<script type="text/javascript" src="../_static/menu.js"></script>
|
||
|
||
</head>
|
||
<body>
|
||
<div class="mobile-nav">
|
||
<input type="checkbox" id="menuToggler" class="toggler__input" aria-controls="navigation"
|
||
aria-pressed="false" aria-expanded="false" role="button" aria-label="Menu" />
|
||
<label for="menuToggler" class="toggler__label">
|
||
<span></span>
|
||
</label>
|
||
<nav class="nav-content" role="navigation">
|
||
<a href="https://www.python.org/" class="nav-logo">
|
||
<img src="../_static/py.svg" alt="Logo"/>
|
||
</a>
|
||
<div class="version_switcher_placeholder"></div>
|
||
<form role="search" class="search" action="../search.html" method="get">
|
||
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" class="search-icon">
|
||
<path fill-rule="nonzero"
|
||
d="M15.5 14h-.79l-.28-.27a6.5 6.5 0 001.48-5.34c-.47-2.78-2.79-5-5.59-5.34a6.505 6.505 0 00-7.27 7.27c.34 2.8 2.56 5.12 5.34 5.59a6.5 6.5 0 005.34-1.48l.27.28v.79l4.25 4.25c.41.41 1.08.41 1.49 0 .41-.41.41-1.08 0-1.49L15.5 14zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z" fill="#444"></path>
|
||
</svg>
|
||
<input type="text" name="q" aria-label="快速搜索"/>
|
||
<input type="submit" value="转向"/>
|
||
</form>
|
||
</nav>
|
||
<div class="menu-wrapper">
|
||
<nav class="menu" role="navigation" aria-label="main navigation">
|
||
<div class="language_switcher_placeholder"></div>
|
||
<h3><a href="../contents.html">目录</a></h3>
|
||
<ul>
|
||
<li><a class="reference internal" href="#"><code class="xref py py-mod docutils literal notranslate"><span class="pre">resource</span></code> --- 资源使用信息</a><ul>
|
||
<li><a class="reference internal" href="#resource-limits">资源限制</a></li>
|
||
<li><a class="reference internal" href="#resource-usage">资源用量</a></li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
|
||
<h4>上一个主题</h4>
|
||
<p class="topless"><a href="pipes.html"
|
||
title="上一章"><code class="xref py py-mod docutils literal notranslate"><span class="pre">pipes</span></code> --- 终端管道接口</a></p>
|
||
<h4>下一个主题</h4>
|
||
<p class="topless"><a href="nis.html"
|
||
title="下一章"><code class="xref py py-mod docutils literal notranslate"><span class="pre">nis</span></code> --- Sun 的 NIS (黄页) 接口</a></p>
|
||
<div role="note" aria-label="source link">
|
||
<h3>本页</h3>
|
||
<ul class="this-page-menu">
|
||
<li><a href="../bugs.html">报告 Bug</a></li>
|
||
<li>
|
||
<a href="https://github.com/python/cpython/blob/3.8/Doc/library/resource.rst"
|
||
rel="nofollow">显示源代码
|
||
</a>
|
||
</li>
|
||
</ul>
|
||
</div>
|
||
</nav>
|
||
</div>
|
||
</div>
|
||
|
||
<div id="outdated-warning" style="padding: .5em; text-align: center; background-color: #FFBABA; color: #6A0E0E;">
|
||
这个文档所针对的是一个已不再受支持的 Python 旧版本。
|
||
你应当升级版本,并阅读
|
||
<a href="/3/library/resource.html"> Python 当前稳定版本的文档</a>.
|
||
</div>
|
||
|
||
<div class="related" role="navigation" aria-label="related navigation">
|
||
<h3>导航</h3>
|
||
<ul>
|
||
<li class="right" style="margin-right: 10px">
|
||
<a href="../genindex.html" title="总目录"
|
||
accesskey="I">索引</a></li>
|
||
<li class="right" >
|
||
<a href="../py-modindex.html" title="Python 模块索引"
|
||
>模块</a> |</li>
|
||
<li class="right" >
|
||
<a href="nis.html" title="nis --- Sun 的 NIS (黄页) 接口"
|
||
accesskey="N">下一页</a> |</li>
|
||
<li class="right" >
|
||
<a href="pipes.html" title="pipes --- 终端管道接口"
|
||
accesskey="P">上一页</a> |</li>
|
||
|
||
<li><img src="../_static/py.svg" alt="python logo" style="vertical-align: middle; margin-top: -1px"/></li>
|
||
<li><a href="https://www.python.org/">Python</a> »</li>
|
||
<li class="switchers">
|
||
<div class="language_switcher_placeholder"></div>
|
||
<div class="version_switcher_placeholder"></div>
|
||
</li>
|
||
<li>
|
||
|
||
</li>
|
||
<li id="cpython-language-and-version">
|
||
<a href="../index.html">3.8.20 Documentation</a> »
|
||
</li>
|
||
|
||
<li class="nav-item nav-item-1"><a href="index.html" >Python 标准库</a> »</li>
|
||
<li class="nav-item nav-item-2"><a href="unix.html" accesskey="U">Unix 专有服务</a> »</li>
|
||
<li class="right">
|
||
|
||
|
||
<div class="inline-search" role="search">
|
||
<form class="inline-search" action="../search.html" method="get">
|
||
<input placeholder="快速搜索" aria-label="快速搜索" type="text" name="q" />
|
||
<input type="submit" value="转向" />
|
||
<input type="hidden" name="check_keywords" value="yes" />
|
||
<input type="hidden" name="area" value="default" />
|
||
</form>
|
||
</div>
|
||
|
|
||
</li>
|
||
|
||
</ul>
|
||
</div>
|
||
|
||
<div class="document">
|
||
<div class="documentwrapper">
|
||
<div class="bodywrapper">
|
||
<div class="body" role="main">
|
||
|
||
<section id="module-resource">
|
||
<span id="resource-resource-usage-information"></span><h1><a class="reference internal" href="#module-resource" title="resource: An interface to provide resource usage information on the current process. (Unix)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">resource</span></code></a> --- 资源使用信息<a class="headerlink" href="#module-resource" title="永久链接至标题">¶</a></h1>
|
||
<hr class="docutils" />
|
||
<p>该模块提供了测量和控制程序所利用的系统资源的基本机制。</p>
|
||
<p>符号常量被用来指定特定的系统资源,并要求获得关于当前进程或其子进程的使用信息。</p>
|
||
<p>当系统调用失败时,会触发一个 <a class="reference internal" href="exceptions.html#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a> 。</p>
|
||
<dl class="exception">
|
||
<dt id="resource.error">
|
||
<em class="property">exception </em><code class="sig-prename descclassname">resource.</code><code class="sig-name descname">error</code><a class="headerlink" href="#resource.error" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>一个被弃用的 <a class="reference internal" href="exceptions.html#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a> 的别名。</p>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">在 3.3 版更改: </span>根据 <span class="target" id="index-2"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-3151"><strong>PEP 3151</strong></a>,这个类是 <a class="reference internal" href="exceptions.html#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a> 的别名。</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<section id="resource-limits">
|
||
<h2>资源限制<a class="headerlink" href="#resource-limits" title="永久链接至标题">¶</a></h2>
|
||
<p>资源的使用可以通过下面描述的 <a class="reference internal" href="#resource.setrlimit" title="resource.setrlimit"><code class="xref py py-func docutils literal notranslate"><span class="pre">setrlimit()</span></code></a> 函数来限制。每个资源都被一对限制所控制:一个软限制和一个硬限制。软限制是当前的限制,并且可以由一个进程随着时间的推移而降低或提高。软限制永远不能超过硬限制。硬限制可以降低到大于软限制的任何数值,但不能提高。(只有拥有超级用户有效UID的进程才能提高硬限制。)</p>
|
||
<p>可以被限制的具体资源取决于系统。它们在 man <em class="manpage"><a class="manpage reference external" href="https://manpages.debian.org/getrlimit(2)">getrlimit(2)</a></em> 中描述。 下面列出的资源在底层操作系统支持的情况下被支持;那些不能被操作系统检查或控制的资源在本模块中没有为这些平台定义。</p>
|
||
<dl class="data">
|
||
<dt id="resource.RLIM_INFINITY">
|
||
<code class="sig-prename descclassname">resource.</code><code class="sig-name descname">RLIM_INFINITY</code><a class="headerlink" href="#resource.RLIM_INFINITY" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>用来表示无限资源的极限的常数。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="resource.getrlimit">
|
||
<code class="sig-prename descclassname">resource.</code><code class="sig-name descname">getrlimit</code><span class="sig-paren">(</span><em class="sig-param">resource</em><span class="sig-paren">)</span><a class="headerlink" href="#resource.getrlimit" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>返回一个包含 <em>resource</em> 当前软限制和硬限制的元组。如果指定了一个无效的资源,则触发 <a class="reference internal" href="exceptions.html#ValueError" title="ValueError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ValueError</span></code></a> ,如果底层系统调用意外失败,则引发 <a class="reference internal" href="#resource.error" title="resource.error"><code class="xref py py-exc docutils literal notranslate"><span class="pre">error</span></code></a> 。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="resource.setrlimit">
|
||
<code class="sig-prename descclassname">resource.</code><code class="sig-name descname">setrlimit</code><span class="sig-paren">(</span><em class="sig-param">resource</em>, <em class="sig-param">limits</em><span class="sig-paren">)</span><a class="headerlink" href="#resource.setrlimit" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>设置 <em>resource</em> 的新的消耗极限。参数 <em>limits</em> 必须是一个由两个整数组成的元组 <code class="docutils literal notranslate"><span class="pre">(soft,</span> <span class="pre">hard)</span></code> ,描述了新的限制。 <a class="reference internal" href="#resource.RLIM_INFINITY" title="resource.RLIM_INFINITY"><code class="xref py py-data docutils literal notranslate"><span class="pre">RLIM_INFINITY</span></code></a> 的值可以用来请求一个无限的限制。</p>
|
||
<p>如果指定了一个无效的资源,如果新的软限制超过了硬限制,或者如果一个进程试图提高它的硬限制,将触发 <a class="reference internal" href="exceptions.html#ValueError" title="ValueError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ValueError</span></code></a> 。当资源的硬限制或系统限制不是无限时,指定一个 <a class="reference internal" href="#resource.RLIM_INFINITY" title="resource.RLIM_INFINITY"><code class="xref py py-data docutils literal notranslate"><span class="pre">RLIM_INFINITY</span></code></a> 的限制将导致 <a class="reference internal" href="exceptions.html#ValueError" title="ValueError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ValueError</span></code></a> 。 一个有效 UID 为超级用户的进程可以请求任何有效的限制值,包括无限,但如果请求的限制超过了系统规定的限制,则仍然会产生 <a class="reference internal" href="exceptions.html#ValueError" title="ValueError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ValueError</span></code></a> 。</p>
|
||
<p>如果底层系统调用失败, <code class="docutils literal notranslate"><span class="pre">setrlimit</span></code> 也可能触发 <a class="reference internal" href="#resource.error" title="resource.error"><code class="xref py py-exc docutils literal notranslate"><span class="pre">error</span></code></a> 。</p>
|
||
<p>VxWorks只支持设置 <a class="reference internal" href="#resource.RLIMIT_NOFILE" title="resource.RLIMIT_NOFILE"><code class="xref py py-data docutils literal notranslate"><span class="pre">RLIMIT_NOFILE</span></code></a> 。</p>
|
||
<p class="audit-hook">引发一个 <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">审计事件</span></a> <code class="docutils literal notranslate"><span class="pre">resource.setrlimit</span></code> 并附带参数 <code class="docutils literal notranslate"><span class="pre">resource</span></code>, <code class="docutils literal notranslate"><span class="pre">limits</span></code>。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="resource.prlimit">
|
||
<code class="sig-prename descclassname">resource.</code><code class="sig-name descname">prlimit</code><span class="sig-paren">(</span><em class="sig-param">pid</em>, <em class="sig-param">resource</em><span class="optional">[</span>, <em class="sig-param">limits</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#resource.prlimit" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>将 <a class="reference internal" href="#resource.setrlimit" title="resource.setrlimit"><code class="xref py py-func docutils literal notranslate"><span class="pre">setrlimit()</span></code></a> 和 <a class="reference internal" href="#resource.getrlimit" title="resource.getrlimit"><code class="xref py py-func docutils literal notranslate"><span class="pre">getrlimit()</span></code></a> 合并为一个函数,支持获取和设置任意进程的资源限制。如果 <em>pid</em> 为0,那么该调用适用于当前进程。 <em>resource</em> 和 <em>limits</em> 的含义与 <a class="reference internal" href="#resource.setrlimit" title="resource.setrlimit"><code class="xref py py-func docutils literal notranslate"><span class="pre">setrlimit()</span></code></a> 相同,只是 <em>limits</em> 是可选的。</p>
|
||
<p>当 <em>limits</em> 没有给出时,该函数返回进程 <em>pid</em> 的 <em>resource</em> 限制。当 <em>limits</em> 被给定时,进程的 <em>resource</em> 限制被设置,并返回以前的资源限制。</p>
|
||
<p>当 <em>pid</em> 找不到时,触发 <a class="reference internal" href="exceptions.html#ProcessLookupError" title="ProcessLookupError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ProcessLookupError</span></code></a> ;当用户没有进程的 <code class="docutils literal notranslate"><span class="pre">CAP_SYS_RESOURCE</span></code> 时,触发 <a class="reference internal" href="exceptions.html#PermissionError" title="PermissionError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">PermissionError</span></code></a> 。</p>
|
||
<p class="audit-hook">引发一个 <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">审计事件</span></a> <code class="docutils literal notranslate"><span class="pre">resource.prlimit</span></code> 并附带参数 <code class="docutils literal notranslate"><span class="pre">pid</span></code>, <code class="docutils literal notranslate"><span class="pre">resource</span></code>, <code class="docutils literal notranslate"><span class="pre">limits</span></code>。</p>
|
||
<p class="availability"><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Linux 2.6.36 或更新版本带有 glibc 2.13 或更新版本</p>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">3.4 新版功能.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<p>这些符号定义了资源的消耗可以通过下面描述的 <a class="reference internal" href="#resource.setrlimit" title="resource.setrlimit"><code class="xref py py-func docutils literal notranslate"><span class="pre">setrlimit()</span></code></a> 和 <a class="reference internal" href="#resource.getrlimit" title="resource.getrlimit"><code class="xref py py-func docutils literal notranslate"><span class="pre">getrlimit()</span></code></a> 函数来控制。这些符号的值正是 C 程序所使用的常数。</p>
|
||
<p>Unix man 页面 <em class="manpage"><a class="manpage reference external" href="https://manpages.debian.org/getrlimit(2)">getrlimit(2)</a></em> 列出了可用的资源。注意,并非所有系统都使用相同的符号或相同的值来表示相同的资源。本模块并不试图掩盖平台的差异——没有为某一平台定义的符号在该平台上将无法从本模块中获得。</p>
|
||
<dl class="data">
|
||
<dt id="resource.RLIMIT_CORE">
|
||
<code class="sig-prename descclassname">resource.</code><code class="sig-name descname">RLIMIT_CORE</code><a class="headerlink" href="#resource.RLIMIT_CORE" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>当前进程可以创建的核心文件的最大大小(以字节为单位)。如果需要更大的核心文件来包含整个进程的镜像,这可能会导致创建一个部分核心文件。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="data">
|
||
<dt id="resource.RLIMIT_CPU">
|
||
<code class="sig-prename descclassname">resource.</code><code class="sig-name descname">RLIMIT_CPU</code><a class="headerlink" href="#resource.RLIMIT_CPU" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>一个进程可以使用的最大处理器时间(以秒为单位)。如果超过了这个限制,一个 <code class="xref py py-const docutils literal notranslate"><span class="pre">SIGXCPU</span></code> 信号将被发送给进程。(参见 <a class="reference internal" href="signal.html#module-signal" title="signal: Set handlers for asynchronous events."><code class="xref py py-mod docutils literal notranslate"><span class="pre">signal</span></code></a> 模块文档,了解如何捕捉这个信号并做一些有用的事情,例如,将打开的文件刷新到磁盘上)。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="data">
|
||
<dt id="resource.RLIMIT_FSIZE">
|
||
<code class="sig-prename descclassname">resource.</code><code class="sig-name descname">RLIMIT_FSIZE</code><a class="headerlink" href="#resource.RLIMIT_FSIZE" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>进程可能创建的文件的最大大小。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="data">
|
||
<dt id="resource.RLIMIT_DATA">
|
||
<code class="sig-prename descclassname">resource.</code><code class="sig-name descname">RLIMIT_DATA</code><a class="headerlink" href="#resource.RLIMIT_DATA" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>进程的堆的最大大小(以字节为单位)。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="data">
|
||
<dt id="resource.RLIMIT_STACK">
|
||
<code class="sig-prename descclassname">resource.</code><code class="sig-name descname">RLIMIT_STACK</code><a class="headerlink" href="#resource.RLIMIT_STACK" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>当前进程的调用堆栈的最大大小(字节)。 这只影响到多线程进程中主线程的堆栈。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="data">
|
||
<dt id="resource.RLIMIT_RSS">
|
||
<code class="sig-prename descclassname">resource.</code><code class="sig-name descname">RLIMIT_RSS</code><a class="headerlink" href="#resource.RLIMIT_RSS" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>应该提供给进程的最大常驻内存大小。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="data">
|
||
<dt id="resource.RLIMIT_NPROC">
|
||
<code class="sig-prename descclassname">resource.</code><code class="sig-name descname">RLIMIT_NPROC</code><a class="headerlink" href="#resource.RLIMIT_NPROC" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>当前进程可能创建的最大进程数。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="data">
|
||
<dt id="resource.RLIMIT_NOFILE">
|
||
<code class="sig-prename descclassname">resource.</code><code class="sig-name descname">RLIMIT_NOFILE</code><a class="headerlink" href="#resource.RLIMIT_NOFILE" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>当前进程打开的文件描述符的最大数量。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="data">
|
||
<dt id="resource.RLIMIT_OFILE">
|
||
<code class="sig-prename descclassname">resource.</code><code class="sig-name descname">RLIMIT_OFILE</code><a class="headerlink" href="#resource.RLIMIT_OFILE" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>BSD 对 <a class="reference internal" href="#resource.RLIMIT_NOFILE" title="resource.RLIMIT_NOFILE"><code class="xref py py-const docutils literal notranslate"><span class="pre">RLIMIT_NOFILE</span></code></a> 的命名。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="data">
|
||
<dt id="resource.RLIMIT_MEMLOCK">
|
||
<code class="sig-prename descclassname">resource.</code><code class="sig-name descname">RLIMIT_MEMLOCK</code><a class="headerlink" href="#resource.RLIMIT_MEMLOCK" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>可能被锁定在内存中的最大地址空间。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="data">
|
||
<dt id="resource.RLIMIT_VMEM">
|
||
<code class="sig-prename descclassname">resource.</code><code class="sig-name descname">RLIMIT_VMEM</code><a class="headerlink" href="#resource.RLIMIT_VMEM" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>进程可能占用的最大映射内存区域。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="data">
|
||
<dt id="resource.RLIMIT_AS">
|
||
<code class="sig-prename descclassname">resource.</code><code class="sig-name descname">RLIMIT_AS</code><a class="headerlink" href="#resource.RLIMIT_AS" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>进程可能占用的地址空间的最大区域(以字节为单位)。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="data">
|
||
<dt id="resource.RLIMIT_MSGQUEUE">
|
||
<code class="sig-prename descclassname">resource.</code><code class="sig-name descname">RLIMIT_MSGQUEUE</code><a class="headerlink" href="#resource.RLIMIT_MSGQUEUE" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>可分配给 POSIX 消息队列的字节数。</p>
|
||
<p class="availability"><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Linux 2.6.8 或更新版本。</p>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">3.4 新版功能.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="data">
|
||
<dt id="resource.RLIMIT_NICE">
|
||
<code class="sig-prename descclassname">resource.</code><code class="sig-name descname">RLIMIT_NICE</code><a class="headerlink" href="#resource.RLIMIT_NICE" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>进程的 Nice 级别的上限(计算为 20 - rlim_cur )。</p>
|
||
<p class="availability"><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Linux 2.6.12 或更新版本</p>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">3.4 新版功能.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="data">
|
||
<dt id="resource.RLIMIT_RTPRIO">
|
||
<code class="sig-prename descclassname">resource.</code><code class="sig-name descname">RLIMIT_RTPRIO</code><a class="headerlink" href="#resource.RLIMIT_RTPRIO" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>实时优先级的上限。</p>
|
||
<p class="availability"><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Linux 2.6.12 或更新版本</p>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">3.4 新版功能.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="data">
|
||
<dt id="resource.RLIMIT_RTTIME">
|
||
<code class="sig-prename descclassname">resource.</code><code class="sig-name descname">RLIMIT_RTTIME</code><a class="headerlink" href="#resource.RLIMIT_RTTIME" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>在实时调度下,一个进程在不进行阻塞性系统调用的情况下,可以花费的 CPU 时间限制(以微秒计)。</p>
|
||
<p class="availability"><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Linux 2.6.25 或更新版本</p>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">3.4 新版功能.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="data">
|
||
<dt id="resource.RLIMIT_SIGPENDING">
|
||
<code class="sig-prename descclassname">resource.</code><code class="sig-name descname">RLIMIT_SIGPENDING</code><a class="headerlink" href="#resource.RLIMIT_SIGPENDING" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>进程可能排队的信号数量。</p>
|
||
<p class="availability"><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Linux 2.6.8 或更新版本。</p>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">3.4 新版功能.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="data">
|
||
<dt id="resource.RLIMIT_SBSIZE">
|
||
<code class="sig-prename descclassname">resource.</code><code class="sig-name descname">RLIMIT_SBSIZE</code><a class="headerlink" href="#resource.RLIMIT_SBSIZE" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>这个用户使用的套接字缓冲区的最大大小(字节数)。这限制了这个用户在任何时候都可以持有的网络内存数量,因此也限制了 mbufs 的数量。</p>
|
||
<p class="availability"><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: FreeBSD 9 或更新版本</p>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">3.4 新版功能.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="data">
|
||
<dt id="resource.RLIMIT_SWAP">
|
||
<code class="sig-prename descclassname">resource.</code><code class="sig-name descname">RLIMIT_SWAP</code><a class="headerlink" href="#resource.RLIMIT_SWAP" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>这个用户 ID 的所有进程可能保留或使用的交换空间的最大大小(字节数)。这个限制只有在 vm.overcommit sysctl的第 1 位被置 1 时才会被强制执行。请参阅 <a class="reference external" href="https://www.freebsd.org/cgi/man.cgi?query=tuning&sektion=7">tuning(7)</a> 以获得关于这个系统检测器的完整介绍。</p>
|
||
<p class="availability"><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: FreeBSD 9 或更新版本</p>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">3.4 新版功能.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="data">
|
||
<dt id="resource.RLIMIT_NPTS">
|
||
<code class="sig-prename descclassname">resource.</code><code class="sig-name descname">RLIMIT_NPTS</code><a class="headerlink" href="#resource.RLIMIT_NPTS" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>该用户 ID 创建的伪终端的最大数量。</p>
|
||
<p class="availability"><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: FreeBSD 9 或更新版本</p>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">3.4 新版功能.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
</section>
|
||
<section id="resource-usage">
|
||
<h2>资源用量<a class="headerlink" href="#resource-usage" title="永久链接至标题">¶</a></h2>
|
||
<p>这些函数被用来检索资源使用信息。</p>
|
||
<dl class="function">
|
||
<dt id="resource.getrusage">
|
||
<code class="sig-prename descclassname">resource.</code><code class="sig-name descname">getrusage</code><span class="sig-paren">(</span><em class="sig-param">who</em><span class="sig-paren">)</span><a class="headerlink" href="#resource.getrusage" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>这个函数返回一个对象,描述当前进程或其子进程所消耗的资源,由 <em>who</em> 参数指定。 <em>who</em> 参数应该使用下面描述的 <code class="xref py py-const docutils literal notranslate"><span class="pre">RUSAGE_*</span></code> 常数之一来指定。</p>
|
||
<p>一个简单的示例:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">resource</span> <span class="kn">import</span> <span class="o">*</span>
|
||
<span class="kn">import</span> <span class="nn">time</span>
|
||
|
||
<span class="c1"># a non CPU-bound task</span>
|
||
<span class="n">time</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span>
|
||
<span class="nb">print</span><span class="p">(</span><span class="n">getrusage</span><span class="p">(</span><span class="n">RUSAGE_SELF</span><span class="p">))</span>
|
||
|
||
<span class="c1"># a CPU-bound task</span>
|
||
<span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">10</span> <span class="o">**</span> <span class="mi">8</span><span class="p">):</span>
|
||
<span class="n">_</span> <span class="o">=</span> <span class="mi">1</span> <span class="o">+</span> <span class="mi">1</span>
|
||
<span class="nb">print</span><span class="p">(</span><span class="n">getrusage</span><span class="p">(</span><span class="n">RUSAGE_SELF</span><span class="p">))</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>返回值的字段分别描述了某一特定系统资源的使用情况,例如,在用户模式下运行的时间或进程从主内存中换出的次数。有些值取决于内部的时钟周期,例如进程使用的内存量。</p>
|
||
<p>为了向后兼容,返回值也可以作为一个 16 个元素的元组来访问。</p>
|
||
<p>返回值中的 <code class="xref py py-attr docutils literal notranslate"><span class="pre">ru_utime</span></code> 和 <code class="xref py py-attr docutils literal notranslate"><span class="pre">ru_stime</span></code> 字段是浮点值,分别代表在用户模式下执行的时间和在系统模式下执行的时间。其余的值是整数。关于这些值的详细信息,请查阅 <em class="manpage"><a class="manpage reference external" href="https://manpages.debian.org/getrusage(2)">getrusage(2)</a></em> man page 。这里介绍一个简短的摘要。</p>
|
||
<table class="docutils align-default">
|
||
<colgroup>
|
||
<col style="width: 12%" />
|
||
<col style="width: 31%" />
|
||
<col style="width: 57%" />
|
||
</colgroup>
|
||
<thead>
|
||
<tr class="row-odd"><th class="head"><p>索引</p></th>
|
||
<th class="head"><p>域</p></th>
|
||
<th class="head"><p>资源</p></th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">0</span></code></p></td>
|
||
<td><p><code class="xref py py-attr docutils literal notranslate"><span class="pre">ru_utime</span></code></p></td>
|
||
<td><p>用户模式下的时间(浮点数秒)</p></td>
|
||
</tr>
|
||
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">1</span></code></p></td>
|
||
<td><p><code class="xref py py-attr docutils literal notranslate"><span class="pre">ru_stime</span></code></p></td>
|
||
<td><p>系统模式下的时间(浮点数秒)</p></td>
|
||
</tr>
|
||
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">2</span></code></p></td>
|
||
<td><p><code class="xref py py-attr docutils literal notranslate"><span class="pre">ru_maxrss</span></code></p></td>
|
||
<td><p>最大的常驻内存大小</p></td>
|
||
</tr>
|
||
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">3</span></code></p></td>
|
||
<td><p><code class="xref py py-attr docutils literal notranslate"><span class="pre">ru_ixrss</span></code></p></td>
|
||
<td><p>共享内存大小</p></td>
|
||
</tr>
|
||
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">4</span></code></p></td>
|
||
<td><p><code class="xref py py-attr docutils literal notranslate"><span class="pre">ru_idrss</span></code></p></td>
|
||
<td><p>未共享的内存大小</p></td>
|
||
</tr>
|
||
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">5</span></code></p></td>
|
||
<td><p><code class="xref py py-attr docutils literal notranslate"><span class="pre">ru_isrss</span></code></p></td>
|
||
<td><p>未共享的堆栈大小</p></td>
|
||
</tr>
|
||
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">6</span></code></p></td>
|
||
<td><p><code class="xref py py-attr docutils literal notranslate"><span class="pre">ru_minflt</span></code></p></td>
|
||
<td><p>不需要 I/O 的页面故障数</p></td>
|
||
</tr>
|
||
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">7</span></code></p></td>
|
||
<td><p><code class="xref py py-attr docutils literal notranslate"><span class="pre">ru_majflt</span></code></p></td>
|
||
<td><p>需要 I/O 的页面故障数</p></td>
|
||
</tr>
|
||
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">8</span></code></p></td>
|
||
<td><p><code class="xref py py-attr docutils literal notranslate"><span class="pre">ru_nswap</span></code></p></td>
|
||
<td><p>swap out 的数量</p></td>
|
||
</tr>
|
||
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">9</span></code></p></td>
|
||
<td><p><code class="xref py py-attr docutils literal notranslate"><span class="pre">ru_inblock</span></code></p></td>
|
||
<td><p>块输入操作数</p></td>
|
||
</tr>
|
||
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">10</span></code></p></td>
|
||
<td><p><code class="xref py py-attr docutils literal notranslate"><span class="pre">ru_oublock</span></code></p></td>
|
||
<td><p>块输出操作数</p></td>
|
||
</tr>
|
||
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">11</span></code></p></td>
|
||
<td><p><code class="xref py py-attr docutils literal notranslate"><span class="pre">ru_msgsnd</span></code></p></td>
|
||
<td><p>发送消息数</p></td>
|
||
</tr>
|
||
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">12</span></code></p></td>
|
||
<td><p><code class="xref py py-attr docutils literal notranslate"><span class="pre">ru_msgrcv</span></code></p></td>
|
||
<td><p>收到消息数</p></td>
|
||
</tr>
|
||
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">13</span></code></p></td>
|
||
<td><p><code class="xref py py-attr docutils literal notranslate"><span class="pre">ru_nsignals</span></code></p></td>
|
||
<td><p>收到信号数</p></td>
|
||
</tr>
|
||
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">14</span></code></p></td>
|
||
<td><p><code class="xref py py-attr docutils literal notranslate"><span class="pre">ru_nvcsw</span></code></p></td>
|
||
<td><p>主动上下文切换</p></td>
|
||
</tr>
|
||
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">15</span></code></p></td>
|
||
<td><p><code class="xref py py-attr docutils literal notranslate"><span class="pre">ru_nivcsw</span></code></p></td>
|
||
<td><p>被动上下文切换</p></td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
<p>如果指定了一个无效的 <em>who</em> 参数,这个函数将触发一个 <a class="reference internal" href="exceptions.html#ValueError" title="ValueError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ValueError</span></code></a> 。在特殊情况下,它也可能触发 <a class="reference internal" href="#resource.error" title="resource.error"><code class="xref py py-exc docutils literal notranslate"><span class="pre">error</span></code></a> 异常。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="resource.getpagesize">
|
||
<code class="sig-prename descclassname">resource.</code><code class="sig-name descname">getpagesize</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#resource.getpagesize" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>返回一个系统页面的字节数。(这不需要和硬件页的大小相同)。</p>
|
||
</dd></dl>
|
||
|
||
<p>下面的 <code class="xref py py-const docutils literal notranslate"><span class="pre">RUSAGE_*</span></code> 符号被传递给 <a class="reference internal" href="#resource.getrusage" title="resource.getrusage"><code class="xref py py-func docutils literal notranslate"><span class="pre">getrusage()</span></code></a> 函数,以指定应该为哪些进程提供信息。</p>
|
||
<dl class="data">
|
||
<dt id="resource.RUSAGE_SELF">
|
||
<code class="sig-prename descclassname">resource.</code><code class="sig-name descname">RUSAGE_SELF</code><a class="headerlink" href="#resource.RUSAGE_SELF" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>传递给 <a class="reference internal" href="#resource.getrusage" title="resource.getrusage"><code class="xref py py-func docutils literal notranslate"><span class="pre">getrusage()</span></code></a> 以请求调用进程消耗的资源,这是进程中所有线程使用的资源总和。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="data">
|
||
<dt id="resource.RUSAGE_CHILDREN">
|
||
<code class="sig-prename descclassname">resource.</code><code class="sig-name descname">RUSAGE_CHILDREN</code><a class="headerlink" href="#resource.RUSAGE_CHILDREN" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>传递给 <a class="reference internal" href="#resource.getrusage" title="resource.getrusage"><code class="xref py py-func docutils literal notranslate"><span class="pre">getrusage()</span></code></a> 以请求被终止和等待的调用进程的子进程所消耗的资源。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="data">
|
||
<dt id="resource.RUSAGE_BOTH">
|
||
<code class="sig-prename descclassname">resource.</code><code class="sig-name descname">RUSAGE_BOTH</code><a class="headerlink" href="#resource.RUSAGE_BOTH" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>传递给 <a class="reference internal" href="#resource.getrusage" title="resource.getrusage"><code class="xref py py-func docutils literal notranslate"><span class="pre">getrusage()</span></code></a> 以请求当前进程和子进程所消耗的资源。并非所有系统都能使用。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="data">
|
||
<dt id="resource.RUSAGE_THREAD">
|
||
<code class="sig-prename descclassname">resource.</code><code class="sig-name descname">RUSAGE_THREAD</code><a class="headerlink" href="#resource.RUSAGE_THREAD" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>传递给 <a class="reference internal" href="#resource.getrusage" title="resource.getrusage"><code class="xref py py-func docutils literal notranslate"><span class="pre">getrusage()</span></code></a> 以请求当前线程所消耗的资源。 并非所有系统都能使用。</p>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">3.2 新版功能.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
</section>
|
||
</section>
|
||
|
||
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
|
||
<div class="sphinxsidebarwrapper">
|
||
<h3><a href="../contents.html">目录</a></h3>
|
||
<ul>
|
||
<li><a class="reference internal" href="#"><code class="xref py py-mod docutils literal notranslate"><span class="pre">resource</span></code> --- 资源使用信息</a><ul>
|
||
<li><a class="reference internal" href="#resource-limits">资源限制</a></li>
|
||
<li><a class="reference internal" href="#resource-usage">资源用量</a></li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
|
||
<h4>上一个主题</h4>
|
||
<p class="topless"><a href="pipes.html"
|
||
title="上一章"><code class="xref py py-mod docutils literal notranslate"><span class="pre">pipes</span></code> --- 终端管道接口</a></p>
|
||
<h4>下一个主题</h4>
|
||
<p class="topless"><a href="nis.html"
|
||
title="下一章"><code class="xref py py-mod docutils literal notranslate"><span class="pre">nis</span></code> --- Sun 的 NIS (黄页) 接口</a></p>
|
||
<div role="note" aria-label="source link">
|
||
<h3>本页</h3>
|
||
<ul class="this-page-menu">
|
||
<li><a href="../bugs.html">报告 Bug</a></li>
|
||
<li>
|
||
<a href="https://github.com/python/cpython/blob/3.8/Doc/library/resource.rst"
|
||
rel="nofollow">显示源代码
|
||
</a>
|
||
</li>
|
||
</ul>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="clearer"></div>
|
||
</div>
|
||
<div class="related" role="navigation" aria-label="related navigation">
|
||
<h3>导航</h3>
|
||
<ul>
|
||
<li class="right" style="margin-right: 10px">
|
||
<a href="../genindex.html" title="总目录"
|
||
>索引</a></li>
|
||
<li class="right" >
|
||
<a href="../py-modindex.html" title="Python 模块索引"
|
||
>模块</a> |</li>
|
||
<li class="right" >
|
||
<a href="nis.html" title="nis --- Sun 的 NIS (黄页) 接口"
|
||
>下一页</a> |</li>
|
||
<li class="right" >
|
||
<a href="pipes.html" title="pipes --- 终端管道接口"
|
||
>上一页</a> |</li>
|
||
|
||
<li><img src="../_static/py.svg" alt="python logo" style="vertical-align: middle; margin-top: -1px"/></li>
|
||
<li><a href="https://www.python.org/">Python</a> »</li>
|
||
<li class="switchers">
|
||
<div class="language_switcher_placeholder"></div>
|
||
<div class="version_switcher_placeholder"></div>
|
||
</li>
|
||
<li>
|
||
|
||
</li>
|
||
<li id="cpython-language-and-version">
|
||
<a href="../index.html">3.8.20 Documentation</a> »
|
||
</li>
|
||
|
||
<li class="nav-item nav-item-1"><a href="index.html" >Python 标准库</a> »</li>
|
||
<li class="nav-item nav-item-2"><a href="unix.html" >Unix 专有服务</a> »</li>
|
||
<li class="right">
|
||
|
||
|
||
<div class="inline-search" role="search">
|
||
<form class="inline-search" action="../search.html" method="get">
|
||
<input placeholder="快速搜索" aria-label="快速搜索" type="text" name="q" />
|
||
<input type="submit" value="转向" />
|
||
<input type="hidden" name="check_keywords" value="yes" />
|
||
<input type="hidden" name="area" value="default" />
|
||
</form>
|
||
</div>
|
||
|
|
||
</li>
|
||
|
||
</ul>
|
||
</div>
|
||
<div class="footer">
|
||
© <a href="../copyright.html">版权所有</a> 2001-2024, Python Software Foundation.
|
||
<br />
|
||
This page is licensed under the Python Software Foundation License Version 2.
|
||
<br />
|
||
Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.
|
||
<br />
|
||
|
||
<br />
|
||
|
||
The Python Software Foundation is a non-profit corporation.
|
||
<a href="https://www.python.org/psf/donations/">Please donate.</a>
|
||
<br />
|
||
<br />
|
||
|
||
最后更新于 12月 09, 2024.
|
||
<a href="https://docs.python.org/3/bugs.html">Found a bug</a>?
|
||
<br />
|
||
|
||
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 2.4.4.
|
||
</div>
|
||
|
||
</body>
|
||
</html> |