Fred Drake | 295da24 | 1998-08-10 19:42:37 +0000 | [diff] [blame] | 1 | \section{\module{posix} --- |
| 2 | The most common \POSIX{} system calls.} |
Fred Drake | b91e934 | 1998-07-23 17:59:49 +0000 | [diff] [blame] | 3 | \declaremodule{builtin}{posix} |
| 4 | |
Fred Drake | bb3b002 | 1999-01-11 18:36:23 +0000 | [diff] [blame] | 5 | \modulesynopsis{The most common \POSIX{} system calls (normally used |
| 6 | via module \module{os}).} |
Fred Drake | b91e934 | 1998-07-23 17:59:49 +0000 | [diff] [blame] | 7 | |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 8 | |
| 9 | This module provides access to operating system functionality that is |
Fred Drake | 75aae9a | 1998-03-11 05:29:58 +0000 | [diff] [blame] | 10 | standardized by the \C{} Standard and the \POSIX{} standard (a thinly |
| 11 | disguised \UNIX{} interface). |
Guido van Rossum | 470be14 | 1995-03-17 16:07:09 +0000 | [diff] [blame] | 12 | |
| 13 | \strong{Do not import this module directly.} Instead, import the |
Fred Drake | 75aae9a | 1998-03-11 05:29:58 +0000 | [diff] [blame] | 14 | module \module{os}, which provides a \emph{portable} version of this |
| 15 | interface. On \UNIX{}, the \module{os} module provides a superset of |
| 16 | the \module{posix} interface. On non-\UNIX{} operating systems the |
| 17 | \module{posix} module is not available, but a subset is always |
| 18 | available through the \module{os} interface. Once \module{os} is |
| 19 | imported, there is \emph{no} performance penalty in using it instead |
Fred Drake | bb3b002 | 1999-01-11 18:36:23 +0000 | [diff] [blame] | 20 | of \module{posix}. In addition, \module{os}\refstmodindex{os} |
| 21 | provides some additional functionality, such as automatically calling |
| 22 | \function{putenv()} when an entry in \code{os.environ} is changed. |
Guido van Rossum | 470be14 | 1995-03-17 16:07:09 +0000 | [diff] [blame] | 23 | |
Guido van Rossum | 282290f | 1997-08-27 14:54:25 +0000 | [diff] [blame] | 24 | The descriptions below are very terse; refer to the corresponding |
Fred Drake | 65b32f7 | 1998-02-09 20:27:12 +0000 | [diff] [blame] | 25 | \UNIX{} manual (or \POSIX{} documentation) entry for more information. |
Guido van Rossum | 282290f | 1997-08-27 14:54:25 +0000 | [diff] [blame] | 26 | Arguments called \var{path} refer to a pathname given as a string. |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 27 | |
Barry Warsaw | eef2cd1 | 1998-07-23 19:50:09 +0000 | [diff] [blame] | 28 | Errors are reported as exceptions; the usual exceptions are given for |
| 29 | type errors, while errors reported by the system calls raise |
| 30 | \exception{error} (a synonym for the standard exception |
Fred Drake | bb3b002 | 1999-01-11 18:36:23 +0000 | [diff] [blame] | 31 | \exception{OSError}), described below. |
| 32 | |
| 33 | \subsection{Large File Support \label{posix-large-files}} |
| 34 | \index{large files} |
| 35 | \index{file!large files} |
| 36 | |
| 37 | \sectionauthor{Steve Clift}{clift@mail.anacapa.net} |
| 38 | |
| 39 | Several operating systems (including AIX, HPUX, Irix and Solaris) |
| 40 | provide support for files that are larger than 2 Gb from a \C{} |
| 41 | programming model where \ctype{int} and \ctype{long} are 32-bit |
| 42 | values. This is typically accomplished by defining the relevant size |
| 43 | and offset types as 64-bit values. Such files are sometimes referred |
| 44 | to as \dfn{large files}. |
| 45 | |
| 46 | Large file support is enabled in Python when the size of an |
| 47 | \ctype{off_t} is larger than a \ctype{long} and the \ctype{long long} |
| 48 | type is available and is at least as large as an \ctype{off_t}. Python |
| 49 | longs are then used to represent file sizes, offsets and other values |
| 50 | that can exceed the range of a Python int. It may be necessary to |
| 51 | configure and compile Python with certain compiler flags to enable |
| 52 | this mode. For example, it is enabled by default with recent versions |
| 53 | of Irix, but with Solaris 2.6 and 2.7 you need to do something like: |
| 54 | |
| 55 | \begin{verbatim} |
| 56 | CFLAGS="-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64" OPT="-g -O2 $CFLAGS" \ |
| 57 | configure |
| 58 | \end{verbatim} % $ <-- bow to font-lock |
| 59 | |
| 60 | |
| 61 | \subsection{\module{posix} Module Contents \label{posix-contents}} |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 62 | |
Fred Drake | 75aae9a | 1998-03-11 05:29:58 +0000 | [diff] [blame] | 63 | Module \module{posix} defines the following data items: |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 64 | |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 65 | \begin{datadesc}{environ} |
Guido van Rossum | 0410196 | 1998-10-24 20:16:56 +0000 | [diff] [blame] | 66 | A dictionary or dictionary look-alike representing the string |
Fred Drake | bb3b002 | 1999-01-11 18:36:23 +0000 | [diff] [blame] | 67 | environment at the time the interpreter was started. For example, |
| 68 | \code{posix.environ['HOME']} is the pathname of your home directory, |
| 69 | equivalent to \code{getenv("HOME")} in \C{}. |
Guido van Rossum | 9c43c59 | 1997-08-08 21:05:09 +0000 | [diff] [blame] | 70 | |
Guido van Rossum | 470be14 | 1995-03-17 16:07:09 +0000 | [diff] [blame] | 71 | Modifying this dictionary does not affect the string environment |
Fred Drake | 75aae9a | 1998-03-11 05:29:58 +0000 | [diff] [blame] | 72 | passed on by \function{execv()}, \function{popen()} or |
| 73 | \function{system()}; if you need to change the environment, pass |
| 74 | \code{environ} to \function{execve()} or add variable assignments and |
| 75 | export statements to the command string for \function{system()} or |
| 76 | \function{popen()}. |
Guido van Rossum | 9c43c59 | 1997-08-08 21:05:09 +0000 | [diff] [blame] | 77 | |
Fred Drake | 75aae9a | 1998-03-11 05:29:58 +0000 | [diff] [blame] | 78 | \emph{However:} If you are using this module via the \module{os} |
| 79 | module (as you should -- see the introduction above), \code{environ} |
| 80 | is a a mapping object that behaves almost like a dictionary but |
Fred Drake | c024c99 | 1998-10-28 18:19:16 +0000 | [diff] [blame] | 81 | invokes \function{putenv()} automatically whenever an item is changed. |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 82 | \end{datadesc} |
| 83 | |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 84 | \begin{excdesc}{error} |
Fred Drake | 65b32f7 | 1998-02-09 20:27:12 +0000 | [diff] [blame] | 85 | This exception is raised when a \POSIX{} function returns a |
Fred Drake | 75aae9a | 1998-03-11 05:29:58 +0000 | [diff] [blame] | 86 | \POSIX{}-related error (e.g., not for illegal argument types). The |
| 87 | accompanying value is a pair containing the numeric error code from |
| 88 | \cdata{errno} and the corresponding string, as would be printed by the |
| 89 | \C{} function \cfunction{perror()}. See the module |
| 90 | \module{errno}\refbimodindex{errno}, which contains names for the |
| 91 | error codes defined by the underlying operating system. |
| 92 | |
| 93 | When exceptions are classes, this exception carries two attributes, |
| 94 | \member{errno} and \member{strerror}. The first holds the value of |
| 95 | the \C{} \cdata{errno} variable, and the latter holds the |
Barry Warsaw | eef2cd1 | 1998-07-23 19:50:09 +0000 | [diff] [blame] | 96 | corresponding error message from \cfunction{strerror()}. For |
| 97 | exceptions that involve a file system path (e.g. \code{chdir} or |
| 98 | \code{unlink}), the exception instance will contain a third attribute |
| 99 | \member{filename} which is the file name passed to the |
| 100 | function. |
Fred Drake | 75aae9a | 1998-03-11 05:29:58 +0000 | [diff] [blame] | 101 | |
| 102 | When exceptions are strings, the string for the exception is |
Barry Warsaw | eef2cd1 | 1998-07-23 19:50:09 +0000 | [diff] [blame] | 103 | \code{'OSError'}. |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 104 | \end{excdesc} |
| 105 | |
Fred Drake | bb3b002 | 1999-01-11 18:36:23 +0000 | [diff] [blame] | 106 | It defines the following functions and constants when the operating |
| 107 | system provides them directly or provides the means to emulate them: |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 108 | |
Guido van Rossum | 74429ea | 1999-01-06 23:03:43 +0000 | [diff] [blame] | 109 | \begin{funcdesc}{access}{path, mode} |
| 110 | Check read/write/execute permissions for this process or extance of file |
| 111 | \var{path}. Return \code{1} if access is granted, \code{0} if not. |
| 112 | See the \UNIX{} manual for the semantics. |
| 113 | \end{funcdesc} |
| 114 | |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 115 | \begin{funcdesc}{chdir}{path} |
| 116 | Change the current working directory to \var{path}. |
| 117 | \end{funcdesc} |
| 118 | |
Fred Drake | cce1090 | 1998-03-17 06:33:25 +0000 | [diff] [blame] | 119 | \begin{funcdesc}{chmod}{path, mode} |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 120 | Change the mode of \var{path} to the numeric \var{mode}. |
| 121 | \end{funcdesc} |
| 122 | |
Fred Drake | cce1090 | 1998-03-17 06:33:25 +0000 | [diff] [blame] | 123 | \begin{funcdesc}{chown}{path, uid, gid} |
Guido van Rossum | 31cce97 | 1995-01-04 19:17:34 +0000 | [diff] [blame] | 124 | Change the owner and group id of \var{path} to the numeric \var{uid} |
| 125 | and \var{gid}. |
| 126 | (Not on MS-DOS.) |
| 127 | \end{funcdesc} |
| 128 | |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 129 | \begin{funcdesc}{close}{fd} |
| 130 | Close file descriptor \var{fd}. |
Guido van Rossum | 2837970 | 1995-01-12 12:38:22 +0000 | [diff] [blame] | 131 | |
| 132 | Note: this function is intended for low-level I/O and must be applied |
Fred Drake | 75aae9a | 1998-03-11 05:29:58 +0000 | [diff] [blame] | 133 | to a file descriptor as returned by \function{open()} or |
| 134 | \function{pipe()}. To close a ``file object'' returned by the |
| 135 | built-in function \function{open()} or by \function{popen()} or |
| 136 | \function{fdopen()}, use its \method{close()} method. |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 137 | \end{funcdesc} |
| 138 | |
| 139 | \begin{funcdesc}{dup}{fd} |
| 140 | Return a duplicate of file descriptor \var{fd}. |
| 141 | \end{funcdesc} |
| 142 | |
Fred Drake | cce1090 | 1998-03-17 06:33:25 +0000 | [diff] [blame] | 143 | \begin{funcdesc}{dup2}{fd, fd2} |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 144 | Duplicate file descriptor \var{fd} to \var{fd2}, closing the latter |
Fred Drake | 75aae9a | 1998-03-11 05:29:58 +0000 | [diff] [blame] | 145 | first if necessary. |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 146 | \end{funcdesc} |
| 147 | |
Fred Drake | cce1090 | 1998-03-17 06:33:25 +0000 | [diff] [blame] | 148 | \begin{funcdesc}{execv}{path, args} |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 149 | Execute the executable \var{path} with argument list \var{args}, |
| 150 | replacing the current process (i.e., the Python interpreter). |
| 151 | The argument list may be a tuple or list of strings. |
| 152 | (Not on MS-DOS.) |
| 153 | \end{funcdesc} |
| 154 | |
Fred Drake | cce1090 | 1998-03-17 06:33:25 +0000 | [diff] [blame] | 155 | \begin{funcdesc}{execve}{path, args, env} |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 156 | Execute the executable \var{path} with argument list \var{args}, |
| 157 | and environment \var{env}, |
| 158 | replacing the current process (i.e., the Python interpreter). |
| 159 | The argument list may be a tuple or list of strings. |
| 160 | The environment must be a dictionary mapping strings to strings. |
| 161 | (Not on MS-DOS.) |
| 162 | \end{funcdesc} |
| 163 | |
| 164 | \begin{funcdesc}{_exit}{n} |
| 165 | Exit to the system with status \var{n}, without calling cleanup |
| 166 | handlers, flushing stdio buffers, etc. |
| 167 | (Not on MS-DOS.) |
| 168 | |
| 169 | Note: the standard way to exit is \code{sys.exit(\var{n})}. |
Fred Drake | 75aae9a | 1998-03-11 05:29:58 +0000 | [diff] [blame] | 170 | \function{_exit()} should normally only be used in the child process |
| 171 | after a \function{fork()}. |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 172 | \end{funcdesc} |
| 173 | |
Fred Drake | cce1090 | 1998-03-17 06:33:25 +0000 | [diff] [blame] | 174 | \begin{funcdesc}{fdopen}{fd\optional{, mode\optional{, bufsize}}} |
Guido van Rossum | 2837970 | 1995-01-12 12:38:22 +0000 | [diff] [blame] | 175 | Return an open file object connected to the file descriptor \var{fd}. |
| 176 | The \var{mode} and \var{bufsize} arguments have the same meaning as |
Fred Drake | 75aae9a | 1998-03-11 05:29:58 +0000 | [diff] [blame] | 177 | the corresponding arguments to the built-in \function{open()} function. |
Guido van Rossum | c5c67bc | 1994-02-15 15:59:23 +0000 | [diff] [blame] | 178 | \end{funcdesc} |
| 179 | |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 180 | \begin{funcdesc}{fork}{} |
Fred Drake | 75aae9a | 1998-03-11 05:29:58 +0000 | [diff] [blame] | 181 | Fork a child process. Return \code{0} in the child, the child's |
| 182 | process id in the parent. |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 183 | (Not on MS-DOS.) |
| 184 | \end{funcdesc} |
| 185 | |
| 186 | \begin{funcdesc}{fstat}{fd} |
Fred Drake | 75aae9a | 1998-03-11 05:29:58 +0000 | [diff] [blame] | 187 | Return status for file descriptor \var{fd}, like \function{stat()}. |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 188 | \end{funcdesc} |
| 189 | |
Fred Drake | bb3b002 | 1999-01-11 18:36:23 +0000 | [diff] [blame] | 190 | \begin{funcdesc}{fstatvfs}{fd} |
| 191 | Return information about the filesystem containing the file associated |
| 192 | with file descriptor \var{fd}, like \function{statvfs()}. |
| 193 | \end{funcdesc} |
| 194 | |
Fred Drake | cce1090 | 1998-03-17 06:33:25 +0000 | [diff] [blame] | 195 | \begin{funcdesc}{ftruncate}{fd, length} |
Guido van Rossum | f967bf6 | 1997-06-02 17:28:51 +0000 | [diff] [blame] | 196 | Truncate the file corresponding to file descriptor \var{fd}, |
| 197 | so that it is at most \var{length} bytes in size. |
| 198 | \end{funcdesc} |
| 199 | |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 200 | \begin{funcdesc}{getcwd}{} |
| 201 | Return a string representing the current working directory. |
| 202 | \end{funcdesc} |
| 203 | |
| 204 | \begin{funcdesc}{getegid}{} |
Guido van Rossum | eb0f066 | 1997-12-30 20:38:16 +0000 | [diff] [blame] | 205 | Return the current process' effective group id. |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 206 | (Not on MS-DOS.) |
| 207 | \end{funcdesc} |
| 208 | |
| 209 | \begin{funcdesc}{geteuid}{} |
Guido van Rossum | eb0f066 | 1997-12-30 20:38:16 +0000 | [diff] [blame] | 210 | Return the current process' effective user id. |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 211 | (Not on MS-DOS.) |
| 212 | \end{funcdesc} |
| 213 | |
| 214 | \begin{funcdesc}{getgid}{} |
Guido van Rossum | eb0f066 | 1997-12-30 20:38:16 +0000 | [diff] [blame] | 215 | Return the current process' group id. |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 216 | (Not on MS-DOS.) |
| 217 | \end{funcdesc} |
| 218 | |
Guido van Rossum | 1e8b63e | 1996-06-26 19:22:46 +0000 | [diff] [blame] | 219 | \begin{funcdesc}{getpgrp}{} |
Fred Drake | 3b02ddf | 1998-12-21 18:52:53 +0000 | [diff] [blame] | 220 | \index{process!group} |
Guido van Rossum | 1e8b63e | 1996-06-26 19:22:46 +0000 | [diff] [blame] | 221 | Return the current process group id. |
| 222 | (Not on MS-DOS.) |
| 223 | \end{funcdesc} |
| 224 | |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 225 | \begin{funcdesc}{getpid}{} |
Fred Drake | 3b02ddf | 1998-12-21 18:52:53 +0000 | [diff] [blame] | 226 | \index{process!id} |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 227 | Return the current process id. |
| 228 | (Not on MS-DOS.) |
| 229 | \end{funcdesc} |
| 230 | |
| 231 | \begin{funcdesc}{getppid}{} |
Fred Drake | 3b02ddf | 1998-12-21 18:52:53 +0000 | [diff] [blame] | 232 | \index{process!id of parent} |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 233 | Return the parent's process id. |
| 234 | (Not on MS-DOS.) |
| 235 | \end{funcdesc} |
| 236 | |
| 237 | \begin{funcdesc}{getuid}{} |
Fred Drake | 3b02ddf | 1998-12-21 18:52:53 +0000 | [diff] [blame] | 238 | \index{user id} |
Guido van Rossum | eb0f066 | 1997-12-30 20:38:16 +0000 | [diff] [blame] | 239 | Return the current process' user id. |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 240 | (Not on MS-DOS.) |
| 241 | \end{funcdesc} |
| 242 | |
Fred Drake | cce1090 | 1998-03-17 06:33:25 +0000 | [diff] [blame] | 243 | \begin{funcdesc}{kill}{pid, sig} |
Fred Drake | 3b02ddf | 1998-12-21 18:52:53 +0000 | [diff] [blame] | 244 | \index{process!killing} |
| 245 | \index{process!signalling} |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 246 | Kill the process \var{pid} with signal \var{sig}. |
| 247 | (Not on MS-DOS.) |
| 248 | \end{funcdesc} |
| 249 | |
Fred Drake | cce1090 | 1998-03-17 06:33:25 +0000 | [diff] [blame] | 250 | \begin{funcdesc}{link}{src, dst} |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 251 | Create a hard link pointing to \var{src} named \var{dst}. |
| 252 | (Not on MS-DOS.) |
| 253 | \end{funcdesc} |
| 254 | |
| 255 | \begin{funcdesc}{listdir}{path} |
| 256 | Return a list containing the names of the entries in the directory. |
Guido van Rossum | 8c07bb4 | 1996-02-12 23:16:08 +0000 | [diff] [blame] | 257 | The list is in arbitrary order. It does not include the special |
| 258 | entries \code{'.'} and \code{'..'} even if they are present in the |
| 259 | directory. |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 260 | \end{funcdesc} |
| 261 | |
Fred Drake | cce1090 | 1998-03-17 06:33:25 +0000 | [diff] [blame] | 262 | \begin{funcdesc}{lseek}{fd, pos, how} |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 263 | Set the current position of file descriptor \var{fd} to position |
Fred Drake | 75aae9a | 1998-03-11 05:29:58 +0000 | [diff] [blame] | 264 | \var{pos}, modified by \var{how}: \code{0} to set the position |
| 265 | relative to the beginning of the file; \code{1} to set it relative to |
| 266 | the current position; \code{2} to set it relative to the end of the |
| 267 | file. |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 268 | \end{funcdesc} |
| 269 | |
| 270 | \begin{funcdesc}{lstat}{path} |
Fred Drake | 75aae9a | 1998-03-11 05:29:58 +0000 | [diff] [blame] | 271 | Like \function{stat()}, but do not follow symbolic links. (On systems |
| 272 | without symbolic links, this is identical to \function{stat()}.) |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 273 | \end{funcdesc} |
| 274 | |
Fred Drake | cce1090 | 1998-03-17 06:33:25 +0000 | [diff] [blame] | 275 | \begin{funcdesc}{mkfifo}{path\optional{, mode}} |
Fred Drake | 65b32f7 | 1998-02-09 20:27:12 +0000 | [diff] [blame] | 276 | Create a FIFO (a \POSIX{} named pipe) named \var{path} with numeric mode |
Fred Drake | 75aae9a | 1998-03-11 05:29:58 +0000 | [diff] [blame] | 277 | \var{mode}. The default \var{mode} is \code{0666} (octal). The current |
Guido van Rossum | 1e8b63e | 1996-06-26 19:22:46 +0000 | [diff] [blame] | 278 | umask value is first masked out from the mode. |
| 279 | (Not on MS-DOS.) |
| 280 | |
| 281 | FIFOs are pipes that can be accessed like regular files. FIFOs exist |
Fred Drake | 75aae9a | 1998-03-11 05:29:58 +0000 | [diff] [blame] | 282 | until they are deleted (for example with \function{os.unlink()}). |
| 283 | Generally, FIFOs are used as rendezvous between ``client'' and |
Guido van Rossum | 1e8b63e | 1996-06-26 19:22:46 +0000 | [diff] [blame] | 284 | ``server'' type processes: the server opens the FIFO for reading, and |
Fred Drake | 75aae9a | 1998-03-11 05:29:58 +0000 | [diff] [blame] | 285 | the client opens it for writing. Note that \function{mkfifo()} |
| 286 | doesn't open the FIFO --- it just creates the rendezvous point. |
Guido van Rossum | 1e8b63e | 1996-06-26 19:22:46 +0000 | [diff] [blame] | 287 | \end{funcdesc} |
| 288 | |
Fred Drake | cce1090 | 1998-03-17 06:33:25 +0000 | [diff] [blame] | 289 | \begin{funcdesc}{mkdir}{path\optional{, mode}} |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 290 | Create a directory named \var{path} with numeric mode \var{mode}. |
Fred Drake | 75aae9a | 1998-03-11 05:29:58 +0000 | [diff] [blame] | 291 | The default \var{mode} is \code{0777} (octal). On some systems, |
| 292 | \var{mode} is ignored. Where it is used, the current umask value is |
| 293 | first masked out. |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 294 | \end{funcdesc} |
| 295 | |
| 296 | \begin{funcdesc}{nice}{increment} |
Fred Drake | 75aae9a | 1998-03-11 05:29:58 +0000 | [diff] [blame] | 297 | Add \var{increment} to the process' ``niceness''. Return the new |
| 298 | niceness. (Not on MS-DOS.) |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 299 | \end{funcdesc} |
| 300 | |
Fred Drake | cce1090 | 1998-03-17 06:33:25 +0000 | [diff] [blame] | 301 | \begin{funcdesc}{open}{file, flags\optional{, mode}} |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 302 | Open the file \var{file} and set various flags according to |
| 303 | \var{flags} and possibly its mode according to \var{mode}. |
Fred Drake | 75aae9a | 1998-03-11 05:29:58 +0000 | [diff] [blame] | 304 | The default \var{mode} is \code{0777} (octal), and the current umask |
| 305 | value is first masked out. Return the file descriptor for the newly |
| 306 | opened file. |
Guido van Rossum | 2837970 | 1995-01-12 12:38:22 +0000 | [diff] [blame] | 307 | |
Fred Drake | 75aae9a | 1998-03-11 05:29:58 +0000 | [diff] [blame] | 308 | For a description of the flag and mode values, see the \UNIX{} or \C{} |
| 309 | run-time documentation; flag constants (like \constant{O_RDONLY} and |
| 310 | \constant{O_WRONLY}) are defined in this module too (see below). |
Guido van Rossum | 9c43c59 | 1997-08-08 21:05:09 +0000 | [diff] [blame] | 311 | |
Guido van Rossum | 2837970 | 1995-01-12 12:38:22 +0000 | [diff] [blame] | 312 | Note: this function is intended for low-level I/O. For normal usage, |
Fred Drake | 75aae9a | 1998-03-11 05:29:58 +0000 | [diff] [blame] | 313 | use the built-in function \function{open()}, which returns a ``file |
| 314 | object'' with \method{read()} and \method{write()} methods (and many |
| 315 | more). |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 316 | \end{funcdesc} |
| 317 | |
| 318 | \begin{funcdesc}{pipe}{} |
Fred Drake | 75aae9a | 1998-03-11 05:29:58 +0000 | [diff] [blame] | 319 | Create a pipe. Return a pair of file descriptors \code{(\var{r}, |
| 320 | \var{w})} usable for reading and writing, respectively. |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 321 | (Not on MS-DOS.) |
| 322 | \end{funcdesc} |
| 323 | |
Guido van Rossum | 38e5088 | 1996-07-21 02:21:49 +0000 | [diff] [blame] | 324 | \begin{funcdesc}{plock}{op} |
| 325 | Lock program segments into memory. The value of \var{op} |
| 326 | (defined in \code{<sys/lock.h>}) determines which segments are locked. |
| 327 | (Not on MS-DOS.) |
| 328 | \end{funcdesc} |
| 329 | |
Fred Drake | cce1090 | 1998-03-17 06:33:25 +0000 | [diff] [blame] | 330 | \begin{funcdesc}{popen}{command\optional{, mode\optional{, bufsize}}} |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 331 | Open a pipe to or from \var{command}. The return value is an open |
| 332 | file object connected to the pipe, which can be read or written |
Guido van Rossum | 2837970 | 1995-01-12 12:38:22 +0000 | [diff] [blame] | 333 | depending on whether \var{mode} is \code{'r'} (default) or \code{'w'}. |
| 334 | The \var{bufsize} argument has the same meaning as the corresponding |
Fred Drake | 75aae9a | 1998-03-11 05:29:58 +0000 | [diff] [blame] | 335 | argument to the built-in \function{open()} function. The exit status of |
| 336 | the command (encoded in the format specified for \function{wait()}) is |
| 337 | available as the return value of the \method{close()} method of the file |
Guido van Rossum | f35b884 | 1998-10-15 13:28:29 +0000 | [diff] [blame] | 338 | object, except that when the exit status is zero (termination without |
| 339 | errors), \code{None} is returned. |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 340 | (Not on MS-DOS.) |
| 341 | \end{funcdesc} |
| 342 | |
Fred Drake | cce1090 | 1998-03-17 06:33:25 +0000 | [diff] [blame] | 343 | \begin{funcdesc}{putenv}{varname, value} |
Fred Drake | 52405c8 | 1998-03-16 05:21:08 +0000 | [diff] [blame] | 344 | \index{environment variables!setting} |
Fred Drake | 75aae9a | 1998-03-11 05:29:58 +0000 | [diff] [blame] | 345 | Set the environment variable named \var{varname} to the string |
| 346 | \var{value}. Such changes to the environment affect subprocesses |
| 347 | started with \function{os.system()}, \function{os.popen()} or |
| 348 | \function{os.fork()} and \function{os.execv()}. (Not on all systems.) |
Guido van Rossum | f967bf6 | 1997-06-02 17:28:51 +0000 | [diff] [blame] | 349 | |
Fred Drake | 75aae9a | 1998-03-11 05:29:58 +0000 | [diff] [blame] | 350 | When \function{putenv()} is |
Guido van Rossum | f967bf6 | 1997-06-02 17:28:51 +0000 | [diff] [blame] | 351 | supported, assignments to items in \code{os.environ} are automatically |
Fred Drake | 75aae9a | 1998-03-11 05:29:58 +0000 | [diff] [blame] | 352 | translated into corresponding calls to \function{putenv()}; however, |
| 353 | calls to \function{putenv()} don't update \code{os.environ}, so it is |
Guido van Rossum | f967bf6 | 1997-06-02 17:28:51 +0000 | [diff] [blame] | 354 | actually preferable to assign to items of \code{os.environ}. |
| 355 | \end{funcdesc} |
| 356 | |
Guido van Rossum | 0bfd146 | 1997-10-05 18:54:52 +0000 | [diff] [blame] | 357 | \begin{funcdesc}{strerror}{code} |
| 358 | Return the error message corresponding to the error code in \var{code}. |
| 359 | \end{funcdesc} |
| 360 | |
Guido van Rossum | 74429ea | 1999-01-06 23:03:43 +0000 | [diff] [blame] | 361 | \begin{funcdesc}{ttyname}{fd} |
| 362 | Return a string which specifies the terminal device associated with |
| 363 | file-descriptor \var{fd}. If \var{fd} is not associated with a terminal |
| 364 | device, an exception is raised. |
| 365 | \end{funcdesc} |
| 366 | |
Fred Drake | cce1090 | 1998-03-17 06:33:25 +0000 | [diff] [blame] | 367 | \begin{funcdesc}{read}{fd, n} |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 368 | Read at most \var{n} bytes from file descriptor \var{fd}. |
| 369 | Return a string containing the bytes read. |
Guido van Rossum | 2837970 | 1995-01-12 12:38:22 +0000 | [diff] [blame] | 370 | |
| 371 | Note: this function is intended for low-level I/O and must be applied |
Fred Drake | 75aae9a | 1998-03-11 05:29:58 +0000 | [diff] [blame] | 372 | to a file descriptor as returned by \function{open()} or |
| 373 | \function{pipe()}. To read a ``file object'' returned by the |
| 374 | built-in function \function{open()} or by \function{popen()} or |
| 375 | \function{fdopen()}, or \code{sys.stdin}, use its |
| 376 | \method{read()} or \method{readline()} methods. |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 377 | \end{funcdesc} |
| 378 | |
| 379 | \begin{funcdesc}{readlink}{path} |
| 380 | Return a string representing the path to which the symbolic link |
| 381 | points. (On systems without symbolic links, this always raises |
Fred Drake | 75aae9a | 1998-03-11 05:29:58 +0000 | [diff] [blame] | 382 | \exception{error}.) |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 383 | \end{funcdesc} |
| 384 | |
Guido van Rossum | 8c07bb4 | 1996-02-12 23:16:08 +0000 | [diff] [blame] | 385 | \begin{funcdesc}{remove}{path} |
Fred Drake | 75aae9a | 1998-03-11 05:29:58 +0000 | [diff] [blame] | 386 | Remove the file \var{path}. See \function{rmdir()} below to remove a |
| 387 | directory. This is identical to the \function{unlink()} function |
| 388 | documented below. |
Guido van Rossum | 8c07bb4 | 1996-02-12 23:16:08 +0000 | [diff] [blame] | 389 | \end{funcdesc} |
| 390 | |
Fred Drake | cce1090 | 1998-03-17 06:33:25 +0000 | [diff] [blame] | 391 | \begin{funcdesc}{rename}{src, dst} |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 392 | Rename the file or directory \var{src} to \var{dst}. |
| 393 | \end{funcdesc} |
| 394 | |
| 395 | \begin{funcdesc}{rmdir}{path} |
| 396 | Remove the directory \var{path}. |
| 397 | \end{funcdesc} |
| 398 | |
| 399 | \begin{funcdesc}{setgid}{gid} |
Guido van Rossum | eb0f066 | 1997-12-30 20:38:16 +0000 | [diff] [blame] | 400 | Set the current process' group id. |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 401 | (Not on MS-DOS.) |
| 402 | \end{funcdesc} |
| 403 | |
Guido van Rossum | 1e8b63e | 1996-06-26 19:22:46 +0000 | [diff] [blame] | 404 | \begin{funcdesc}{setpgrp}{} |
Fred Drake | 75aae9a | 1998-03-11 05:29:58 +0000 | [diff] [blame] | 405 | Calls the system call \cfunction{setpgrp()} or \cfunction{setpgrp(0, |
| 406 | 0)} depending on which version is implemented (if any). See the |
| 407 | \UNIX{} manual for the semantics. |
Guido van Rossum | 1e8b63e | 1996-06-26 19:22:46 +0000 | [diff] [blame] | 408 | (Not on MS-DOS.) |
| 409 | \end{funcdesc} |
| 410 | |
Fred Drake | cce1090 | 1998-03-17 06:33:25 +0000 | [diff] [blame] | 411 | \begin{funcdesc}{setpgid}{pid, pgrp} |
Fred Drake | 75aae9a | 1998-03-11 05:29:58 +0000 | [diff] [blame] | 412 | Calls the system call \cfunction{setpgid()}. See the \UNIX{} manual |
| 413 | for the semantics. |
Guido van Rossum | 1e8b63e | 1996-06-26 19:22:46 +0000 | [diff] [blame] | 414 | (Not on MS-DOS.) |
| 415 | \end{funcdesc} |
| 416 | |
| 417 | \begin{funcdesc}{setsid}{} |
Fred Drake | 75aae9a | 1998-03-11 05:29:58 +0000 | [diff] [blame] | 418 | Calls the system call \cfunction{setsid()}. See the \UNIX{} manual |
| 419 | for the semantics. |
Guido van Rossum | 1e8b63e | 1996-06-26 19:22:46 +0000 | [diff] [blame] | 420 | (Not on MS-DOS.) |
| 421 | \end{funcdesc} |
| 422 | |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 423 | \begin{funcdesc}{setuid}{uid} |
Guido van Rossum | eb0f066 | 1997-12-30 20:38:16 +0000 | [diff] [blame] | 424 | Set the current process' user id. |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 425 | (Not on MS-DOS.) |
| 426 | \end{funcdesc} |
| 427 | |
| 428 | \begin{funcdesc}{stat}{path} |
Fred Drake | 75aae9a | 1998-03-11 05:29:58 +0000 | [diff] [blame] | 429 | Perform a \cfunction{stat()} system call on the given path. The |
| 430 | return value is a tuple of at least 10 integers giving the most |
| 431 | important (and portable) members of the \emph{stat} structure, in the |
| 432 | order |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 433 | \code{st_mode}, |
| 434 | \code{st_ino}, |
| 435 | \code{st_dev}, |
| 436 | \code{st_nlink}, |
| 437 | \code{st_uid}, |
| 438 | \code{st_gid}, |
| 439 | \code{st_size}, |
| 440 | \code{st_atime}, |
| 441 | \code{st_mtime}, |
| 442 | \code{st_ctime}. |
| 443 | More items may be added at the end by some implementations. |
| 444 | (On MS-DOS, some items are filled with dummy values.) |
| 445 | |
Fred Drake | 75aae9a | 1998-03-11 05:29:58 +0000 | [diff] [blame] | 446 | Note: The standard module \module{stat}\refstmodindex{stat} defines |
| 447 | functions and constants that are useful for extracting information |
Fred Drake | bb3b002 | 1999-01-11 18:36:23 +0000 | [diff] [blame] | 448 | from a \ctype{stat} structure. |
| 449 | \end{funcdesc} |
| 450 | |
| 451 | \begin{funcdesc}{statvfs}{path} |
| 452 | Perform a \cfunction{statvfs()} system call on the given path. The |
| 453 | return value is a tuple of 11 integers giving the most common |
| 454 | members of the \ctype{statvfs} structure, in the order |
| 455 | \code{f_bsize}, |
| 456 | \code{f_frsize}, |
| 457 | \code{f_blocks}, |
| 458 | \code{f_bfree}, |
| 459 | \code{f_bavail}, |
| 460 | \code{f_files}, |
| 461 | \code{f_ffree}, |
| 462 | \code{f_favail}, |
| 463 | \code{f_fsid}, |
| 464 | \code{f_flag}, |
| 465 | \code{f_namemax}. |
| 466 | |
| 467 | Note: The standard module \module{statvfs}\refstmodindex{statvfs} |
| 468 | defines constants that are useful for extracting information |
| 469 | from a \ctype{statvfs} structure. |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 470 | \end{funcdesc} |
| 471 | |
Fred Drake | cce1090 | 1998-03-17 06:33:25 +0000 | [diff] [blame] | 472 | \begin{funcdesc}{symlink}{src, dst} |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 473 | Create a symbolic link pointing to \var{src} named \var{dst}. (On |
Fred Drake | 75aae9a | 1998-03-11 05:29:58 +0000 | [diff] [blame] | 474 | systems without symbolic links, this always raises \exception{error}.) |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 475 | \end{funcdesc} |
| 476 | |
| 477 | \begin{funcdesc}{system}{command} |
| 478 | Execute the command (a string) in a subshell. This is implemented by |
Fred Drake | 75aae9a | 1998-03-11 05:29:58 +0000 | [diff] [blame] | 479 | calling the Standard \C{} function \cfunction{system()}, and has the |
| 480 | same limitations. Changes to \code{posix.environ}, \code{sys.stdin} |
| 481 | etc.\ are not reflected in the environment of the executed command. |
| 482 | The return value is the exit status of the process encoded in the |
| 483 | format specified for \function{wait()}. |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 484 | \end{funcdesc} |
| 485 | |
Guido van Rossum | 1e8b63e | 1996-06-26 19:22:46 +0000 | [diff] [blame] | 486 | \begin{funcdesc}{tcgetpgrp}{fd} |
| 487 | Return the process group associated with the terminal given by |
Fred Drake | 75aae9a | 1998-03-11 05:29:58 +0000 | [diff] [blame] | 488 | \var{fd} (an open file descriptor as returned by \function{open()}). |
Guido van Rossum | 1e8b63e | 1996-06-26 19:22:46 +0000 | [diff] [blame] | 489 | (Not on MS-DOS.) |
| 490 | \end{funcdesc} |
| 491 | |
Fred Drake | cce1090 | 1998-03-17 06:33:25 +0000 | [diff] [blame] | 492 | \begin{funcdesc}{tcsetpgrp}{fd, pg} |
Guido van Rossum | 1e8b63e | 1996-06-26 19:22:46 +0000 | [diff] [blame] | 493 | Set the process group associated with the terminal given by |
Fred Drake | 75aae9a | 1998-03-11 05:29:58 +0000 | [diff] [blame] | 494 | \var{fd} (an open file descriptor as returned by \function{open()}) |
Guido van Rossum | 1e8b63e | 1996-06-26 19:22:46 +0000 | [diff] [blame] | 495 | to \var{pg}. |
| 496 | (Not on MS-DOS.) |
| 497 | \end{funcdesc} |
| 498 | |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 499 | \begin{funcdesc}{times}{} |
Guido van Rossum | 1e15061 | 1995-09-13 17:36:35 +0000 | [diff] [blame] | 500 | Return a 5-tuple of floating point numbers indicating accumulated (CPU |
| 501 | or other) |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 502 | times, in seconds. The items are: user time, system time, children's |
Guido van Rossum | 1e15061 | 1995-09-13 17:36:35 +0000 | [diff] [blame] | 503 | user time, children's system time, and elapsed real time since a fixed |
| 504 | point in the past, in that order. See the \UNIX{} |
Fred Drake | 75aae9a | 1998-03-11 05:29:58 +0000 | [diff] [blame] | 505 | manual page \manpage{times}{2}. (Not on MS-DOS.) |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 506 | \end{funcdesc} |
| 507 | |
| 508 | \begin{funcdesc}{umask}{mask} |
| 509 | Set the current numeric umask and returns the previous umask. |
| 510 | (Not on MS-DOS.) |
| 511 | \end{funcdesc} |
| 512 | |
| 513 | \begin{funcdesc}{uname}{} |
| 514 | Return a 5-tuple containing information identifying the current |
| 515 | operating system. The tuple contains 5 strings: |
Fred Drake | 75aae9a | 1998-03-11 05:29:58 +0000 | [diff] [blame] | 516 | \code{(\var{sysname}, \var{nodename}, \var{release}, \var{version}, |
| 517 | \var{machine})}. Some systems truncate the nodename to 8 |
Guido van Rossum | 6bb1adc | 1995-03-13 10:03:32 +0000 | [diff] [blame] | 518 | characters or to the leading component; a better way to get the |
Fred Drake | 75aae9a | 1998-03-11 05:29:58 +0000 | [diff] [blame] | 519 | hostname is \function{socket.gethostname()}% |
Fred Drake | 371ecc0 | 1998-03-12 06:44:58 +0000 | [diff] [blame] | 520 | \withsubitem{(in module socket)}{\ttindex{gethostname()}} |
Fred Drake | 75aae9a | 1998-03-11 05:29:58 +0000 | [diff] [blame] | 521 | or even |
| 522 | \code{socket.gethostbyaddr(socket.gethostname())}% |
Fred Drake | 371ecc0 | 1998-03-12 06:44:58 +0000 | [diff] [blame] | 523 | \withsubitem{(in module socket)}{\ttindex{gethostbyaddr()}}. |
Guido van Rossum | eb0f066 | 1997-12-30 20:38:16 +0000 | [diff] [blame] | 524 | (Not on MS-DOS, nor on older \UNIX{} systems.) |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 525 | \end{funcdesc} |
| 526 | |
| 527 | \begin{funcdesc}{unlink}{path} |
Guido van Rossum | 8c07bb4 | 1996-02-12 23:16:08 +0000 | [diff] [blame] | 528 | Remove the file \var{path}. This is the same function as \code{remove}; |
| 529 | the \code{unlink} name is its traditional \UNIX{} name. |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 530 | \end{funcdesc} |
| 531 | |
Fred Drake | caa3379 | 1998-11-30 21:53:47 +0000 | [diff] [blame] | 532 | \begin{funcdesc}{utime}{path, (atime, mtime)} |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 533 | Set the access and modified time of the file to the given values. |
| 534 | (The second argument is a tuple of two items.) |
| 535 | \end{funcdesc} |
| 536 | |
| 537 | \begin{funcdesc}{wait}{} |
| 538 | Wait for completion of a child process, and return a tuple containing |
Guido van Rossum | 7e691de | 1997-05-09 02:22:59 +0000 | [diff] [blame] | 539 | its pid and exit status indication: a 16-bit number, whose low byte is |
| 540 | the signal number that killed the process, and whose high byte is the |
| 541 | exit status (if the signal number is zero); the high bit of the low |
| 542 | byte is set if a core file was produced. (Not on MS-DOS.) |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 543 | \end{funcdesc} |
| 544 | |
Fred Drake | cce1090 | 1998-03-17 06:33:25 +0000 | [diff] [blame] | 545 | \begin{funcdesc}{waitpid}{pid, options} |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 546 | Wait for completion of a child process given by proces id, and return |
Guido van Rossum | 7e691de | 1997-05-09 02:22:59 +0000 | [diff] [blame] | 547 | a tuple containing its pid and exit status indication (encoded as for |
Fred Drake | 75aae9a | 1998-03-11 05:29:58 +0000 | [diff] [blame] | 548 | \function{wait()}). The semantics of the call are affected by the |
| 549 | value of the integer \var{options}, which should be \code{0} for |
| 550 | normal operation. (If the system does not support |
| 551 | \function{waitpid()}, this always raises \exception{error}. Not on |
| 552 | MS-DOS.) |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 553 | \end{funcdesc} |
| 554 | |
Fred Drake | cce1090 | 1998-03-17 06:33:25 +0000 | [diff] [blame] | 555 | \begin{funcdesc}{write}{fd, str} |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 556 | Write the string \var{str} to file descriptor \var{fd}. |
| 557 | Return the number of bytes actually written. |
Guido van Rossum | 2837970 | 1995-01-12 12:38:22 +0000 | [diff] [blame] | 558 | |
| 559 | Note: this function is intended for low-level I/O and must be applied |
Fred Drake | 75aae9a | 1998-03-11 05:29:58 +0000 | [diff] [blame] | 560 | to a file descriptor as returned by \function{open()} or |
| 561 | \function{pipe()}. To write a ``file object'' returned by the |
| 562 | built-in function \function{open()} or by \function{popen()} or |
| 563 | \function{fdopen()}, or \code{sys.stdout} or \code{sys.stderr}, use |
| 564 | its \method{write()} method. |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 565 | \end{funcdesc} |
Guido van Rossum | 4bbe9c0 | 1995-03-30 16:00:36 +0000 | [diff] [blame] | 566 | |
| 567 | \begin{datadesc}{WNOHANG} |
Fred Drake | 75aae9a | 1998-03-11 05:29:58 +0000 | [diff] [blame] | 568 | The option for \function{waitpid()} to avoid hanging if no child |
| 569 | process status is available immediately. |
Guido van Rossum | 4bbe9c0 | 1995-03-30 16:00:36 +0000 | [diff] [blame] | 570 | \end{datadesc} |
Barry Warsaw | e5a43a4 | 1996-12-19 23:50:34 +0000 | [diff] [blame] | 571 | |
| 572 | |
| 573 | \begin{datadesc}{O_RDONLY} |
Fred Drake | 86b5dce | 1998-02-13 21:55:21 +0000 | [diff] [blame] | 574 | \dataline{O_WRONLY} |
| 575 | \dataline{O_RDWR} |
| 576 | \dataline{O_NDELAY} |
| 577 | \dataline{O_NONBLOCK} |
| 578 | \dataline{O_APPEND} |
| 579 | \dataline{O_DSYNC} |
| 580 | \dataline{O_RSYNC} |
| 581 | \dataline{O_SYNC} |
| 582 | \dataline{O_NOCTTY} |
| 583 | \dataline{O_CREAT} |
| 584 | \dataline{O_EXCL} |
| 585 | \dataline{O_TRUNC} |
Fred Drake | 75aae9a | 1998-03-11 05:29:58 +0000 | [diff] [blame] | 586 | Options for the \code{flag} argument to the \function{open()} function. |
Barry Warsaw | e5a43a4 | 1996-12-19 23:50:34 +0000 | [diff] [blame] | 587 | These can be bit-wise OR'd together. |
| 588 | \end{datadesc} |