blob: 06bab04aaafb3d282650daa513d4e164fc0e695a [file] [log] [blame]
Georg Brandl116aa622007-08-15 14:28:22 +00001:mod:`posix` --- The most common POSIX system calls
2===================================================
3
4.. module:: posix
5 :platform: Unix
6 :synopsis: The most common POSIX system calls (normally used via module os).
7
8
9This module provides access to operating system functionality that is
10standardized by the C Standard and the POSIX standard (a thinly disguised Unix
11interface).
12
13.. index:: module: os
14
15**Do not import this module directly.** Instead, import the module :mod:`os`,
16which provides a *portable* version of this interface. On Unix, the :mod:`os`
17module provides a superset of the :mod:`posix` interface. On non-Unix operating
18systems the :mod:`posix` module is not available, but a subset is always
19available through the :mod:`os` interface. Once :mod:`os` is imported, there is
20*no* performance penalty in using it instead of :mod:`posix`. In addition,
21:mod:`os` provides some additional functionality, such as automatically calling
Serhiy Storchakadab83542013-10-13 20:12:43 +030022:func:`~os.putenv` when an entry in ``os.environ`` is changed.
Georg Brandl116aa622007-08-15 14:28:22 +000023
Georg Brandl116aa622007-08-15 14:28:22 +000024Errors are reported as exceptions; the usual exceptions are given for type
Christian Heimesa62da1d2008-01-12 19:39:10 +000025errors, while errors reported by the system calls raise :exc:`OSError`.
Georg Brandl116aa622007-08-15 14:28:22 +000026
27
28.. _posix-large-files:
29
30Large File Support
31------------------
32
33.. index::
34 single: large files
35 single: file; large files
36
37.. sectionauthor:: Steve Clift <clift@mail.anacapa.net>
38
Christian Heimesa62da1d2008-01-12 19:39:10 +000039Several operating systems (including AIX, HP-UX, Irix and Solaris) provide
Serhiy Storchakaf8def282013-02-16 17:29:56 +020040support for files that are larger than 2 GiB from a C programming model where
Georg Brandl60203b42010-10-06 10:11:56 +000041:c:type:`int` and :c:type:`long` are 32-bit values. This is typically accomplished
Georg Brandl116aa622007-08-15 14:28:22 +000042by defining the relevant size and offset types as 64-bit values. Such files are
43sometimes referred to as :dfn:`large files`.
44
Georg Brandl60203b42010-10-06 10:11:56 +000045Large file support is enabled in Python when the size of an :c:type:`off_t` is
46larger than a :c:type:`long` and the :c:type:`long long` type is available and is
47at least as large as an :c:type:`off_t`.
Georg Brandl116aa622007-08-15 14:28:22 +000048It may be necessary to configure and compile Python with certain compiler flags
49to enable this mode. For example, it is enabled by default with recent versions
50of Irix, but with Solaris 2.6 and 2.7 you need to do something like::
51
52 CFLAGS="`getconf LFS_CFLAGS`" OPT="-g -O2 $CFLAGS" \
53 ./configure
54
Georg Brandl81ac1ce2007-08-31 17:17:17 +000055On large-file-capable Linux systems, this might work::
Georg Brandl116aa622007-08-15 14:28:22 +000056
57 CFLAGS='-D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64' OPT="-g -O2 $CFLAGS" \
58 ./configure
59
Georg Brandl116aa622007-08-15 14:28:22 +000060
61.. _posix-contents:
62
Christian Heimesa62da1d2008-01-12 19:39:10 +000063Notable Module Contents
64-----------------------
Georg Brandl116aa622007-08-15 14:28:22 +000065
Christian Heimesa62da1d2008-01-12 19:39:10 +000066In addition to many functions described in the :mod:`os` module documentation,
67:mod:`posix` defines the following data item:
Georg Brandl116aa622007-08-15 14:28:22 +000068
69.. data:: environ
70
Christian Heimesa62da1d2008-01-12 19:39:10 +000071 A dictionary representing the string environment at the time the interpreter
Victor Stinner84ae1182010-05-06 22:05:07 +000072 was started. Keys and values are bytes on Unix and str on Windows. For
73 example, ``environ[b'HOME']`` (``environ['HOME']`` on Windows) is the
74 pathname of your home directory, equivalent to ``getenv("HOME")`` in C.
Georg Brandl116aa622007-08-15 14:28:22 +000075
76 Modifying this dictionary does not affect the string environment passed on by
Serhiy Storchakadab83542013-10-13 20:12:43 +030077 :func:`~os.execv`, :func:`~os.popen` or :func:`~os.system`; if you need to
78 change the environment, pass ``environ`` to :func:`~os.execve` or add
79 variable assignments and export statements to the command string for
80 :func:`~os.system` or :func:`~os.popen`.
Georg Brandl116aa622007-08-15 14:28:22 +000081
Victor Stinner84ae1182010-05-06 22:05:07 +000082 .. versionchanged:: 3.2
83 On Unix, keys and values are bytes.
84
Georg Brandl116aa622007-08-15 14:28:22 +000085 .. note::
86
Victor Stinner84ae1182010-05-06 22:05:07 +000087 The :mod:`os` module provides an alternate implementation of ``environ``
88 which updates the environment on modification. Note also that updating
89 :data:`os.environ` will render this dictionary obsolete. Use of the
90 :mod:`os` module version of this is recommended over direct access to the
91 :mod:`posix` module.