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