gooderp18绿色标准版
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

402 line
24KB

  1. <!DOCTYPE html>
  2. <html lang="en" data-content_root="../">
  3. <head>
  4. <meta charset="utf-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />
  6. <meta property="og:title" content="posix — The most common POSIX system calls" />
  7. <meta property="og:type" content="website" />
  8. <meta property="og:url" content="https://docs.python.org/3/library/posix.html" />
  9. <meta property="og:site_name" content="Python documentation" />
  10. <meta property="og:description" content="This module provides access to operating system functionality that is standardized by the C Standard and the POSIX standard (a thinly disguised Unix interface). Availability: Unix. Do not import th..." />
  11. <meta property="og:image" content="https://docs.python.org/3/_static/og-image.png" />
  12. <meta property="og:image:alt" content="Python documentation" />
  13. <meta name="description" content="This module provides access to operating system functionality that is standardized by the C Standard and the POSIX standard (a thinly disguised Unix interface). Availability: Unix. Do not import th..." />
  14. <meta property="og:image:width" content="200" />
  15. <meta property="og:image:height" content="200" />
  16. <meta name="theme-color" content="#3776ab" />
  17. <title>posix — The most common POSIX system calls &#8212; Python 3.12.3 documentation</title><meta name="viewport" content="width=device-width, initial-scale=1.0">
  18. <link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=80d5e7a1" />
  19. <link rel="stylesheet" type="text/css" href="../_static/pydoctheme.css?v=bb723527" />
  20. <link id="pygments_dark_css" media="(prefers-color-scheme: dark)" rel="stylesheet" type="text/css" href="../_static/pygments_dark.css?v=b20cc3f5" />
  21. <script src="../_static/documentation_options.js?v=2c828074"></script>
  22. <script src="../_static/doctools.js?v=888ff710"></script>
  23. <script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
  24. <script src="../_static/sidebar.js"></script>
  25. <link rel="search" type="application/opensearchdescription+xml"
  26. title="Search within Python 3.12.3 documentation"
  27. href="../_static/opensearch.xml"/>
  28. <link rel="author" title="About these documents" href="../about.html" />
  29. <link rel="index" title="Index" href="../genindex.html" />
  30. <link rel="search" title="Search" href="../search.html" />
  31. <link rel="copyright" title="Copyright" href="../copyright.html" />
  32. <link rel="next" title="pwd — The password database" href="pwd.html" />
  33. <link rel="prev" title="Unix Specific Services" href="unix.html" />
  34. <link rel="canonical" href="https://docs.python.org/3/library/posix.html" />
  35. <style>
  36. @media only screen {
  37. table.full-width-table {
  38. width: 100%;
  39. }
  40. }
  41. </style>
  42. <link rel="stylesheet" href="../_static/pydoctheme_dark.css" media="(prefers-color-scheme: dark)" id="pydoctheme_dark_css">
  43. <link rel="shortcut icon" type="image/png" href="../_static/py.svg" />
  44. <script type="text/javascript" src="../_static/copybutton.js"></script>
  45. <script type="text/javascript" src="../_static/menu.js"></script>
  46. <script type="text/javascript" src="../_static/search-focus.js"></script>
  47. <script type="text/javascript" src="../_static/themetoggle.js"></script>
  48. </head>
  49. <body>
  50. <div class="mobile-nav">
  51. <input type="checkbox" id="menuToggler" class="toggler__input" aria-controls="navigation"
  52. aria-pressed="false" aria-expanded="false" role="button" aria-label="Menu" />
  53. <nav class="nav-content" role="navigation">
  54. <label for="menuToggler" class="toggler__label">
  55. <span></span>
  56. </label>
  57. <span class="nav-items-wrapper">
  58. <a href="https://www.python.org/" class="nav-logo">
  59. <img src="../_static/py.svg" alt="Python logo"/>
  60. </a>
  61. <span class="version_switcher_placeholder"></span>
  62. <form role="search" class="search" action="../search.html" method="get">
  63. <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" class="search-icon">
  64. <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>
  65. </svg>
  66. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" />
  67. <input type="submit" value="Go"/>
  68. </form>
  69. </span>
  70. </nav>
  71. <div class="menu-wrapper">
  72. <nav class="menu" role="navigation" aria-label="main navigation">
  73. <div class="language_switcher_placeholder"></div>
  74. <label class="theme-selector-label">
  75. Theme
  76. <select class="theme-selector" oninput="activateTheme(this.value)">
  77. <option value="auto" selected>Auto</option>
  78. <option value="light">Light</option>
  79. <option value="dark">Dark</option>
  80. </select>
  81. </label>
  82. <div>
  83. <h3><a href="../contents.html">Table of Contents</a></h3>
  84. <ul>
  85. <li><a class="reference internal" href="#"><code class="xref py py-mod docutils literal notranslate"><span class="pre">posix</span></code> — The most common POSIX system calls</a><ul>
  86. <li><a class="reference internal" href="#large-file-support">Large File Support</a></li>
  87. <li><a class="reference internal" href="#notable-module-contents">Notable Module Contents</a></li>
  88. </ul>
  89. </li>
  90. </ul>
  91. </div>
  92. <div>
  93. <h4>Previous topic</h4>
  94. <p class="topless"><a href="unix.html"
  95. title="previous chapter">Unix Specific Services</a></p>
  96. </div>
  97. <div>
  98. <h4>Next topic</h4>
  99. <p class="topless"><a href="pwd.html"
  100. title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">pwd</span></code> — The password database</a></p>
  101. </div>
  102. <div role="note" aria-label="source link">
  103. <h3>This Page</h3>
  104. <ul class="this-page-menu">
  105. <li><a href="../bugs.html">Report a Bug</a></li>
  106. <li>
  107. <a href="https://github.com/python/cpython/blob/main/Doc/library/posix.rst"
  108. rel="nofollow">Show Source
  109. </a>
  110. </li>
  111. </ul>
  112. </div>
  113. </nav>
  114. </div>
  115. </div>
  116. <div class="related" role="navigation" aria-label="related navigation">
  117. <h3>Navigation</h3>
  118. <ul>
  119. <li class="right" style="margin-right: 10px">
  120. <a href="../genindex.html" title="General Index"
  121. accesskey="I">index</a></li>
  122. <li class="right" >
  123. <a href="../py-modindex.html" title="Python Module Index"
  124. >modules</a> |</li>
  125. <li class="right" >
  126. <a href="pwd.html" title="pwd — The password database"
  127. accesskey="N">next</a> |</li>
  128. <li class="right" >
  129. <a href="unix.html" title="Unix Specific Services"
  130. accesskey="P">previous</a> |</li>
  131. <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  132. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  133. <li class="switchers">
  134. <div class="language_switcher_placeholder"></div>
  135. <div class="version_switcher_placeholder"></div>
  136. </li>
  137. <li>
  138. </li>
  139. <li id="cpython-language-and-version">
  140. <a href="../index.html">3.12.3 Documentation</a> &#187;
  141. </li>
  142. <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>
  143. <li class="nav-item nav-item-2"><a href="unix.html" accesskey="U">Unix Specific Services</a> &#187;</li>
  144. <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">posix</span></code> — The most common POSIX system calls</a></li>
  145. <li class="right">
  146. <div class="inline-search" role="search">
  147. <form class="inline-search" action="../search.html" method="get">
  148. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  149. <input type="submit" value="Go" />
  150. </form>
  151. </div>
  152. |
  153. </li>
  154. <li class="right">
  155. <label class="theme-selector-label">
  156. Theme
  157. <select class="theme-selector" oninput="activateTheme(this.value)">
  158. <option value="auto" selected>Auto</option>
  159. <option value="light">Light</option>
  160. <option value="dark">Dark</option>
  161. </select>
  162. </label> |</li>
  163. </ul>
  164. </div>
  165. <div class="document">
  166. <div class="documentwrapper">
  167. <div class="bodywrapper">
  168. <div class="body" role="main">
  169. <section id="module-posix">
  170. <span id="posix-the-most-common-posix-system-calls"></span><h1><a class="reference internal" href="#module-posix" title="posix: The most common POSIX system calls (normally used via module os). (Unix)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">posix</span></code></a> — The most common POSIX system calls<a class="headerlink" href="#module-posix" title="Link to this heading">¶</a></h1>
  171. <hr class="docutils" />
  172. <p>This module provides access to operating system functionality that is
  173. standardized by the C Standard and the POSIX standard (a thinly disguised Unix
  174. interface).</p>
  175. <div class="availability docutils container">
  176. <p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix.</p>
  177. </div>
  178. <p id="index-0"><strong>Do not import this module directly.</strong> Instead, import the module <a class="reference internal" href="os.html#module-os" title="os: Miscellaneous operating system interfaces."><code class="xref py py-mod docutils literal notranslate"><span class="pre">os</span></code></a>,
  179. which provides a <em>portable</em> version of this interface. On Unix, the <a class="reference internal" href="os.html#module-os" title="os: Miscellaneous operating system interfaces."><code class="xref py py-mod docutils literal notranslate"><span class="pre">os</span></code></a>
  180. module provides a superset of the <a class="reference internal" href="#module-posix" title="posix: The most common POSIX system calls (normally used via module os). (Unix)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">posix</span></code></a> interface. On non-Unix operating
  181. systems the <a class="reference internal" href="#module-posix" title="posix: The most common POSIX system calls (normally used via module os). (Unix)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">posix</span></code></a> module is not available, but a subset is always
  182. available through the <a class="reference internal" href="os.html#module-os" title="os: Miscellaneous operating system interfaces."><code class="xref py py-mod docutils literal notranslate"><span class="pre">os</span></code></a> interface. Once <a class="reference internal" href="os.html#module-os" title="os: Miscellaneous operating system interfaces."><code class="xref py py-mod docutils literal notranslate"><span class="pre">os</span></code></a> is imported, there is
  183. <em>no</em> performance penalty in using it instead of <a class="reference internal" href="#module-posix" title="posix: The most common POSIX system calls (normally used via module os). (Unix)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">posix</span></code></a>. In addition,
  184. <a class="reference internal" href="os.html#module-os" title="os: Miscellaneous operating system interfaces."><code class="xref py py-mod docutils literal notranslate"><span class="pre">os</span></code></a> provides some additional functionality, such as automatically calling
  185. <a class="reference internal" href="os.html#os.putenv" title="os.putenv"><code class="xref py py-func docutils literal notranslate"><span class="pre">putenv()</span></code></a> when an entry in <code class="docutils literal notranslate"><span class="pre">os.environ</span></code> is changed.</p>
  186. <p>Errors are reported as exceptions; the usual exceptions are given for type
  187. errors, while errors reported by the system calls raise <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>
  188. <section id="large-file-support">
  189. <span id="posix-large-files"></span><h2>Large File Support<a class="headerlink" href="#large-file-support" title="Link to this heading">¶</a></h2>
  190. <p id="index-1">Several operating systems (including AIX and Solaris) provide
  191. support for files that are larger than 2 GiB from a C programming model where
  192. <span class="c-expr sig sig-inline c"><span class="kt">int</span></span> and <span class="c-expr sig sig-inline c"><span class="kt">long</span></span> are 32-bit values. This is typically accomplished
  193. by defining the relevant size and offset types as 64-bit values. Such files are
  194. sometimes referred to as <em class="dfn">large files</em>.</p>
  195. <p>Large file support is enabled in Python when the size of an <code class="xref c c-type docutils literal notranslate"><span class="pre">off_t</span></code> is
  196. larger than a <span class="c-expr sig sig-inline c"><span class="kt">long</span></span> and the <span class="c-expr sig sig-inline c"><span class="kt">long</span><span class="w"> </span><span class="kt">long</span></span> is at least as large
  197. as an <code class="xref c c-type docutils literal notranslate"><span class="pre">off_t</span></code>.
  198. It may be necessary to configure and compile Python with certain compiler flags
  199. to enable this mode. For example, with Solaris 2.6 and 2.7 you need to do
  200. something like:</p>
  201. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">CFLAGS</span><span class="o">=</span><span class="s2">&quot;`getconf LFS_CFLAGS`&quot;</span> <span class="n">OPT</span><span class="o">=</span><span class="s2">&quot;-g -O2 $CFLAGS&quot;</span> \
  202. <span class="o">./</span><span class="n">configure</span>
  203. </pre></div>
  204. </div>
  205. <p>On large-file-capable Linux systems, this might work:</p>
  206. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">CFLAGS</span><span class="o">=</span><span class="s1">&#39;-D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64&#39;</span> <span class="n">OPT</span><span class="o">=</span><span class="s2">&quot;-g -O2 $CFLAGS&quot;</span> \
  207. <span class="o">./</span><span class="n">configure</span>
  208. </pre></div>
  209. </div>
  210. </section>
  211. <section id="notable-module-contents">
  212. <span id="posix-contents"></span><h2>Notable Module Contents<a class="headerlink" href="#notable-module-contents" title="Link to this heading">¶</a></h2>
  213. <p>In addition to many functions described in the <a class="reference internal" href="os.html#module-os" title="os: Miscellaneous operating system interfaces."><code class="xref py py-mod docutils literal notranslate"><span class="pre">os</span></code></a> module documentation,
  214. <a class="reference internal" href="#module-posix" title="posix: The most common POSIX system calls (normally used via module os). (Unix)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">posix</span></code></a> defines the following data item:</p>
  215. <dl class="py data">
  216. <dt class="sig sig-object py" id="posix.environ">
  217. <span class="sig-prename descclassname"><span class="pre">posix.</span></span><span class="sig-name descname"><span class="pre">environ</span></span><a class="headerlink" href="#posix.environ" title="Link to this definition">¶</a></dt>
  218. <dd><p>A dictionary representing the string environment at the time the interpreter
  219. was started. Keys and values are bytes on Unix and str on Windows. For
  220. example, <code class="docutils literal notranslate"><span class="pre">environ[b'HOME']</span></code> (<code class="docutils literal notranslate"><span class="pre">environ['HOME']</span></code> on Windows) is the
  221. pathname of your home directory, equivalent to <code class="docutils literal notranslate"><span class="pre">getenv(&quot;HOME&quot;)</span></code> in C.</p>
  222. <p>Modifying this dictionary does not affect the string environment passed on by
  223. <a class="reference internal" href="os.html#os.execv" title="os.execv"><code class="xref py py-func docutils literal notranslate"><span class="pre">execv()</span></code></a>, <a class="reference internal" href="os.html#os.popen" title="os.popen"><code class="xref py py-func docutils literal notranslate"><span class="pre">popen()</span></code></a> or <a class="reference internal" href="os.html#os.system" title="os.system"><code class="xref py py-func docutils literal notranslate"><span class="pre">system()</span></code></a>; if you need to
  224. change the environment, pass <code class="docutils literal notranslate"><span class="pre">environ</span></code> to <a class="reference internal" href="os.html#os.execve" title="os.execve"><code class="xref py py-func docutils literal notranslate"><span class="pre">execve()</span></code></a> or add
  225. variable assignments and export statements to the command string for
  226. <a class="reference internal" href="os.html#os.system" title="os.system"><code class="xref py py-func docutils literal notranslate"><span class="pre">system()</span></code></a> or <a class="reference internal" href="os.html#os.popen" title="os.popen"><code class="xref py py-func docutils literal notranslate"><span class="pre">popen()</span></code></a>.</p>
  227. <div class="versionchanged">
  228. <p><span class="versionmodified changed">Changed in version 3.2: </span>On Unix, keys and values are bytes.</p>
  229. </div>
  230. <div class="admonition note">
  231. <p class="admonition-title">Note</p>
  232. <p>The <a class="reference internal" href="os.html#module-os" title="os: Miscellaneous operating system interfaces."><code class="xref py py-mod docutils literal notranslate"><span class="pre">os</span></code></a> module provides an alternate implementation of <code class="docutils literal notranslate"><span class="pre">environ</span></code>
  233. which updates the environment on modification. Note also that updating
  234. <a class="reference internal" href="os.html#os.environ" title="os.environ"><code class="xref py py-data docutils literal notranslate"><span class="pre">os.environ</span></code></a> will render this dictionary obsolete. Use of the
  235. <a class="reference internal" href="os.html#module-os" title="os: Miscellaneous operating system interfaces."><code class="xref py py-mod docutils literal notranslate"><span class="pre">os</span></code></a> module version of this is recommended over direct access to the
  236. <a class="reference internal" href="#module-posix" title="posix: The most common POSIX system calls (normally used via module os). (Unix)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">posix</span></code></a> module.</p>
  237. </div>
  238. </dd></dl>
  239. </section>
  240. </section>
  241. <div class="clearer"></div>
  242. </div>
  243. </div>
  244. </div>
  245. <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
  246. <div class="sphinxsidebarwrapper">
  247. <div>
  248. <h3><a href="../contents.html">Table of Contents</a></h3>
  249. <ul>
  250. <li><a class="reference internal" href="#"><code class="xref py py-mod docutils literal notranslate"><span class="pre">posix</span></code> — The most common POSIX system calls</a><ul>
  251. <li><a class="reference internal" href="#large-file-support">Large File Support</a></li>
  252. <li><a class="reference internal" href="#notable-module-contents">Notable Module Contents</a></li>
  253. </ul>
  254. </li>
  255. </ul>
  256. </div>
  257. <div>
  258. <h4>Previous topic</h4>
  259. <p class="topless"><a href="unix.html"
  260. title="previous chapter">Unix Specific Services</a></p>
  261. </div>
  262. <div>
  263. <h4>Next topic</h4>
  264. <p class="topless"><a href="pwd.html"
  265. title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">pwd</span></code> — The password database</a></p>
  266. </div>
  267. <div role="note" aria-label="source link">
  268. <h3>This Page</h3>
  269. <ul class="this-page-menu">
  270. <li><a href="../bugs.html">Report a Bug</a></li>
  271. <li>
  272. <a href="https://github.com/python/cpython/blob/main/Doc/library/posix.rst"
  273. rel="nofollow">Show Source
  274. </a>
  275. </li>
  276. </ul>
  277. </div>
  278. </div>
  279. <div id="sidebarbutton" title="Collapse sidebar">
  280. <span>«</span>
  281. </div>
  282. </div>
  283. <div class="clearer"></div>
  284. </div>
  285. <div class="related" role="navigation" aria-label="related navigation">
  286. <h3>Navigation</h3>
  287. <ul>
  288. <li class="right" style="margin-right: 10px">
  289. <a href="../genindex.html" title="General Index"
  290. >index</a></li>
  291. <li class="right" >
  292. <a href="../py-modindex.html" title="Python Module Index"
  293. >modules</a> |</li>
  294. <li class="right" >
  295. <a href="pwd.html" title="pwd — The password database"
  296. >next</a> |</li>
  297. <li class="right" >
  298. <a href="unix.html" title="Unix Specific Services"
  299. >previous</a> |</li>
  300. <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  301. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  302. <li class="switchers">
  303. <div class="language_switcher_placeholder"></div>
  304. <div class="version_switcher_placeholder"></div>
  305. </li>
  306. <li>
  307. </li>
  308. <li id="cpython-language-and-version">
  309. <a href="../index.html">3.12.3 Documentation</a> &#187;
  310. </li>
  311. <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>
  312. <li class="nav-item nav-item-2"><a href="unix.html" >Unix Specific Services</a> &#187;</li>
  313. <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">posix</span></code> — The most common POSIX system calls</a></li>
  314. <li class="right">
  315. <div class="inline-search" role="search">
  316. <form class="inline-search" action="../search.html" method="get">
  317. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  318. <input type="submit" value="Go" />
  319. </form>
  320. </div>
  321. |
  322. </li>
  323. <li class="right">
  324. <label class="theme-selector-label">
  325. Theme
  326. <select class="theme-selector" oninput="activateTheme(this.value)">
  327. <option value="auto" selected>Auto</option>
  328. <option value="light">Light</option>
  329. <option value="dark">Dark</option>
  330. </select>
  331. </label> |</li>
  332. </ul>
  333. </div>
  334. <div class="footer">
  335. &copy;
  336. <a href="../copyright.html">
  337. Copyright
  338. </a>
  339. 2001-2024, Python Software Foundation.
  340. <br />
  341. This page is licensed under the Python Software Foundation License Version 2.
  342. <br />
  343. Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.
  344. <br />
  345. See <a href="/license.html">History and License</a> for more information.<br />
  346. <br />
  347. The Python Software Foundation is a non-profit corporation.
  348. <a href="https://www.python.org/psf/donations/">Please donate.</a>
  349. <br />
  350. <br />
  351. Last updated on Apr 09, 2024 (13:47 UTC).
  352. <a href="/bugs.html">Found a bug</a>?
  353. <br />
  354. Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 7.2.6.
  355. </div>
  356. </body>
  357. </html>
上海开阖软件有限公司 沪ICP备12045867号-1