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