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