process.eh

Work with program processes. More...

use "process.eh"

Constants

const MAX_PRIORITY = 10
const MIN_PRIORITY = 1
const NORM_PRIORITY = 5
const PS_ENDED = 5
const PS_NEW = 0
const PS_RUNNING = 1

Types

type Process < Any;

Functions

def new_process(): Process;
def Process.get_cwd(): String;
def Process.get_err(): OStream;
def Process.get_error(): Error;
def Process.get_exitcode(): Int;
def Process.get_in(): IStream;
def Process.get_name(): String;
def Process.get_out(): OStream;
def Process.get_priority(): Int;
def Process.get_state(): Int;
def Process.getenv(key: String): String;
def Process.interrupt();
def Process.set_cwd(dir: String);
def Process.set_err(err: OStream);
def Process.set_in(in: IStream);
def Process.set_out(out: OStream);
def Process.set_priority(value: Int);
def Process.setenv(key: String, value: String);
def Process.start(prog: String, args: [String]);
def Process.start_wait(prog: String, args: [String]): Int;
def this_process(): Process;

Description

This header allows you to run one program from another in a more complex way than exec and exec_wait do. It provides routines to work with program processes including process of the current program.

A process lifecycle consists of three steps.

  1. A process created with new_process() is initially in PS_NEW state. In this state you can configure it setting numerous attributes, such as priority, input/output streams, current working directory.
  2. When you call start or start_wait process enters PS_RUNNING state. Running process executes program until it is ended by itself or interrupted.
  3. When program ends, process enters final state PS_ENDED. In this state you can examine exit code of the process, and check if it ended with error.

Constant details

const PS_NEW = 0
A state of process that has been created but not yet started.

const PS_RUNNING = 1
A state of process that has been started and not yet died.

const PS_ENDED = 5
A state of process that has been terminated.

const MIN_PRIORITY = 1
The minimum priority that a process can have.

const NORM_PRIORITY = 5
The default priority assigned to a process.

const MAX_PRIORITY = 10
The maximum priority that a process can have.

Type details

type Process < Any;
Instance of executing program.

Function details

def this_process(): Process;
Returns reference to the process of current program.

def new_process(): Process;
Creates new process.

def Process.get_state(): Int;
Returns state of the process. State is one of PS_* constants defined in this header.

def Process.getenv(key: String): String;
Returns value of environment variable of this process.

def Process.setenv(key: String, value: String);
Sets value to the environment variable of this process.

def Process.get_in(): IStream;
Returns default input stream associated with the process.

def Process.get_out(): OStream;
Returns default output stream associated with the process.

def Process.get_err(): OStream;
Returns default error stream associated with the process.

def Process.set_in(in: IStream);
Sets new input stream for the process.

def Process.set_out(out: OStream);
Sets new output stream for the process.

def Process.set_err(err: OStream);
Sets new error stream for the process.

def Process.get_cwd(): String;
Returns current working directory of the process.

def Process.set_cwd(dir: String);
Sets current working directory of the process.

def Process.start(prog: String, args: [String]);
Starts specified program in this process. This function can be called only in PS_NEW state. After calling this function process enters PS_RUNNING state.

def Process.start_wait(prog: String, args: [String]): Int;
Starts specified program in this process and waits for it to die. This function can be called only when process is in PS_NEW state. Current process blocks until running process terminates.

def Process.get_priority(): Int;
Returns current priority of the process.

def Process.set_priority(value: Int);
Sets new priority to the process.

def Process.get_name(): String;
Returns name of the program this process executes. Returns null if the process is in PS_NEW state.

def Process.interrupt();
Interrupts the process. This function can be called only when process is in PS_RUNNING state. If the process is blocked waiting for some external operation, that operation is interrupted and process receives error ERR_INTERRUPT. If process is running normally, this function does nothing.

def Process.get_error(): Error;
If process ended with error, returns corresponding error object.

def Process.get_exitcode(): Int;
Returns exit code of the process.