Types of Process and State Management

Overview of Processes

  • A process encapsulates all state of a running application.

    • Includes code, data, and all necessary variables.

    • Each element of process state uniquely identified by its address.

Address Space

  • An OS abstraction to encapsulate process state is called the address space.

    • Defined by a range of addresses from v zero (v₀) to v max (v_max).

    • Different types of process states occupy different regions within this address space.

Types of Process State

Static State

  • Code (Text): The executable instructions.

  • Data: Static data available at initialization.

    • This is all considered static state available during process loading.

Dynamic State

  • Heap: An area of the address space for dynamically created state.

    • Allocates memory for temporary results and reads data from files.

    • In the address space representation:

    • The heap is shown as a contiguous portion, typically located after static data.

    • Realistically, there may be gaps or holes within the heap space.

    • Some areas may not hold any data relevant to the process and could be inaccessible.

Stack

  • The stack is another crucial part of dynamic state within the address space.

    • Grows and shrinks during process execution, managing data in a last in, first out (LIFO) order.

    • Each entry on the stack is processed in reverse order of its addition, making stack management pivotal during execution.

Stack Operations

  • When calling a procedure (e.g., moving execution to a different code segment):

    • The current state (e.g., local variables, program counter) is saved onto the stack.

    • Control jumps to the new procedure (e.g., Procedure Y).

    • Once execution of Procedure Y finishes, the state from the stack is popped back to restore parameters to their prior values.

Significance of the Stack

  • The LIFO nature of the stack is advantageous at various points during execution, ensuring safe state restoration after function calls.

  • The stack serves as an effective data structure for managing function calls and local state across diverse contexts within the process.