Lines Matching +full:unix +full:- +full:like
1 :mod:`os` --- Miscellaneous operating system interfaces
9 --------------
16 module, and for high-level file and directory handling see the :mod:`shutil`
21 * The design of all built-in operating system dependent modules of Python is
37 * On WebAssembly platforms ``wasm32-emscripten`` and ``wasm32-wasi``, large
41 (e.g. :func:`~os.nice`) are not available. Others like :func:`~os.getuid`
53 An alias for the built-in :exc:`OSError` exception.
64 system-dependent version information.
70 .. _os-filenames:
71 .. _filesystem-encoding:
74 -------------------------------------------------------------
103 .. _utf8-mode:
105 Python UTF-8 Mode
106 -----------------
111 The Python UTF-8 Mode ignores the :term:`locale encoding` and forces the usage
112 of the UTF-8 encoding:
114 * Use UTF-8 as the :term:`filesystem encoding <filesystem encoding and error
116 * :func:`sys.getfilesystemencoding()` returns ``'utf-8'``.
117 * :func:`locale.getpreferredencoding()` returns ``'utf-8'`` (the *do_setlocale*
120 UTF-8 as their text encoding, with the ``surrogateescape``
121 :ref:`error handler <error-handlers>` being enabled for :data:`sys.stdin`
123 ``backslashreplace`` as it does in the default locale-aware mode)
124 * On Unix, :func:`os.device_encoding` returns ``'utf-8'`` rather than the
127 Note that the standard stream settings in UTF-8 mode can be overridden by
128 :envvar:`PYTHONIOENCODING` (just as they can be in the default locale-aware
135 to text using the UTF-8 encoding.
136 * :func:`os.fsdecode()` and :func:`os.fsencode()` use the UTF-8 encoding.
137 * :func:`open()`, :func:`io.open()`, and :func:`codecs.open()` use the UTF-8
142 The :ref:`Python UTF-8 Mode <utf8-mode>` is enabled if the LC_CTYPE locale is
146 It can be enabled or disabled using the :option:`-X utf8 <-X>` command line
151 locale is identified as a legacy ASCII-based locale (as described for
153 fails. In such legacy locales, the interpreter will default to enabling UTF-8
156 The Python UTF-8 Mode can only be enabled at the Python startup. Its value
159 See also the :ref:`UTF-8 mode on Windows <win-utf8-mode>`
165 Python 3.15 will make :ref:`utf8-mode` default.
168 .. _os-procinfo:
171 ------------------
181 .. availability:: Unix, not Emscripten, not WASI.
200 On Unix, keys and values use :func:`sys.getfilesystemencoding` and
201 ``'surrogateescape'`` error handler. Use :data:`environb` if you would like
250 These functions are described in :ref:`os-file-dir`.
255 Encode :term:`path-like <path-like object>` *filename* to the
270 Decode the :term:`path-like <path-like object>` *filename* from the
318 On Unix, keys and values are decoded with :func:`sys.getfilesystemencoding`
320 would like to use a different encoding.
322 .. availability:: Unix, Windows.
337 .. availability:: Unix.
358 .. availability:: Unix, not Emscripten, not WASI.
367 .. availability:: Unix, not Emscripten, not WASI.
376 .. availability:: Unix.
379 :ref:`wasm-availability` for more information.
389 .. availability:: Unix, not Emscripten, not WASI.
398 .. availability:: Unix, not Emscripten, not WASI.
403 other Unix platforms. If the Python interpreter was built with a
406 this list is limited to a system-defined number of entries, typically 16,
426 .. availability:: Unix, Windows, not Emscripten, not WASI.
434 .. availability:: Unix, not Emscripten, not WASI.
442 .. availability:: Unix, not Emscripten, not WASI.
452 :ref:`wasm-availability` for more information.
458 Return the parent's process id. When the parent process has exited, on Unix
462 .. availability:: Unix, Windows, not Emscripten, not WASI.
480 .. availability:: Unix, not Emscripten, not WASI.
491 .. availability:: Unix, not Emscripten, not WASI.
501 .. availability:: Unix, not Emscripten, not WASI.
511 .. availability:: Unix, not Emscripten, not WASI.
522 .. availability:: Unix.
525 :ref:`wasm-availability` for more information.
534 .. availability:: Unix, not Emscripten, not WASI.
558 .. audit-event:: os.putenv key,value os.putenv
568 .. availability:: Unix, not Emscripten, not WASI.
575 .. availability:: Unix, not Emscripten, not WASI.
582 .. availability:: Unix, not Emscripten, not WASI.
591 .. availability:: Unix, not Emscripten, not WASI.
594 system-defined maximum number of effective group ids, typically 16.
601 which version is implemented (if any). See the Unix manual for the semantics.
603 .. availability:: Unix, not Emscripten, not WASI.
609 process with id *pid* to the process group with id *pgrp*. See the Unix manual
612 .. availability:: Unix, not Emscripten, not WASI.
626 *priority* is a value in the range -20 to 19. The default priority is 0;
629 .. availability:: Unix, not Emscripten, not WASI.
638 .. availability:: Unix, not Emscripten, not WASI.
645 .. availability:: Unix, not Emscripten, not WASI.
654 .. availability:: Unix, not Emscripten, not WASI.
663 .. availability:: Unix, not Emscripten, not WASI.
668 Call the system call :c:func:`getsid`. See the Unix manual for the semantics.
670 .. availability:: Unix, not Emscripten, not WASI.
675 Call the system call :c:func:`setsid`. See the Unix manual for the semantics.
677 .. availability:: Unix, not Emscripten, not WASI.
686 .. availability:: Unix, not Emscripten, not WASI.
710 :ref:`wasm-availability` for more information.
722 * :attr:`sysname` - operating system name
723 * :attr:`nodename` - name of machine on network (implementation-defined)
724 * :attr:`release` - operating system release
725 * :attr:`version` - operating system version
726 * :attr:`machine` - hardware identifier
729 like a five-tuple containing :attr:`sysname`, :attr:`nodename`,
738 .. availability:: Unix.
741 Return type changed from a tuple to a tuple-like object
758 .. audit-event:: os.unsetenv key os.unsetenv
764 .. _os-newstreams:
767 --------------------
776 alias of the :func:`open` built-in function and accepts the same arguments.
781 .. _os-fd-ops:
784 --------------------------
792 is slightly deceptive; on Unix platforms, sockets and pipes are also referenced
807 This function is intended for low-level I/O and must be applied to a file
809 object" returned by the built-in function :func:`open` or by :func:`popen` or
852 On Unix, if the :ref:`Python UTF-8 Mode <utf8-mode>` is enabled, return
853 ``'UTF-8'`` rather than the device encoding.
856 On Unix, the function now implements the Python UTF-8 Mode.
862 :ref:`non-inheritable <fd_inheritance>`.
871 The new file descriptor is now non-inheritable.
878 <fd_inheritance>` by default or non-inheritable if *inheritable*
896 .. audit-event:: os.chmod path,mode,dir_fd os.fchmod
898 .. availability:: Unix.
901 :ref:`wasm-availability` for more information.
907 and *gid*. To leave one of the ids unchanged, set it to -1. See
911 .. audit-event:: os.chown path,uid,gid,dir_fd os.fchown
913 .. availability:: Unix.
916 :ref:`wasm-availability` for more information.
924 .. availability:: Unix.
935 standards (POSIX.1, Unix 95, Unix 98, and others). Some platforms define
947 .. availability:: Unix.
965 file descriptor *fd*, like :func:`statvfs`. As of Python 3.3, this is
968 .. availability:: Unix.
973 Force write of file with filedescriptor *fd* to disk. On Unix, this calls the
980 .. availability:: Unix, Windows.
989 .. audit-event:: os.truncate fd,length os.ftruncate
991 .. availability:: Unix, Windows.
1004 .. availability:: Unix.
1007 :ref:`wasm-availability` for more information.
1015 tty(-like) device, else ``False``.
1022 *cmd* specifies the command to use - one of :data:`F_LOCK`, :data:`F_TLOCK`,
1026 .. audit-event:: os.lockf fd,cmd,len os.lockf
1028 .. availability:: Unix.
1040 .. availability:: Unix.
1051 .. availability:: Unix, not Emscripten, not WASI.
1073 Some operating systems could support additional values, like
1082 The new file descriptor is :ref:`non-inheritable <fd_inheritance>`.
1084 For a description of the flag and mode values, see the C run-time documentation;
1085 flag constants (like :const:`O_RDONLY` and :const:`O_WRONLY`) are defined in
1092 .. audit-event:: open path,mode,flags os.open
1095 The new file descriptor is now non-inheritable.
1099 This function is intended for low-level I/O. For normal usage, use the
1100 built-in function :func:`open`, which returns a :term:`file object` with
1113 Accepts a :term:`path-like object`.
1118 their availability and use, consult the :manpage:`open(2)` manual page on Unix
1119 or `the MSDN <https://msdn.microsoft.com/en-us/library/z0kc8e3z.aspx>`_ on Windows.
1130 The above constants are available on Unix and Windows.
1141 The above constants are only available on Unix.
1190 Open a new pseudo-terminal pair. Return a pair of file descriptors
1192 descriptors are :ref:`non-inheritable <fd_inheritance>`. For a (slightly) more
1195 .. availability:: Unix, not Emscripten, not WASI.
1198 The new file descriptors are now non-inheritable.
1205 :ref:`non-inheritable <fd_inheritance>`.
1207 .. availability:: Unix, Windows.
1210 The new file descriptors are now non-inheritable.
1221 .. availability:: Unix, not Emscripten, not WASI.
1231 .. availability:: Unix, not Emscripten.
1246 .. availability:: Unix.
1261 .. availability:: Unix.
1274 .. availability:: Unix.
1282 :term:`bytes-like objects <bytes-like object>` *buffers*, leaving the file
1289 - :data:`RWF_HIPRI`
1290 - :data:`RWF_NOWAIT`
1314 If no bytes were read, it will return ``-1`` and set errno to
1324 High priority read/write. Allows block-based filesystems to use polling
1343 .. availability:: Unix.
1352 :term:`bytes-like objects <bytes-like object>`. Buffers are processed in
1359 - :data:`RWF_DSYNC`
1360 - :data:`RWF_SYNC`
1361 - :data:`RWF_APPEND`
1379 Provide a per-write equivalent of the :data:`O_DSYNC` :func:`os.open` flag.
1389 Provide a per-write equivalent of the :data:`O_SYNC` :func:`os.open` flag.
1399 Provide a per-write equivalent of the :data:`O_APPEND` :func:`os.open`
1404 ``-1``, the current file *offset* is updated.
1420 This function is intended for low-level I/O and must be applied to a file
1422 "file object" returned by the built-in function :func:`open` or by
1455 Cross-platform applications should not use *headers*, *trailers* and *flags*
1458 .. availability:: Unix, not Emscripten, not WASI.
1462 For a higher-level wrapper of :func:`sendfile`, see
1478 .. availability:: Unix.
1481 :ref:`wasm-availability` for more information.
1493 .. availability:: Unix, not Emscripten, not WASI.
1502 .. availability:: Unix, not Emscripten, not WASI.
1542 Read from a file descriptor *fd* into a number of mutable :term:`bytes-like
1543 objects <bytes-like object>` *buffers*. Transfer data into each buffer until
1553 .. availability:: Unix.
1563 .. availability:: Unix, not WASI.
1571 .. availability:: Unix, not WASI.
1580 .. availability:: Unix.
1591 This function is intended for low-level I/O and must be applied to a file
1593 object" returned by the built-in function :func:`open` or by :func:`popen` or
1606 a sequence of :term:`bytes-like objects <bytes-like object>`. Buffers are
1615 .. availability:: Unix.
1620 .. _terminal-size:
1638 :func:`shutil.get_terminal_size` is the high-level function which
1639 should normally be used, ``os.get_terminal_size`` is the low-level
1642 .. availability:: Unix, Windows.
1666 created by Python are non-inheritable by default.
1668 On UNIX, non-inheritable file descriptors are closed in child processes at the
1671 On Windows, non-inheritable handles and file descriptors are closed in child
1679 On WebAssembly platforms ``wasm32-emscripten`` and ``wasm32-wasi``, the file
1703 .. _os-file-dir:
1706 ---------------------
1708 On some Unix platforms, many of these functions support one or more of these
1764 :const:`False` if not. See the Unix man page :manpage:`access(2)` for more
1803 permissions semantics beyond the usual POSIX permission-bit model.
1809 Accepts a :term:`path-like object`.
1834 .. audit-event:: os.chdir path os.chdir
1841 Accepts a :term:`path-like object`.
1864 .. audit-event:: os.chflags path,flags os.chflags
1866 .. availability:: Unix, not Emscripten, not WASI.
1872 Accepts a :term:`path-like object`.
1908 read-only flag with it (via the ``stat.S_IWRITE`` and ``stat.S_IREAD``
1912 :ref:`wasm-availability` for more information.
1914 .. audit-event:: os.chmod path,mode,dir_fd os.chmod
1921 Accepts a :term:`path-like object`.
1927 leave one of the ids unchanged, set it to -1.
1933 See :func:`shutil.chown` for a higher-level function that accepts names in
1936 .. audit-event:: os.chown path,uid,gid,dir_fd os.chown
1938 .. availability:: Unix.
1941 :ref:`wasm-availability` for more information.
1948 Supports a :term:`path-like object`.
1955 .. availability:: Unix, not Emscripten, not WASI.
1958 Accepts a :term:`path-like object`.
1967 .. audit-event:: os.chdir path os.fchdir
1969 .. availability:: Unix.
1982 The function now uses the UTF-8 encoding on Windows, rather than the ANSI
1989 Set the flags of *path* to the numeric *flags*, like :func:`chflags`, but do
1993 .. audit-event:: os.chflags path,flags os.lchflags
1995 .. availability:: Unix, not Emscripten, not WASI.
1998 Accepts a :term:`path-like object`.
2008 .. audit-event:: os.chmod path,mode,dir_fd os.lchmod
2010 .. availability:: Unix.
2013 Accepts a :term:`path-like object`.
2021 .. audit-event:: os.chown path,uid,gid,dir_fd os.lchown
2023 .. availability:: Unix.
2026 Accepts a :term:`path-like object`.
2037 .. audit-event:: os.link src,dst,src_dir_fd,dst_dir_fd os.link
2039 .. availability:: Unix, Windows.
2048 Accepts a :term:`path-like object` for *src* and *dst*.
2059 *path* may be a :term:`path-like object`. If *path* is of type ``bytes``
2067 .. audit-event:: os.listdir path os.listdir
2085 Accepts a :term:`path-like object`.
2114 Accepts a :term:`path-like object`.
2135 platform-dependent. On some platforms, they are ignored and you should call
2144 .. audit-event:: os.mkdir path,mode,dir_fd os.mkdir
2150 Accepts a :term:`path-like object`.
2159 Recursive directory creation function. Like :func:`mkdir`, but makes all
2160 intermediate-level directories needed to contain the leaf directory.
2174 include :data:`pardir` (eg. ".." on UNIX systems).
2178 .. audit-event:: os.mkdir path,mode,dir_fd os.makedirs
2191 Accepts a :term:`path-like object`.
2195 newly created intermediate-level directories.
2206 FIFOs are pipes that can be accessed like regular files. FIFOs exist until they
2210 doesn't open the FIFO --- it just creates the rendezvous point.
2212 .. availability:: Unix, not Emscripten, not WASI.
2218 Accepts a :term:`path-like object`.
2234 .. availability:: Unix, not Emscripten, not WASI.
2240 Accepts a :term:`path-like object`.
2265 standards (POSIX.1, Unix 95, Unix 98, and others). Some platforms define
2278 .. availability:: Unix.
2281 Accepts a :term:`path-like object`.
2290 .. availability:: Unix.
2312 .. availability:: Unix, Windows.
2321 Accepts a :term:`path-like object` on Unix.
2324 Accepts a :term:`path-like object` and a bytes object on Windows.
2341 be raised; on Unix, the directory entry is removed but the storage allocated
2346 .. audit-event:: os.remove path,dir_fd os.remove
2352 Accepts a :term:`path-like object`.
2359 Remove directories recursively. Works like :func:`rmdir` except that, if the
2368 .. audit-event:: os.remove path,dir_fd os.removedirs
2371 Accepts a :term:`path-like object`.
2383 On Unix, if *src* is a file and *dst* is a directory or vice-versa, an
2386 silently replaced. If *dst* is a non-empty directory, an :exc:`OSError`
2388 has permission. The operation may fail on some Unix flavors if *src* and
2395 If you want cross-platform overwriting of the destination, use :func:`replace`.
2397 .. audit-event:: os.rename src,dst,src_dir_fd,dst_dir_fd os.rename
2403 Accepts a :term:`path-like object` for *src* and *dst*.
2408 Recursive directory or file renaming function. Works like :func:`rename`, except
2418 .. audit-event:: os.rename src,dst,src_dir_fd,dst_dir_fd os.renames
2421 Accepts a :term:`path-like object` for *old* and *new*.
2426 Rename the file or directory *src* to *dst*. If *dst* is a non-empty directory,
2435 .. audit-event:: os.rename src,dst,src_dir_fd,dst_dir_fd os.replace
2440 Accepts a :term:`path-like object` for *src* and *dst*.
2453 .. audit-event:: os.rmdir path,dir_fd os.rmdir
2459 Accepts a :term:`path-like object`.
2478 always requires a system call on Unix but only requires one for
2481 *path* may be a :term:`path-like object`. If *path* is of type ``bytes``
2490 .. audit-event:: os.scandir path os.scandir
2518 On Unix-based systems, :func:`scandir` uses the system's
2523 …`FindFirstFileW <https://msdn.microsoft.com/en-us/library/windows/desktop/aa364418(v=vs.85).aspx>`_
2525 … `FindNextFileW <https://msdn.microsoft.com/en-us/library/windows/desktop/aa364428(v=vs.85).aspx>`_
2536 The function accepts a :term:`path-like object`.
2539 Added support for :ref:`file descriptors <path_fd>` on Unix.
2551 ``os.DirEntry`` instances are not intended to be stored in long-lived data
2554 up-to-date information.
2557 also raise :exc:`OSError`. If you need very fine-grained
2561 To be directly usable as a :term:`path-like object`, ``os.DirEntry``
2593 ``os.stat(entry.path, follow_symlinks=False).st_ino`` to fetch up-to-date
2597 not on Unix.
2611 with :func:`stat.S_ISDIR` to fetch up-to-date information.
2614 Specifically, for non-symlinks, neither Windows or Unix require a system
2615 call, except on certain Unix file systems, such as network file systems,
2627 non-file entry, or if it doesn't exist anymore.
2631 a directory or other non-file entry, or if it doesn't exist anymore.
2643 :func:`os.path.islink` to fetch up-to-date information.
2646 Specifically, neither Windows or Unix require a system call, except on
2647 certain Unix file systems, such as network file systems, that return
2659 On Unix, this method always requires a system call. On Windows, it
2670 fetch up-to-date information.
2689 either a string or bytes -- directly or indirectly through the :class:`PathLike`
2690 interface -- or as an open file descriptor. Return a :class:`stat_result`
2700 name-surrogate reparse points, which includes symlinks and directory
2704 being returned instead of the non-link that prevented full traversal. To
2732 Accepts a :term:`path-like object`.
2757 Platform dependent, but if non-zero, uniquely identifies the
2760 * the inode number on Unix,
2762 <https://msdn.microsoft.com/en-us/library/aa363788>`_ on
2801 * the time of most recent metadata change on Unix,
2817 * the time of most recent metadata change on Unix,
2826 or FAT32 file systems, :attr:`st_mtime` has 2-second resolution, and
2827 :attr:`st_atime` has only 1-day resolution. See your operating system
2833 provide nanosecond precision, the floating-point object used to
2839 On some Unix systems (such as Linux), the following attributes may also be
2844 Number of 512-byte blocks allocated for file.
2850 smaller chunks may cause an inefficient read-modify-rewrite.
2860 On other Unix systems (such as FreeBSD), the following attributes may be
2952 Two module-level constants are defined for the :attr:`f_flag` attribute's
2953 bit-flags: if :const:`ST_RDONLY` is set, the filesystem is mounted
2954 read-only, and if :const:`ST_NOSUID` is set, the semantics of
2957 Additional module-level constants are defined for GNU/glibc based systems.
2962 (append-only file), :const:`ST_IMMUTABLE` (immutable file), :const:`ST_NOATIME`
2968 .. availability:: Unix.
2983 Accepts a :term:`path-like object`.
3008 Currently *dir_fd* parameters only work on Unix platforms;
3027 Currently *effective_ids* is only supported on Unix platforms;
3084 default) otherwise. On non-Windows platforms, *target_is_directory* is ignored.
3100 .. audit-event:: os.symlink src,dst,dir_fd os.symlink
3102 .. availability:: Unix, Windows.
3105 :ref:`wasm-availability` for more information.
3112 on non-Windows platforms.
3115 Accepts a :term:`path-like object` for *src* and *dst*.
3125 .. availability:: Unix.
3137 .. audit-event:: os.truncate path,length os.truncate
3139 .. availability:: Unix, Windows.
3147 Accepts a :term:`path-like object`.
3154 traditional Unix name. Please see the documentation for
3157 .. audit-event:: os.remove path,dir_fd os.unlink
3163 Accepts a :term:`path-like object`.
3173 - If *ns* is specified,
3174 it must be a 2-tuple of the form ``(atime_ns, mtime_ns)``
3176 - If *times* is not ``None``,
3177 it must be a 2-tuple of the form ``(atime, mtime)``
3179 - If *times* is ``None`` and *ns* is unspecified,
3196 .. audit-event:: os.utime path,times,ns,dir_fd os.utime
3203 Accepts a :term:`path-like object`.
3213 either top-down or bottom-up. For each directory in the tree rooted at directory
3214 *top* (including *top* itself), it yields a 3-tuple ``(dirpath, dirnames,
3220 *filenames* is a list of the names of the non-directory files in *dirpath*.
3230 (directories are generated top-down). If *topdown* is ``False``, the triple
3232 (directories are generated bottom-up). No matter the value of *topdown*, the
3236 When *topdown* is ``True``, the caller can modify the *dirnames* list in-place
3242 no effect on the behavior of the walk, because in bottom-up mode the directories
3267 This example displays the number of bytes taken by non-directory files in each
3276 print("bytes in", len(files), "non-directory files")
3281 walking the tree bottom-up is essential, :func:`rmdir` doesn't allow
3295 .. audit-event:: os.walk top,topdown,onerror,followlinks os.walk
3302 Accepts a :term:`path-like object`.
3311 This behaves exactly like :func:`walk`, except that it yields a 4-tuple
3328 This example displays the number of bytes taken by non-directory files in each
3337 print("bytes in", len(files), "non-directory files")
3341 In the next example, walking the tree bottom-up is essential:
3356 .. audit-event:: os.fwalk top,topdown,onerror,follow_symlinks,dir_fd os.fwalk
3358 .. availability:: Unix.
3363 Accepts a :term:`path-like object`.
3374 descriptor is :ref:`non-inheritable <fd_inheritance>`.
3421 new file descriptor is :ref:`non-inheritable <fd_inheritance>`.
3426 64 bit integer with a maximum value of 2\ :sup:`64`\ -\ 2.
3431 If :const:`EFD_SEMAPHORE` is specified and the event counter is non-zero,
3435 non-zero, :func:`eventfd_read` returns the current event counter value and
3443 2\ :sup:`64`\ -\ 2.
3486 Set close-on-exec flag for new :func:`eventfd` file descriptor.
3503 Provide semaphore-like semantics for reads from a :func:`eventfd` file
3528 .. audit-event:: os.getxattr path,attribute os.getxattr
3531 Accepts a :term:`path-like object` for *path* and *attribute*.
3544 .. audit-event:: os.listxattr path os.listxattr
3547 Accepts a :term:`path-like object`.
3560 .. audit-event:: os.removexattr path,attribute os.removexattr
3563 Accepts a :term:`path-like object` for *path* and *attribute*.
3585 .. audit-event:: os.setxattr path,attribute,value,flags os.setxattr
3588 Accepts a :term:`path-like object` for *path* and *attribute*.
3609 .. _os-process:
3612 ------------------
3627 Generate a :const:`SIGABRT` signal to the current process. On Unix, the default
3646 <https://msdn.microsoft.com/44228cf2-6306-466c-8f16-f513cd3ba8b5>`_
3649 .. audit-event:: os.add_dll_directory path os.add_dll_directory
3661 override the process-wide behavior to ensure consistency. See the
3662 :ref:`porting notes <bpo-36085-whatsnew>` for information on
3676 do not return. On Unix, the new executable is loaded into the current process,
3687 command-line arguments are passed. The "l" variants are perhaps the easiest
3717 .. audit-event:: os.exec path,args,env os.execl
3719 .. availability:: Unix, Windows, not Emscripten, not WASI.
3726 Accepts a :term:`path-like object`.
3744 Some of these may not be available on all Unix platforms, since there is some
3754 .. availability:: Unix, Windows.
3762 .. availability:: Unix, not Emscripten, not WASI.
3769 .. availability:: Unix, not Emscripten, not WASI.
3776 .. availability:: Unix, not Emscripten, not WASI.
3783 .. availability:: Unix, not Emscripten, not WASI.
3790 .. availability:: Unix, not Emscripten, not WASI.
3797 .. availability:: Unix, not Emscripten, not WASI.
3804 .. availability:: Unix, not Emscripten, not WASI.
3812 .. availability:: Unix, not Emscripten, not WASI.
3820 .. availability:: Unix, not Emscripten, not WASI.
3827 .. availability:: Unix, not Emscripten, not WASI.
3834 .. availability:: Unix, not Emscripten, not WASI.
3843 .. availability:: Unix, not Emscripten, not WASI.
3851 .. availability:: Unix, not Emscripten, not WASI.
3859 .. availability:: Unix, not Emscripten, not WASI.
3866 .. availability:: Unix, not Emscripten, not WASI.
3871 Exit code that means something like "an entry was not found".
3873 .. availability:: Unix, not Emscripten, not WASI.
3884 .. audit-event:: os.fork "" os.fork
3894 .. availability:: Unix, not Emscripten, not WASI.
3899 Fork a child process, using a new pseudo-terminal as the child's controlling
3902 master end of the pseudo-terminal. For a more portable approach, use the
3905 .. audit-event:: os.forkpty "" os.forkpty
3911 .. availability:: Unix, not Emscripten, not WASI.
3933 .. audit-event:: os.kill pid,sig os.kill
3935 .. availability:: Unix, Windows, not Emscripten, not WASI.
3949 .. audit-event:: os.killpg pgid,sig os.killpg
3951 .. availability:: Unix, not Emscripten, not WASI.
3958 .. availability:: Unix, not Emscripten, not WASI.
3979 .. availability:: Unix, not Emscripten, not WASI.
3982 .. function:: popen(cmd, mode='r', buffering=-1)
3989 the corresponding argument to the built-in :func:`open` function. The
3995 represents the return value of the process left-shifted by one
3998 example, the return value might be ``- signal.SIGKILL`` if the
4002 On Unix, :func:`waitstatus_to_exitcode` can be used to convert the ``close``
4014 The :ref:`Python UTF-8 Mode <utf8-mode>` affects encodings used
4019 control options like encodings.
4030 The positional-only arguments *path*, *args*, and *env* are similar to
4076 the parent. In either case, if the set-user-ID and set-group-ID permission
4102 .. audit-event:: os.posix_spawn path,argv,env os.posix_spawn
4106 .. availability:: Unix, not Emscripten, not WASI.
4118 .. audit-event:: os.posix_spawn path,argv,env os.posix_spawnp
4132 The parameters are optional and keyword-only.
4142 trigger them as the child is not going to re-enter the interpreter.
4149 Note that :c:func:`fork` calls made by third-party C code may not
4155 .. availability:: Unix, not Emscripten, not WASI.
4174 :ref:`subprocess-replacements` section.)
4178 exits normally, or ``-signal``, where *signal* is the signal that killed the
4182 Note on VxWorks, this function doesn't return ``-signal`` when the new process is
4186 command-line arguments are passed. The "l" variants are perhaps the easiest
4222 .. audit-event:: os.spawn mode,path,args,env os.spawnl
4224 .. availability:: Unix, Windows, not Emscripten, not WASI.
4228 :func:`spawnve` are not thread-safe on Windows; we advise you to use the
4232 Accepts a :term:`path-like object`.
4243 .. availability:: Unix, Windows.
4251 of the process the run is successful, or ``-signal`` if a signal kills the
4254 .. availability:: Unix, Windows.
4273 When *operation* is not specified or ``'open'``, this acts like double-clicking
4307 .. audit-event:: os.startfile path,operation os.startfile
4309 .. audit-event:: os.startfile/2 path,operation,arguments,cwd,show_cmd os.startfile
4326 value of the Python function is system-dependent.
4328 On Unix, the return value is the exit status of the process encoded in the
4334 status of the command run; on systems using a non-native shell, consult your
4339 to using this function. See the :ref:`subprocess-replacements` section in
4342 On Unix, :func:`waitstatus_to_exitcode` can be used to convert the result
4346 .. audit-event:: os.system command os.system
4348 .. availability:: Unix, Windows, not Emscripten, not WASI.
4356 * :attr:`!user` - user time
4357 * :attr:`!system` - system time
4358 * :attr:`!children_user` - user time of all child processes
4359 * :attr:`!children_system` - system time of all child processes
4360 * :attr:`!elapsed` - elapsed real time since a fixed point in the past
4362 For backwards compatibility, this object also behaves like a five-tuple
4366 See the Unix manual page
4367 … `times(3) <https://man.freebsd.org/cgi/man.cgi?time(3)>`_ manual page on Unix or `the GetProcessT…
4368 …<https://docs.microsoft.com/windows/win32/api/processthreadsapi/nf-processthreadsapi-getprocesstim…
4371 .. availability:: Unix, Windows.
4374 Return type changed from a tuple to a tuple-like object
4381 and exit status indication: a 16-bit number, whose low byte is the signal number
4392 .. availability:: Unix, not Emscripten, not WASI.
4426 .. availability:: Unix, not Emscripten, not WASI.
4433 The details of this function differ on Unix and Windows.
4435 On Unix: Wait for completion of a child process given by process id *pid*, and
4442 child in the process group of the current process. If *pid* is ``-1``, the
4444 ``-1``, status is requested for any process in the process group ``-pid`` (the
4455 (shifting makes cross-platform use of the function easier). A *pid* less than or
4464 .. availability:: Unix, Windows, not Emscripten, not WASI.
4475 3-element tuple containing the child's process id, exit status indication,
4484 .. availability:: Unix, not Emscripten, not WASI.
4489 Similar to :func:`waitpid`, except a 3-element tuple, containing the child's
4498 .. availability:: Unix, not Emscripten, not WASI.
4509 * :data:`!P_PID` - wait for the child whose PID is *id*.
4510 * :data:`!P_PGID` - wait for any child whose progress group ID is *id*.
4511 * :data:`!P_ALL` - wait for any child; *id* is ignored.
4512 * :data:`!P_PIDFD` - wait for the child identified by the file descriptor
4515 .. availability:: Unix, not Emscripten, not WASI.
4530 .. availability:: Unix, not Emscripten, not WASI.
4541 .. availability:: Unix, not Emscripten, not WASI.
4553 .. availability:: Unix, not Emscripten, not WASI.
4566 .. availability:: Unix, not Emscripten, not WASI.
4575 .. availability:: Unix, not Emscripten, not WASI.
4585 .. availability:: Unix, not Emscripten, not WASI.
4598 .. availability:: Unix, not Emscripten, not WASI.
4610 On Unix:
4616 true), return ``-signum`` where *signum* is the number of the signal that
4617 caused the process to terminate (return ``-WTERMSIG(status)``):
4623 On Unix, if the process is being traced or if :func:`waitpid` was called
4633 .. availability:: Unix, Windows, not Emscripten, not WASI.
4649 .. availability:: Unix, not Emscripten, not WASI.
4660 .. availability:: Unix, not Emscripten, not WASI.
4672 .. availability:: Unix, not Emscripten, not WASI.
4679 .. availability:: Unix, not Emscripten, not WASI.
4688 .. availability:: Unix, not Emscripten, not WASI.
4697 .. availability:: Unix, not Emscripten, not WASI.
4706 .. availability:: Unix, not Emscripten, not WASI.
4715 .. availability:: Unix, not Emscripten, not WASI.
4719 --------------------------
4722 system. They are only available on some Unix platforms. For more detailed
4723 information, consult your Unix manpages.
4736 Scheduling policy for CPU-intensive processes that tries to preserve
4753 A round-robin scheduling policy.
4815 Return the round-robin quantum in seconds for the process with PID *pid*. A
4837 .. _os-path:
4840 --------------------------------
4845 Return string-valued system configuration values. *name* specifies the
4848 Unix 95, Unix 98, and others). Some platforms define additional names as well.
4861 .. availability:: Unix.
4870 .. availability:: Unix.
4891 .. availability:: Unix.
4896 Return integer-valued system configuration values. If the configuration value
4897 specified by *name* isn't defined, ``-1`` is returned. The comments regarding
4901 .. availability:: Unix.
4910 .. availability:: Unix.
4918 Higher-level operations on pathnames are defined in the :mod:`os.path` module.
4943 is not sufficient to be able to parse or concatenate pathnames --- use
4944 :func:`os.path.split` and :func:`os.path.join` --- but it is occasionally
5003 :func:`~sys.getdlopenflags` functions. See the Unix manual page
5010 --------------
5018 These bytes can be used to seed user-space random number generators or for
5031 <https://man7.org/linux/man-pages/man2/getrandom.2.html>`_.
5041 This function returns random bytes from an OS-specific randomness source. The
5049 random bytes in non-blocking mode (using the :data:`GRND_NONBLOCK` flag) or
5052 On a Unix-like system, random bytes are read from the ``/dev/urandom``
5060 easy-to-use interface to the random number generator provided by your