parthtamu/rag-code-assistant
0
1<!DOCTYPE html>2 3<html lang="en" data-content_root="../">4 <head>5 <meta charset="utf-8" />6 <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />7<meta property="og:title" content="resource — Resource usage information" />8<meta property="og:type" content="website" />9<meta property="og:url" content="https://docs.python.org/3/library/resource.html" />10<meta property="og:site_name" content="Python documentation" />11<meta property="og:description" content="This module provides basic mechanisms for measuring and controlling system resources utilized by a program. Availability: Unix, not WASI. Symbolic constants are used to specify particular system re..." />12<meta property="og:image:width" content="1146" />13<meta property="og:image:height" content="600" />14<meta property="og:image" content="https://docs.python.org/3.15/_images/social_previews/summary_library_resource_cdbcea50.png" />15<meta property="og:image:alt" content="This module provides basic mechanisms for measuring and controlling system resources utilized by a program. Availability: Unix, not WASI. Symbolic constants are used to specify particular system re..." />16<meta name="description" content="This module provides basic mechanisms for measuring and controlling system resources utilized by a program. Availability: Unix, not WASI. Symbolic constants are used to specify particular system re..." />17<meta name="twitter:card" content="summary_large_image" />18<meta name="theme-color" content="#3776ab">19 20 <title>resource — Resource usage information — Python 3.15.0a6 documentation</title><meta name="viewport" content="width=device-width, initial-scale=1.0">21 22 <link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=b86133f3" />23 <link rel="stylesheet" type="text/css" href="../_static/classic.css?v=234b1a7c" />24 <link rel="stylesheet" type="text/css" href="../_static/pydoctheme.css?v=89a2f22a" />25 <link rel="stylesheet" type="text/css" href="../_static/profiling-sampling-visualization.css?v=0c2600ae" />26 <link id="pygments_dark_css" media="(prefers-color-scheme: dark)" rel="stylesheet" type="text/css" href="../_static/pygments_dark.css?v=5349f25f" />27 28 <script src="../_static/documentation_options.js?v=6b7c9ff5"></script>29 <script src="../_static/doctools.js?v=9bcbadda"></script>30 <script src="../_static/sphinx_highlight.js?v=dc90522c"></script>31 <script src="../_static/profiling-sampling-visualization.js?v=9811ed04"></script>32 33 <script src="../_static/sidebar.js"></script>34 35 <link rel="search" type="application/opensearchdescription+xml"36 title="Search within Python 3.15.0a6 documentation"37 href="../_static/opensearch.xml"/>38 <link rel="author" title="About these documents" href="../about.html" />39 <link rel="index" title="Index" href="../genindex.html" />40 <link rel="search" title="Search" href="../search.html" />41 <link rel="copyright" title="Copyright" href="../copyright.html" />42 <link rel="next" title="syslog — Unix syslog library routines" href="syslog.html" />43 <link rel="prev" title="fcntl — The fcntl and ioctl system calls" href="fcntl.html" />44 45 46 <script defer file-types="bz2,epub,zip" data-domain="docs.python.org" src="https://analytics.python.org/js/script.file-downloads.outbound-links.js"></script>47 48 <link rel="canonical" href="https://docs.python.org/3/library/resource.html">49 50 51 52 53 <style>54 @media only screen {55 table.full-width-table {56 width: 100%;57 }58 }59 </style>60<link rel="stylesheet" href="../_static/pydoctheme_dark.css" media="(prefers-color-scheme: dark)" id="pydoctheme_dark_css">61 <link rel="shortcut icon" type="image/png" href="../_static/py.svg">62 <script type="text/javascript" src="../_static/copybutton.js"></script>63 <script type="text/javascript" src="../_static/menu.js"></script>64 <script type="text/javascript" src="../_static/search-focus.js"></script>65 <script type="text/javascript" src="../_static/themetoggle.js"></script> 66 <script type="text/javascript" src="../_static/rtd_switcher.js"></script>67 <meta name="readthedocs-addons-api-version" content="1">68 69 </head>70<body>71<div class="mobile-nav">72 <input type="checkbox" id="menuToggler" class="toggler__input" aria-controls="navigation"73 aria-pressed="false" aria-expanded="false" role="button" aria-label="Menu">74 <nav class="nav-content" role="navigation">75 <label for="menuToggler" class="toggler__label">76 <span></span>77 </label>78 <span class="nav-items-wrapper">79 <a href="https://www.python.org/" class="nav-logo">80 <img src="../_static/py.svg" alt="Python logo">81 </a>82 <span class="version_switcher_placeholder"></span>83 <form role="search" class="search" action="../search.html" method="get">84 <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" class="search-icon">85 <path fill-rule="nonzero" fill="currentColor" 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"></path>86 </svg>87 <input placeholder="Quick search" aria-label="Quick search" type="search" name="q">88 <input type="submit" value="Go">89 </form>90 </span>91 </nav>92 <div class="menu-wrapper">93 <nav class="menu" role="navigation" aria-label="main navigation">94 <div class="language_switcher_placeholder"></div>95 96<label class="theme-selector-label">97 Theme98 <select class="theme-selector" oninput="activateTheme(this.value)">99 <option value="auto" selected>Auto</option>100 <option value="light">Light</option>101 <option value="dark">Dark</option>102 </select>103</label>104 <div>105 <h3><a href="../contents.html">Table of Contents</a></h3>106 <ul>107<li><a class="reference internal" href="#"><code class="xref py py-mod docutils literal notranslate"><span class="pre">resource</span></code> — Resource usage information</a><ul>108<li><a class="reference internal" href="#resource-limits">Resource Limits</a></li>109<li><a class="reference internal" href="#resource-usage">Resource Usage</a></li>110</ul>111</li>112</ul>113 114 </div>115 <div>116 <h4>Previous topic</h4>117 <p class="topless"><a href="fcntl.html"118 title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">fcntl</span></code> — The <code class="docutils literal notranslate"><span class="pre">fcntl</span></code> and <code class="docutils literal notranslate"><span class="pre">ioctl</span></code> system calls</a></p>119 </div>120 <div>121 <h4>Next topic</h4>122 <p class="topless"><a href="syslog.html"123 title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">syslog</span></code> — Unix syslog library routines</a></p>124 </div>125 <script>126 document.addEventListener('DOMContentLoaded', () => {127 const title = document.querySelector('meta[property="og:title"]').content;128 const elements = document.querySelectorAll('.improvepage');129 const pageurl = window.location.href.split('?')[0];130 elements.forEach(element => {131 const url = new URL(element.href.split('?')[0].replace("-nojs", ""));132 url.searchParams.set('pagetitle', title);133 url.searchParams.set('pageurl', pageurl);134 url.searchParams.set('pagesource', "library/resource.rst");135 element.href = url.toString();136 });137 });138 </script>139 <div role="note" aria-label="source link">140 <h3>This page</h3>141 <ul class="this-page-menu">142 <li><a href="../bugs.html">Report a bug</a></li>143 <li><a class="improvepage" href="../improve-page-nojs.html">Improve this page</a></li>144 <li>145 <a href="https://github.com/python/cpython/blob/main/Doc/library/resource.rst?plain=1"146 rel="nofollow">Show source147 </a>148 </li>149 150 </ul>151 </div>152 </nav>153 </div>154</div>155 156 157 <div class="related" role="navigation" aria-label="Related">158 <h3>Navigation</h3>159 <ul>160 <li class="right" style="margin-right: 10px">161 <a href="../genindex.html" title="General Index"162 accesskey="I">index</a></li>163 <li class="right" >164 <a href="../py-modindex.html" title="Python Module Index"165 >modules</a> |</li>166 <li class="right" >167 <a href="syslog.html" title="syslog — Unix syslog library routines"168 accesskey="N">next</a> |</li>169 <li class="right" >170 <a href="fcntl.html" title="fcntl — The fcntl and ioctl system calls"171 accesskey="P">previous</a> |</li>172 173 <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"></li>174 <li><a href="https://www.python.org/">Python</a> »</li>175 <li class="switchers">176 <div class="language_switcher_placeholder"></div>177 <div class="version_switcher_placeholder"></div>178 </li>179 <li>180 181 </li>182 <li id="cpython-language-and-version">183 <a href="../index.html">3.15.0a6 Documentation</a> »184 </li>185 186 <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> »</li>187 <li class="nav-item nav-item-2"><a href="unix.html" accesskey="U">Unix-specific services</a> »</li>188 <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">resource</span></code> — Resource usage information</a></li>189 <li class="right">190 191 192 <div class="inline-search" role="search">193 <form class="inline-search" action="../search.html" method="get">194 <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box">195 <input type="submit" value="Go">196 </form>197 </div>198 |199 </li>200 <li class="right">201<label class="theme-selector-label">202 Theme203 <select class="theme-selector" oninput="activateTheme(this.value)">204 <option value="auto" selected>Auto</option>205 <option value="light">Light</option>206 <option value="dark">Dark</option>207 </select>208</label> |</li>209 210 </ul>211 </div> 212 213 <div class="document">214 <div class="documentwrapper">215 <div class="bodywrapper">216 <div class="body" role="main">217 218 <section id="module-resource">219<span id="resource-resource-usage-information"></span><h1><code class="xref py py-mod docutils literal notranslate"><span class="pre">resource</span></code> — Resource usage information<a class="headerlink" href="#module-resource" title="Link to this heading">¶</a></h1>220<hr class="docutils" />221<p>This module provides basic mechanisms for measuring and controlling system222resources utilized by a program.</p>223<div class="availability docutils container">224<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not WASI.</p>225</div>226<p>Symbolic constants are used to specify particular system resources and to227request usage information about either the current process or its children.</p>228<p>An <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> is raised on syscall failure.</p>229<dl class="py exception">230<dt class="sig sig-object py" id="resource.error">231<em class="property"><span class="k"><span class="pre">exception</span></span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">resource.</span></span><span class="sig-name descname"><span class="pre">error</span></span><a class="headerlink" href="#resource.error" title="Link to this definition">¶</a></dt>232<dd><p>A deprecated alias of <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>233<div class="versionchanged">234<p><span class="versionmodified changed">Changed in version 3.3: </span>Following <span class="target" id="index-0"></span><a class="pep reference external" href="https://peps.python.org/pep-3151/"><strong>PEP 3151</strong></a>, this class was made an alias of <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>235</div>236</dd></dl>237 238<section id="resource-limits">239<h2>Resource Limits<a class="headerlink" href="#resource-limits" title="Link to this heading">¶</a></h2>240<p>Resources usage can be limited using the <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> function described241below. Each resource is controlled by a pair of limits: a soft limit and a hard242limit. The soft limit is the current limit, and may be lowered or raised by a243process over time. The soft limit can never exceed the hard limit. The hard244limit can be lowered to any value greater than the soft limit, but not raised.245(Only processes with the effective UID of the super-user can raise a hard246limit.)</p>247<p>The specific resources that can be limited are system dependent. They are248described in the <em class="manpage"><a class="manpage reference external" href="https://manpages.debian.org/getrlimit(2)">getrlimit(2)</a></em> man page. The resources listed below249are supported when the underlying operating system supports them; resources250which cannot be checked or controlled by the operating system are not defined in251this module for those platforms.</p>252<dl class="py data">253<dt class="sig sig-object py" id="resource.RLIM_INFINITY">254<span class="sig-prename descclassname"><span class="pre">resource.</span></span><span class="sig-name descname"><span class="pre">RLIM_INFINITY</span></span><a class="headerlink" href="#resource.RLIM_INFINITY" title="Link to this definition">¶</a></dt>255<dd><p>Constant used to represent the limit for an unlimited resource.</p>256<div class="versionchanged">257<p><span class="versionmodified changed">Changed in version 3.15: </span>It is now always positive.258Previously, it could be negative, such as -1 or -3.</p>259</div>260</dd></dl>261 262<dl class="py data">263<dt class="sig sig-object py" id="resource.RLIM_SAVED_CUR">264<span class="sig-prename descclassname"><span class="pre">resource.</span></span><span class="sig-name descname"><span class="pre">RLIM_SAVED_CUR</span></span><a class="headerlink" href="#resource.RLIM_SAVED_CUR" title="Link to this definition">¶</a></dt>265<dd></dd></dl>266 267<dl class="py data">268<dt class="sig sig-object py" id="resource.RLIM_SAVED_MAX">269<span class="sig-prename descclassname"><span class="pre">resource.</span></span><span class="sig-name descname"><span class="pre">RLIM_SAVED_MAX</span></span><a class="headerlink" href="#resource.RLIM_SAVED_MAX" title="Link to this definition">¶</a></dt>270<dd><p>Constants used to represent the soft and hard limit values if they271cannot be represented in the <code class="docutils literal notranslate"><span class="pre">rlim_t</span></code> value in C.272Can be equal to <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>273<div class="versionadded">274<p><span class="versionmodified added">Added in version 3.15.</span></p>275</div>276</dd></dl>277 278<dl class="py function">279<dt class="sig sig-object py" id="resource.getrlimit">280<span class="sig-prename descclassname"><span class="pre">resource.</span></span><span class="sig-name descname"><span class="pre">getrlimit</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">resource</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#resource.getrlimit" title="Link to this definition">¶</a></dt>281<dd><p>Returns a tuple <code class="docutils literal notranslate"><span class="pre">(soft,</span> <span class="pre">hard)</span></code> with the current soft and hard limits of282<em>resource</em>. Raises <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> if an invalid resource is specified, or283<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> if the underlying system call fails unexpectedly.</p>284</dd></dl>285 286<dl class="py function">287<dt class="sig sig-object py" id="resource.setrlimit">288<span class="sig-prename descclassname"><span class="pre">resource.</span></span><span class="sig-name descname"><span class="pre">setrlimit</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">resource</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">limits</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#resource.setrlimit" title="Link to this definition">¶</a></dt>289<dd><p>Sets new limits of consumption of <em>resource</em>. The <em>limits</em> argument must be a290tuple <code class="docutils literal notranslate"><span class="pre">(soft,</span> <span class="pre">hard)</span></code> of two integers describing the new limits. A value of291<a class="reference internal" href="#resource.RLIM_INFINITY" title="resource.RLIM_INFINITY"><code class="xref py py-const docutils literal notranslate"><span class="pre">RLIM_INFINITY</span></code></a> can be used to request a limit that is292unlimited.</p>293<p>Raises <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> if an invalid resource is specified, if the new soft294limit exceeds the hard limit, or if a process tries to raise its hard limit.295Specifying a limit of <a class="reference internal" href="#resource.RLIM_INFINITY" title="resource.RLIM_INFINITY"><code class="xref py py-const docutils literal notranslate"><span class="pre">RLIM_INFINITY</span></code></a> when the hard or296system limit for that resource is not unlimited will result in a297<code class="xref py py-exc docutils literal notranslate"><span class="pre">ValueError</span></code>. A process with the effective UID of super-user can298request any valid limit value, including unlimited, but <code class="xref py py-exc docutils literal notranslate"><span class="pre">ValueError</span></code>299will still be raised if the requested limit exceeds the system imposed300limit.</p>301<p><code class="docutils literal notranslate"><span class="pre">setrlimit</span></code> may also raise <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> if the underlying system call302fails.</p>303<p>VxWorks only supports setting <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>304<p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">resource.setrlimit</span></code> with arguments <code class="docutils literal notranslate"><span class="pre">resource</span></code>, <code class="docutils literal notranslate"><span class="pre">limits</span></code>.</p>305</dd></dl>306 307<dl class="py function">308<dt class="sig sig-object py" id="resource.prlimit">309<span class="sig-prename descclassname"><span class="pre">resource.</span></span><span class="sig-name descname"><span class="pre">prlimit</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">pid</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">resource</span></span></em><span class="optional">[</span>, <em class="sig-param"><span class="n"><span class="pre">limits</span></span></em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#resource.prlimit" title="Link to this definition">¶</a></dt>310<dd><p>Combines <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> and <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> in one function and311supports to get and set the resources limits of an arbitrary process. If312<em>pid</em> is 0, then the call applies to the current process. <em>resource</em> and313<em>limits</em> have the same meaning as in <code class="xref py py-func docutils literal notranslate"><span class="pre">setrlimit()</span></code>, except that314<em>limits</em> is optional.</p>315<p>When <em>limits</em> is not given the function returns the <em>resource</em> limit of the316process <em>pid</em>. When <em>limits</em> is given the <em>resource</em> limit of the process is317set and the former resource limit is returned.</p>318<p>Raises <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> when <em>pid</em> can’t be found and319<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> when the user doesn’t have <code class="docutils literal notranslate"><span class="pre">CAP_SYS_RESOURCE</span></code> for320the process.</p>321<p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">resource.prlimit</span></code> with arguments <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>322<div class="availability docutils container">323<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Linux >= 2.6.36 with glibc >= 2.13.</p>324</div>325<div class="versionadded">326<p><span class="versionmodified added">Added in version 3.4.</span></p>327</div>328</dd></dl>329 330<p>These symbols define resources whose consumption can be controlled using the331<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> and <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> functions described below. The values of332these symbols are exactly the constants used by C programs.</p>333<p>The Unix man page for <em class="manpage"><a class="manpage reference external" href="https://manpages.debian.org/getrlimit(2)">getrlimit(2)</a></em> lists the available resources.334Note that not all systems use the same symbol or same value to denote the same335resource. This module does not attempt to mask platform differences — symbols336not defined for a platform will not be available from this module on that337platform.</p>338<dl class="py data">339<dt class="sig sig-object py" id="resource.RLIMIT_CORE">340<span class="sig-prename descclassname"><span class="pre">resource.</span></span><span class="sig-name descname"><span class="pre">RLIMIT_CORE</span></span><a class="headerlink" href="#resource.RLIMIT_CORE" title="Link to this definition">¶</a></dt>341<dd><p>The maximum size (in bytes) of a core file that the current process can create.342This may result in the creation of a partial core file if a larger core would be343required to contain the entire process image.</p>344</dd></dl>345 346<dl class="py data">347<dt class="sig sig-object py" id="resource.RLIMIT_CPU">348<span class="sig-prename descclassname"><span class="pre">resource.</span></span><span class="sig-name descname"><span class="pre">RLIMIT_CPU</span></span><a class="headerlink" href="#resource.RLIMIT_CPU" title="Link to this definition">¶</a></dt>349<dd><p>The maximum amount of processor time (in seconds) that a process can use. If350this limit is exceeded, a <a class="reference internal" href="signal.html#signal.SIGXCPU" title="signal.SIGXCPU"><code class="xref py py-const docutils literal notranslate"><span class="pre">SIGXCPU</span></code></a> signal is sent to the process. (See351the <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> module documentation for information about how to catch this352signal and do something useful, e.g. flush open files to disk.)</p>353</dd></dl>354 355<dl class="py data">356<dt class="sig sig-object py" id="resource.RLIMIT_FSIZE">357<span class="sig-prename descclassname"><span class="pre">resource.</span></span><span class="sig-name descname"><span class="pre">RLIMIT_FSIZE</span></span><a class="headerlink" href="#resource.RLIMIT_FSIZE" title="Link to this definition">¶</a></dt>358<dd><p>The maximum size of a file which the process may create.</p>359</dd></dl>360 361<dl class="py data">362<dt class="sig sig-object py" id="resource.RLIMIT_DATA">363<span class="sig-prename descclassname"><span class="pre">resource.</span></span><span class="sig-name descname"><span class="pre">RLIMIT_DATA</span></span><a class="headerlink" href="#resource.RLIMIT_DATA" title="Link to this definition">¶</a></dt>364<dd><p>The maximum size (in bytes) of the process’s heap.</p>365</dd></dl>366 367<dl class="py data">368<dt class="sig sig-object py" id="resource.RLIMIT_STACK">369<span class="sig-prename descclassname"><span class="pre">resource.</span></span><span class="sig-name descname"><span class="pre">RLIMIT_STACK</span></span><a class="headerlink" href="#resource.RLIMIT_STACK" title="Link to this definition">¶</a></dt>370<dd><p>The maximum size (in bytes) of the call stack for the current process. This only371affects the stack of the main thread in a multi-threaded process.</p>372</dd></dl>373 374<dl class="py data">375<dt class="sig sig-object py" id="resource.RLIMIT_RSS">376<span class="sig-prename descclassname"><span class="pre">resource.</span></span><span class="sig-name descname"><span class="pre">RLIMIT_RSS</span></span><a class="headerlink" href="#resource.RLIMIT_RSS" title="Link to this definition">¶</a></dt>377<dd><p>The maximum resident set size that should be made available to the process.</p>378</dd></dl>379 380<dl class="py data">381<dt class="sig sig-object py" id="resource.RLIMIT_NPROC">382<span class="sig-prename descclassname"><span class="pre">resource.</span></span><span class="sig-name descname"><span class="pre">RLIMIT_NPROC</span></span><a class="headerlink" href="#resource.RLIMIT_NPROC" title="Link to this definition">¶</a></dt>383<dd><p>The maximum number of processes the current process may create.</p>384</dd></dl>385 386<dl class="py data">387<dt class="sig sig-object py" id="resource.RLIMIT_NOFILE">388<span class="sig-prename descclassname"><span class="pre">resource.</span></span><span class="sig-name descname"><span class="pre">RLIMIT_NOFILE</span></span><a class="headerlink" href="#resource.RLIMIT_NOFILE" title="Link to this definition">¶</a></dt>389<dd><p>The maximum number of open file descriptors for the current process.</p>390</dd></dl>391 392<dl class="py data">393<dt class="sig sig-object py" id="resource.RLIMIT_OFILE">394<span class="sig-prename descclassname"><span class="pre">resource.</span></span><span class="sig-name descname"><span class="pre">RLIMIT_OFILE</span></span><a class="headerlink" href="#resource.RLIMIT_OFILE" title="Link to this definition">¶</a></dt>395<dd><p>The BSD name for <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>396</dd></dl>397 398<dl class="py data">399<dt class="sig sig-object py" id="resource.RLIMIT_MEMLOCK">400<span class="sig-prename descclassname"><span class="pre">resource.</span></span><span class="sig-name descname"><span class="pre">RLIMIT_MEMLOCK</span></span><a class="headerlink" href="#resource.RLIMIT_MEMLOCK" title="Link to this definition">¶</a></dt>401<dd><p>The maximum address space which may be locked in memory.</p>402</dd></dl>403 404<dl class="py data">405<dt class="sig sig-object py" id="resource.RLIMIT_VMEM">406<span class="sig-prename descclassname"><span class="pre">resource.</span></span><span class="sig-name descname"><span class="pre">RLIMIT_VMEM</span></span><a class="headerlink" href="#resource.RLIMIT_VMEM" title="Link to this definition">¶</a></dt>407<dd><p>The largest area of mapped memory which the process may occupy.408Usually an alias of <a class="reference internal" href="#resource.RLIMIT_AS" title="resource.RLIMIT_AS"><code class="xref py py-const docutils literal notranslate"><span class="pre">RLIMIT_AS</span></code></a>.</p>409<div class="availability docutils container">410<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Solaris, FreeBSD, NetBSD.</p>411</div>412</dd></dl>413 414<dl class="py data">415<dt class="sig sig-object py" id="resource.RLIMIT_AS">416<span class="sig-prename descclassname"><span class="pre">resource.</span></span><span class="sig-name descname"><span class="pre">RLIMIT_AS</span></span><a class="headerlink" href="#resource.RLIMIT_AS" title="Link to this definition">¶</a></dt>417<dd><p>The maximum area (in bytes) of address space which may be taken by the process.</p>418</dd></dl>419 420<dl class="py data">421<dt class="sig sig-object py" id="resource.RLIMIT_MSGQUEUE">422<span class="sig-prename descclassname"><span class="pre">resource.</span></span><span class="sig-name descname"><span class="pre">RLIMIT_MSGQUEUE</span></span><a class="headerlink" href="#resource.RLIMIT_MSGQUEUE" title="Link to this definition">¶</a></dt>423<dd><p>The number of bytes that can be allocated for POSIX message queues.</p>424<div class="availability docutils container">425<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Linux >= 2.6.8.</p>426</div>427<div class="versionadded">428<p><span class="versionmodified added">Added in version 3.4.</span></p>429</div>430</dd></dl>431 432<dl class="py data">433<dt class="sig sig-object py" id="resource.RLIMIT_NICE">434<span class="sig-prename descclassname"><span class="pre">resource.</span></span><span class="sig-name descname"><span class="pre">RLIMIT_NICE</span></span><a class="headerlink" href="#resource.RLIMIT_NICE" title="Link to this definition">¶</a></dt>435<dd><p>The ceiling for the process’s nice level (calculated as 20 - rlim_cur).</p>436<div class="availability docutils container">437<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Linux >= 2.6.12.</p>438</div>439<div class="versionadded">440<p><span class="versionmodified added">Added in version 3.4.</span></p>441</div>442</dd></dl>443 444<dl class="py data">445<dt class="sig sig-object py" id="resource.RLIMIT_RTPRIO">446<span class="sig-prename descclassname"><span class="pre">resource.</span></span><span class="sig-name descname"><span class="pre">RLIMIT_RTPRIO</span></span><a class="headerlink" href="#resource.RLIMIT_RTPRIO" title="Link to this definition">¶</a></dt>447<dd><p>The ceiling of the real-time priority.</p>448<div class="availability docutils container">449<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Linux >= 2.6.12.</p>450</div>451<div class="versionadded">452<p><span class="versionmodified added">Added in version 3.4.</span></p>453</div>454</dd></dl>455 456<dl class="py data">457<dt class="sig sig-object py" id="resource.RLIMIT_RTTIME">458<span class="sig-prename descclassname"><span class="pre">resource.</span></span><span class="sig-name descname"><span class="pre">RLIMIT_RTTIME</span></span><a class="headerlink" href="#resource.RLIMIT_RTTIME" title="Link to this definition">¶</a></dt>459<dd><p>The time limit (in microseconds) on CPU time that a process can spend460under real-time scheduling without making a blocking syscall.</p>461<div class="availability docutils container">462<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Linux >= 2.6.25.</p>463</div>464<div class="versionadded">465<p><span class="versionmodified added">Added in version 3.4.</span></p>466</div>467</dd></dl>468 469<dl class="py data">470<dt class="sig sig-object py" id="resource.RLIMIT_SIGPENDING">471<span class="sig-prename descclassname"><span class="pre">resource.</span></span><span class="sig-name descname"><span class="pre">RLIMIT_SIGPENDING</span></span><a class="headerlink" href="#resource.RLIMIT_SIGPENDING" title="Link to this definition">¶</a></dt>472<dd><p>The number of signals which the process may queue.</p>473<div class="availability docutils container">474<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Linux >= 2.6.8.</p>475</div>476<div class="versionadded">477<p><span class="versionmodified added">Added in version 3.4.</span></p>478</div>479</dd></dl>480 481<dl class="py data">482<dt class="sig sig-object py" id="resource.RLIMIT_SBSIZE">483<span class="sig-prename descclassname"><span class="pre">resource.</span></span><span class="sig-name descname"><span class="pre">RLIMIT_SBSIZE</span></span><a class="headerlink" href="#resource.RLIMIT_SBSIZE" title="Link to this definition">¶</a></dt>484<dd><p>The maximum size (in bytes) of socket buffer usage for this user.485This limits the amount of network memory, and hence the amount of mbufs,486that this user may hold at any time.</p>487<div class="availability docutils container">488<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: FreeBSD, NetBSD.</p>489</div>490<div class="versionadded">491<p><span class="versionmodified added">Added in version 3.4.</span></p>492</div>493</dd></dl>494 495<dl class="py data">496<dt class="sig sig-object py" id="resource.RLIMIT_SWAP">497<span class="sig-prename descclassname"><span class="pre">resource.</span></span><span class="sig-name descname"><span class="pre">RLIMIT_SWAP</span></span><a class="headerlink" href="#resource.RLIMIT_SWAP" title="Link to this definition">¶</a></dt>498<dd><p>The maximum size (in bytes) of the swap space that may be reserved or499used by all of this user id’s processes.500This limit is enforced only if bit 1 of the vm.overcommit sysctl is set.501Please see502<a class="reference external" href="https://man.freebsd.org/cgi/man.cgi?query=tuning&sektion=7">tuning(7)</a>503for a complete description of this sysctl.</p>504<div class="availability docutils container">505<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: FreeBSD >= 8.</p>506</div>507<div class="versionadded">508<p><span class="versionmodified added">Added in version 3.4.</span></p>509</div>510</dd></dl>511 512<dl class="py data">513<dt class="sig sig-object py" id="resource.RLIMIT_NPTS">514<span class="sig-prename descclassname"><span class="pre">resource.</span></span><span class="sig-name descname"><span class="pre">RLIMIT_NPTS</span></span><a class="headerlink" href="#resource.RLIMIT_NPTS" title="Link to this definition">¶</a></dt>515<dd><p>The maximum number of pseudo-terminals created by this user id.</p>516<div class="availability docutils container">517<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: FreeBSD >= 8.</p>518</div>519<div class="versionadded">520<p><span class="versionmodified added">Added in version 3.4.</span></p>521</div>522</dd></dl>523 524<dl class="py data">525<dt class="sig sig-object py" id="resource.RLIMIT_KQUEUES">526<span class="sig-prename descclassname"><span class="pre">resource.</span></span><span class="sig-name descname"><span class="pre">RLIMIT_KQUEUES</span></span><a class="headerlink" href="#resource.RLIMIT_KQUEUES" title="Link to this definition">¶</a></dt>527<dd><p>The maximum number of kqueues this user id is allowed to create.</p>528<div class="availability docutils container">529<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: FreeBSD >= 11.</p>530</div>531<div class="versionadded">532<p><span class="versionmodified added">Added in version 3.10.</span></p>533</div>534</dd></dl>535 536<dl class="py data">537<dt class="sig sig-object py" id="resource.RLIMIT_NTHR">538<span class="sig-prename descclassname"><span class="pre">resource.</span></span><span class="sig-name descname"><span class="pre">RLIMIT_NTHR</span></span><a class="headerlink" href="#resource.RLIMIT_NTHR" title="Link to this definition">¶</a></dt>539<dd><p>The maximum number of threads for this user id, not counting the main540and kernel threads.</p>541<div class="availability docutils container">542<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: NetBSD >= 7.0.</p>543</div>544<div class="versionadded">545<p><span class="versionmodified added">Added in version 3.15.</span></p>546</div>547</dd></dl>548 549<dl class="py data">550<dt class="sig sig-object py" id="resource.RLIMIT_PIPEBUF">551<span class="sig-prename descclassname"><span class="pre">resource.</span></span><span class="sig-name descname"><span class="pre">RLIMIT_PIPEBUF</span></span><a class="headerlink" href="#resource.RLIMIT_PIPEBUF" title="Link to this definition">¶</a></dt>552<dd><p>The maximum total size of in-kernel buffers for bi-directional pipes/fifos553that this user id is allowed to consume.</p>554<div class="availability docutils container">555<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: FreeBSD >= 14.2.</p>556</div>557<div class="versionadded">558<p><span class="versionmodified added">Added in version 3.15.</span></p>559</div>560</dd></dl>561 562<dl class="py data">563<dt class="sig sig-object py" id="resource.RLIMIT_THREADS">564<span class="sig-prename descclassname"><span class="pre">resource.</span></span><span class="sig-name descname"><span class="pre">RLIMIT_THREADS</span></span><a class="headerlink" href="#resource.RLIMIT_THREADS" title="Link to this definition">¶</a></dt>565<dd><p>The maximum number of threads each process can create.</p>566<div class="availability docutils container">567<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: AIX.</p>568</div>569<div class="versionadded">570<p><span class="versionmodified added">Added in version 3.15.</span></p>571</div>572</dd></dl>573 574<dl class="py data">575<dt class="sig sig-object py" id="resource.RLIMIT_UMTXP">576<span class="sig-prename descclassname"><span class="pre">resource.</span></span><span class="sig-name descname"><span class="pre">RLIMIT_UMTXP</span></span><a class="headerlink" href="#resource.RLIMIT_UMTXP" title="Link to this definition">¶</a></dt>577<dd><p>The limit of the number of process-shared Posix thread library objects578allocated by user id.</p>579<div class="availability docutils container">580<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: FreeBSD >= 11.</p>581</div>582<div class="versionadded">583<p><span class="versionmodified added">Added in version 3.15.</span></p>584</div>585</dd></dl>586 587</section>588<section id="resource-usage">589<h2>Resource Usage<a class="headerlink" href="#resource-usage" title="Link to this heading">¶</a></h2>590<p>These functions are used to retrieve resource usage information:</p>591<dl class="py function">592<dt class="sig sig-object py" id="resource.getrusage">593<span class="sig-prename descclassname"><span class="pre">resource.</span></span><span class="sig-name descname"><span class="pre">getrusage</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">who</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#resource.getrusage" title="Link to this definition">¶</a></dt>594<dd><p>This function returns an object that describes the resources consumed by either595the current process or its children, as specified by the <em>who</em> parameter. The596<em>who</em> parameter should be specified using one of the <code class="xref py py-const docutils literal notranslate"><span class="pre">RUSAGE_*</span></code>597constants described below.</p>598<p>A simple example:</p>599<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span><span class="w"> </span><span class="nn">resource</span><span class="w"> </span><span class="kn">import</span> <span class="o">*</span>600<span class="kn">import</span><span class="w"> </span><span class="nn">time</span>601 602<span class="c1"># a non CPU-bound task</span>603<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>604<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>605 606<span class="c1"># a CPU-bound task</span>607<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>608 <span class="n">_</span> <span class="o">=</span> <span class="mi">1</span> <span class="o">+</span> <span class="mi">1</span>609<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>610</pre></div>611</div>612<p>The fields of the return value each describe how a particular system resource613has been used, e.g. amount of time spent running in user mode or number of times614the process was swapped out of main memory. Some values are dependent on the615clock tick interval, e.g. the amount of memory the process is using.</p>616<p>For backward compatibility, the return value is also accessible as a tuple of 16617elements.</p>618<p>The fields <code class="xref py py-attr docutils literal notranslate"><span class="pre">ru_utime</span></code> and <code class="xref py py-attr docutils literal notranslate"><span class="pre">ru_stime</span></code> of the return value are619floating-point values representing the amount of time spent executing in user620mode and the amount of time spent executing in system mode, respectively. The621remaining values are integers. Consult the <em class="manpage"><a class="manpage reference external" href="https://manpages.debian.org/getrusage(2)">getrusage(2)</a></em> man page for622detailed information about these values. A brief summary is presented here:</p>623<table class="docutils align-default">624<thead>625<tr class="row-odd"><th class="head"><p>Index</p></th>626<th class="head"><p>Field</p></th>627<th class="head"><p>Resource</p></th>628</tr>629</thead>630<tbody>631<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">0</span></code></p></td>632<td><p><code class="xref py py-attr docutils literal notranslate"><span class="pre">ru_utime</span></code></p></td>633<td><p>time in user mode (float seconds)</p></td>634</tr>635<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">1</span></code></p></td>636<td><p><code class="xref py py-attr docutils literal notranslate"><span class="pre">ru_stime</span></code></p></td>637<td><p>time in system mode (float seconds)</p></td>638</tr>639<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">2</span></code></p></td>640<td><p><code class="xref py py-attr docutils literal notranslate"><span class="pre">ru_maxrss</span></code></p></td>641<td><p>maximum resident set size</p></td>642</tr>643<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">3</span></code></p></td>644<td><p><code class="xref py py-attr docutils literal notranslate"><span class="pre">ru_ixrss</span></code></p></td>645<td><p>shared memory size</p></td>646</tr>647<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">4</span></code></p></td>648<td><p><code class="xref py py-attr docutils literal notranslate"><span class="pre">ru_idrss</span></code></p></td>649<td><p>unshared memory size</p></td>650</tr>651<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">5</span></code></p></td>652<td><p><code class="xref py py-attr docutils literal notranslate"><span class="pre">ru_isrss</span></code></p></td>653<td><p>unshared stack size</p></td>654</tr>655<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">6</span></code></p></td>656<td><p><code class="xref py py-attr docutils literal notranslate"><span class="pre">ru_minflt</span></code></p></td>657<td><p>page faults not requiring I/O</p></td>658</tr>659<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">7</span></code></p></td>660<td><p><code class="xref py py-attr docutils literal notranslate"><span class="pre">ru_majflt</span></code></p></td>661<td><p>page faults requiring I/O</p></td>662</tr>663<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">8</span></code></p></td>664<td><p><code class="xref py py-attr docutils literal notranslate"><span class="pre">ru_nswap</span></code></p></td>665<td><p>number of swap outs</p></td>666</tr>667<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">9</span></code></p></td>668<td><p><code class="xref py py-attr docutils literal notranslate"><span class="pre">ru_inblock</span></code></p></td>669<td><p>block input operations</p></td>670</tr>671<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">10</span></code></p></td>672<td><p><code class="xref py py-attr docutils literal notranslate"><span class="pre">ru_oublock</span></code></p></td>673<td><p>block output operations</p></td>674</tr>675<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">11</span></code></p></td>676<td><p><code class="xref py py-attr docutils literal notranslate"><span class="pre">ru_msgsnd</span></code></p></td>677<td><p>messages sent</p></td>678</tr>679<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">12</span></code></p></td>680<td><p><code class="xref py py-attr docutils literal notranslate"><span class="pre">ru_msgrcv</span></code></p></td>681<td><p>messages received</p></td>682</tr>683<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">13</span></code></p></td>684<td><p><code class="xref py py-attr docutils literal notranslate"><span class="pre">ru_nsignals</span></code></p></td>685<td><p>signals received</p></td>686</tr>687<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">14</span></code></p></td>688<td><p><code class="xref py py-attr docutils literal notranslate"><span class="pre">ru_nvcsw</span></code></p></td>689<td><p>voluntary context switches</p></td>690</tr>691<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">15</span></code></p></td>692<td><p><code class="xref py py-attr docutils literal notranslate"><span class="pre">ru_nivcsw</span></code></p></td>693<td><p>involuntary context switches</p></td>694</tr>695</tbody>696</table>697<p>This function will raise 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> if an invalid <em>who</em> parameter is698specified. It may also raise <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> exception in unusual circumstances.</p>699</dd></dl>700 701<dl class="py function">702<dt class="sig sig-object py" id="resource.getpagesize">703<span class="sig-prename descclassname"><span class="pre">resource.</span></span><span class="sig-name descname"><span class="pre">getpagesize</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#resource.getpagesize" title="Link to this definition">¶</a></dt>704<dd><p>Returns the number of bytes in a system page. (This need not be the same as the705hardware page size.)</p>706</dd></dl>707 708<p>The following <code class="xref py py-const docutils literal notranslate"><span class="pre">RUSAGE_*</span></code> symbols are passed to the <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>709function to specify which processes information should be provided for.</p>710<dl class="py data">711<dt class="sig sig-object py" id="resource.RUSAGE_SELF">712<span class="sig-prename descclassname"><span class="pre">resource.</span></span><span class="sig-name descname"><span class="pre">RUSAGE_SELF</span></span><a class="headerlink" href="#resource.RUSAGE_SELF" title="Link to this definition">¶</a></dt>713<dd><p>Pass to <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> to request resources consumed by the calling714process, which is the sum of resources used by all threads in the process.</p>715</dd></dl>716 717<dl class="py data">718<dt class="sig sig-object py" id="resource.RUSAGE_CHILDREN">719<span class="sig-prename descclassname"><span class="pre">resource.</span></span><span class="sig-name descname"><span class="pre">RUSAGE_CHILDREN</span></span><a class="headerlink" href="#resource.RUSAGE_CHILDREN" title="Link to this definition">¶</a></dt>720<dd><p>Pass to <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> to request resources consumed by child processes721of the calling process which have been terminated and waited for.</p>722</dd></dl>723 724<dl class="py data">725<dt class="sig sig-object py" id="resource.RUSAGE_BOTH">726<span class="sig-prename descclassname"><span class="pre">resource.</span></span><span class="sig-name descname"><span class="pre">RUSAGE_BOTH</span></span><a class="headerlink" href="#resource.RUSAGE_BOTH" title="Link to this definition">¶</a></dt>727<dd><p>Pass to <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> to request resources consumed by both the current728process and child processes. May not be available on all systems.</p>729</dd></dl>730 731<dl class="py data">732<dt class="sig sig-object py" id="resource.RUSAGE_THREAD">733<span class="sig-prename descclassname"><span class="pre">resource.</span></span><span class="sig-name descname"><span class="pre">RUSAGE_THREAD</span></span><a class="headerlink" href="#resource.RUSAGE_THREAD" title="Link to this definition">¶</a></dt>734<dd><p>Pass to <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> to request resources consumed by the current735thread. May not be available on all systems.</p>736<div class="versionadded">737<p><span class="versionmodified added">Added in version 3.2.</span></p>738</div>739</dd></dl>740 741</section>742</section>743 744 745 <div class="clearer"></div>746 </div>747 </div>748 </div>749 <div class="sphinxsidebar" role="navigation" aria-label="Main">750 <div class="sphinxsidebarwrapper">751 <div>752 <h3><a href="../contents.html">Table of Contents</a></h3>753 <ul>754<li><a class="reference internal" href="#"><code class="xref py py-mod docutils literal notranslate"><span class="pre">resource</span></code> — Resource usage information</a><ul>755<li><a class="reference internal" href="#resource-limits">Resource Limits</a></li>756<li><a class="reference internal" href="#resource-usage">Resource Usage</a></li>757</ul>758</li>759</ul>760 761 </div>762 <div>763 <h4>Previous topic</h4>764 <p class="topless"><a href="fcntl.html"765 title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">fcntl</span></code> — The <code class="docutils literal notranslate"><span class="pre">fcntl</span></code> and <code class="docutils literal notranslate"><span class="pre">ioctl</span></code> system calls</a></p>766 </div>767 <div>768 <h4>Next topic</h4>769 <p class="topless"><a href="syslog.html"770 title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">syslog</span></code> — Unix syslog library routines</a></p>771 </div>772 <script>773 document.addEventListener('DOMContentLoaded', () => {774 const title = document.querySelector('meta[property="og:title"]').content;775 const elements = document.querySelectorAll('.improvepage');776 const pageurl = window.location.href.split('?')[0];777 elements.forEach(element => {778 const url = new URL(element.href.split('?')[0].replace("-nojs", ""));779 url.searchParams.set('pagetitle', title);780 url.searchParams.set('pageurl', pageurl);781 url.searchParams.set('pagesource', "library/resource.rst");782 element.href = url.toString();783 });784 });785 </script>786 <div role="note" aria-label="source link">787 <h3>This page</h3>788 <ul class="this-page-menu">789 <li><a href="../bugs.html">Report a bug</a></li>790 <li><a class="improvepage" href="../improve-page-nojs.html">Improve this page</a></li>791 <li>792 <a href="https://github.com/python/cpython/blob/main/Doc/library/resource.rst?plain=1"793 rel="nofollow">Show source794 </a>795 </li>796 797 </ul>798 </div>799 </div>800<div id="sidebarbutton" title="Collapse sidebar">801<span>«</span>802</div>803 804 </div>805 <div class="clearer"></div>806 </div> 807 <div class="related" role="navigation" aria-label="Related">808 <h3>Navigation</h3>809 <ul>810 <li class="right" style="margin-right: 10px">811 <a href="../genindex.html" title="General Index"812 >index</a></li>813 <li class="right" >814 <a href="../py-modindex.html" title="Python Module Index"815 >modules</a> |</li>816 <li class="right" >817 <a href="syslog.html" title="syslog — Unix syslog library routines"818 >next</a> |</li>819 <li class="right" >820 <a href="fcntl.html" title="fcntl — The fcntl and ioctl system calls"821 >previous</a> |</li>822 823 <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"></li>824 <li><a href="https://www.python.org/">Python</a> »</li>825 <li class="switchers">826 <div class="language_switcher_placeholder"></div>827 <div class="version_switcher_placeholder"></div>828 </li>829 <li>830 831 </li>832 <li id="cpython-language-and-version">833 <a href="../index.html">3.15.0a6 Documentation</a> »834 </li>835 836 <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> »</li>837 <li class="nav-item nav-item-2"><a href="unix.html" >Unix-specific services</a> »</li>838 <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">resource</span></code> — Resource usage information</a></li>839 <li class="right">840 841 842 <div class="inline-search" role="search">843 <form class="inline-search" action="../search.html" method="get">844 <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box">845 <input type="submit" value="Go">846 </form>847 </div>848 |849 </li>850 <li class="right">851<label class="theme-selector-label">852 Theme853 <select class="theme-selector" oninput="activateTheme(this.value)">854 <option value="auto" selected>Auto</option>855 <option value="light">Light</option>856 <option value="dark">Dark</option>857 </select>858</label> |</li>859 860 </ul>861 </div> 862 <div class="footer">863 © <a href="../copyright.html">Copyright</a> 2001 Python Software Foundation.864 <br>865 This page is licensed under the Python Software Foundation License Version 2.866 <br>867 Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.868 <br>869 870 See <a href="/license.html">History and License</a> for more information.<br>871 872 873 <br>874 875 The Python Software Foundation is a non-profit corporation.876<a href="https://www.python.org/psf/donations/">Please donate.</a>877<br>878 <br>879 Last updated on Mar 10, 2026 (08:58 UTC).880 881 <a href="/bugs.html">Found a bug</a>?882 883 <br>884 885 Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 8.2.3.886 </div>887 888 </body>889</html>