GNU Info

Info Node: (python2.1-lib.info)Process Management

(python2.1-lib.info)Process Management


Next: Miscellaneous System Information Prev: Files and Directories Up: os
Enter node , (file) or (file)node

Process Management
------------------

These functions may be used to create and manage processes.

The various `exec*()' functions take a list of arguments for the new
program loaded into the process.  In each case, the first of these
arguments is passed to the new program as its own name rather than as
an argument a user may have typed on a command line.  For the C
programmer, this is the `argv[0]' passed to a program's `main()'.  For
example, `os.execv('/bin/echo', ['foo', 'bar'])' will only print `bar'
on standard output; `foo' will seem to be ignored.

`abort()'
     Generate a `SIGABRT' signal to the current process.  On UNIX, the
     default behavior is to produce a core dump; on Windows, the
     process immediately returns an exit code of `3'.  Be aware that
     programs which use `signal.signal()' to register a handler for
     `SIGABRT' will behave differently.  Availability: UNIX, Windows.

`execl(path, arg0, arg1, ...)'
     This is equivalent to `execv(PATH, (ARG0, ARG1, ...))'.
     Availability: UNIX, Windows.

`execle(path, arg0, arg1, ..., env)'
     This is equivalent to `execve(PATH, (ARG0, ARG1, ...), ENV)'.
     Availability: UNIX, Windows.

`execlp(path, arg0, arg1, ...)'
     This is equivalent to `execvp(PATH, (ARG0, ARG1, ...))'.
     Availability: UNIX, Windows.

`execv(path, args)'
     Execute the executable PATH with argument list ARGS, replacing the
     current process (i.e., the Python interpreter).  The argument list
     may be a tuple or list of strings.  Availability: UNIX, Windows.

`execve(path, args, env)'
     Execute the executable PATH with argument list ARGS, and
     environment ENV, replacing the current process (i.e., the Python
     interpreter).  The argument list may be a tuple or list of strings.
     The environment must be a dictionary mapping strings to strings.
     Availability: UNIX, Windows.

`execvp(path, args)'
     This is like `execv(PATH, ARGS)' but duplicates the shell's
     actions in searching for an executable file in a list of
     directories.  The directory list is obtained from
     `environ['PATH']'.  Availability: UNIX, Windows.

`execvpe(path, args, env)'
     This is a cross between `execve()' and `execvp()'.  The directory
     list is obtained from `ENV['PATH']'.  Availability: UNIX, Windows.

`_exit(n)'
     Exit to the system with status N, without calling cleanup
     handlers, flushing stdio buffers, etc.  Availability: UNIX,
     Windows.

     Note: the standard way to exit is `sys.exit(N)'.  `_exit()' should
     normally only be used in the child process after a `fork()'.

`fork()'
     Fork a child process.  Return `0' in the child, the child's
     process id in the parent.  Availability: UNIX.

`forkpty()'
     Fork a child process, using a new pseudo-terminal as the child's
     controlling terminal. Return a pair of `(PID, FD)', where PID is
     `0' in the child, the new child's process id in the parent, and
     `fd' is the file descriptor of the master end of the
     pseudo-terminal.  For a more portable approach, use the `pty'
     module.  Availability: Some flavors of UNIX

`kill(pid, sig)'
     Kill the process PID with signal SIG.  Availability: UNIX.

`nice(increment)'
     Add INCREMENT to the process's "niceness".  Return the new
     niceness.  Availability: UNIX.

`plock(op)'
     Lock program segments into memory.  The value of OP (defined in
     `<sys/lock.h>') determines which segments are locked.
     Availability: UNIX.

`popen(...)'

`popen2 ...'

`popen3 ...'

`popen4 ...'
     Run child processes, returning opened pipes for communications.
     These functions are described in section Note: File Object
     Creation.

`spawnv(mode, path, args)'
     Execute the program PATH in a new process, passing the arguments
     specified in ARGS as command-line parameters.  ARGS may be a list
     or a tuple.  MODE is a magic operational constant.  See the Visual
     C++ Runtime Library documentation for further information; the
     constants are exposed to the Python programmer as listed below.
     Availability: UNIX, Windows.  _Added in Python version 1.6_

`spawnve(mode, path, args, env)'
     Execute the program PATH in a new process, passing the arguments
     specified in ARGS as command-line parameters and the contents of
     the mapping ENV as the environment.  ARGS may be a list or a
     tuple.  MODE is a magic operational constant.  See the Visual C++
     Runtime Library documentation for further information; the
     constants are exposed to the Python programmer as listed below.
     Availability: UNIX, Windows.  _Added in Python version 1.6_

`P_WAIT'

`P_NOWAIT'

`P_NOWAITO'
     Possible values for the MODE parameter to `spawnv()' and
     `spawnve()'.  Availability: UNIX, Windows.  _Added in Python
     version 1.6_

`P_OVERLAY'

`P_DETACH'
     Possible values for the MODE parameter to `spawnv()' and
     `spawnve()'.  These are less portable than those listed above.
     Availability: Windows.  _Added in Python version 1.6_

`startfile(path)'
     Start a file with its associated application.  This acts like
     double-clicking the file in Windows Explorer, or giving the file
     name as an argument to the DOS `start' command: the file is opened
     with whatever application (if any) its extension is associated.

     `startfile()' returns as soon as the associated application is
     launched.  There is no option to wait for the application to close,
     and no way to retrieve the application's exit status.  The PATH
     parameter is relative to the current directory.  If you want to
     use an absolute path, make sure the first character is not a slash
     (`/'); the underlying Win32 `ShellExecute()' function doesn't work
     it is.  Use the `os.path.normpath()' function to ensure that the
     path is properly encoded for Win32.  Availability: Windows.
     _Added in Python version 2.0_

`system(command)'
     Execute the command (a string) in a subshell.  This is implemented
     by calling the Standard C function `system()', and has the same
     limitations.  Changes to `posix.environ', `sys.stdin', etc. are
     not reflected in the environment of the executed command.  The
     return value is the exit status of the process encoded in the
     format specified for `wait()', except on Windows 95 and 98, where
     it is always `0'.  Note that POSIX does not specify the meaning of
     the return value of the C `system()' function, so the return value
     of the Python function is system-dependent.  Availability: UNIX,
     Windows.

`times()'
     Return a 5-tuple of floating point numbers indicating accumulated
     (CPU or other) times, in seconds.  The items are: user time,
     system time, children's user time, children's system time, and
     elapsed real time since a fixed point in the past, in that order.
     See the UNIX manual page `times(2)' or the corresponding Windows
     Platform API documentation.  Availability: UNIX, Windows.

`wait()'
     Wait for completion of a child process, and return a tuple
     containing its pid and exit status indication: a 16-bit number,
     whose low byte is the signal number that killed the process, and
     whose high byte is the exit status (if the signal number is zero);
     the high bit of the low byte is set if a core file was produced.
     Availability: UNIX.

`waitpid(pid, options)'
     Wait for completion of a child process given by process id PID,
     and return a tuple containing its process id and exit status
     indication (encoded as for `wait()').  The semantics of the call
     are affected by the value of the integer OPTIONS, which should be
     `0' for normal operation.  Availability: UNIX.

     If PID is greater than `0', `waitpid()' requests status
     information for that specific process.  If PID is `0', the request
     is for the status of any child in the process group of the current
     process.  If PID is `-1', the request pertains to any child of the
     current process.  If PID is less than `-1', status is requested
     for any process in the process group `-PID' (the absolute value of
     PID).

`WNOHANG'
     The option for `waitpid()' to avoid hanging if no child process
     status is available immediately.  Availability: UNIX.

The following functions take a process status code as returned by
`system()', `wait()', or `waitpid()' as a parameter.  They may be used
to determine the disposition of a process.

`WIFSTOPPED(status)'
     Return true if the process has been stopped.  Availability: UNIX.

`WIFSIGNALED(status)'
     Return true if the process exited due to a signal.  Availability:
     UNIX.

`WIFEXITED(status)'
     Return true if the process exited using the `exit(2)' system call.
     Availability: UNIX.

`WEXITSTATUS(status)'
     If `WIFEXITED(STATUS)' is true, return the integer parameter to
     the `exit(2)' system call.  Otherwise, the return value is
     meaningless.  Availability: UNIX.

`WSTOPSIG(status)'
     Return the signal which caused the process to stop.  Availability:
     UNIX.

`WTERMSIG(status)'
     Return the signal which caused the process to exit.  Availability:
     UNIX.


automatically generated by info2www version 1.2.2.9