Process Address Space and Structure

By | September 13, 2021

Process Address Space

  • ┬áIn multiprogramming environments, where several user processes resides in the memory at the same time, protection is an important issue. The operating system residing in the memory also needs to be protected from the user processes.
  • It is also important that the various processes should not interfere with each other and should not alter the programs or data belonging to another process.
  • This problem of protection is solved by operating system by using the concept of address space. The address space in a system is usually divided into two parts
  1. Kernel space. The operating system programs and its data occupies this address space.
  2. User space. This space is shared by various user processes that are running in a system.

Process Address Space and Structure

  • Each user process is assigned a separate private address space. This space contains the programs and data of the process that it can access and execute.
  • The various processes remain restricted to their own address spaces and cannot access each other’s and kernel address space. These processes can interact with each other and kernel only using certain communication commands provided by the operating system.
  • If some process tries to access program and data outside its own address space, the system considers this as an address space violation and takes the necessary action as to prevent this illegal access.
  • The process keep on shifting between kernel space and user space in course of their execution.
  • The process primarily executes application programs in the user space. When it executes OS programs, it is in kernel space.
  • On the other hand, the original kernel processes always execute in the kernel space and never in user space.
  • Whenever a new process is created, the operating system initializes its private address space in user space. However, when a process wants to execute a new program, the operating system reinitializes the process address space. For this, it first destroys the old address space and then creates a new address space.
  • In theory, an address space can be infinite and countable. But in practice, address spaces are of finite and limited sizes only because of the limited availability of resources.
  • The size of address space depends on the underlying processor architecture.

Process Address Space Structure

  • The address space of a process contains programs and data of a process.
  • This space is usually divided into number of blocks of different sizes. The code and data section are divided into many partitions.
  • The process contains both static data and dynamic data. The static data comes from the application programs of process and the various libraries it uses. The dynamic data is obtained by a process when it gets executed.
  • The address space of a process may expand and shrink during its lifetime as it keeps on allocating and releasing dynamic entities to its address space. However, a process cannot release the space allocated to static data as it belongs to application programs and libraries. This space is released by process only when it releases the corresponding programs.

Structure of process address space

In UNIX operating system, the private address space of a process is divided into four blocks. These are :

1. Code block

  • It is also called text section and contains machine instructions that are executed by CPU.
  • This is made up of codes from executable image and various libraries.
  • In modern OS, this code block cannot be modified by processes. As a result multiple processes can share the same code block. This code sharing is automatically set by operating system. The processes are usually not aware of this sharing and behaves as if each one is having its own copy of code block.
  • Usually, OS does not allow any process to perform write operation on code block. If any process tries to do it the operating system terminates this process forcefully.

2. Data Block

Data Block contains the program’s own static data.

This block is divided into three sub-blocks.

(a) Initialized read-only block. It contains values that are set by program at compile time. It is initialized by the program and process cannot change it.

(b) Initialized read-write block. It is also initialized by the program. A process can change data in this block.

(c) Uninitialized block. It is not kept as a part of the compiled program. It is not initialized by program.

3. Stack Block

  • This portion of address space is usually dynamic and is used by the process to store local variables and parameter values for function executions and return addresses for function calls.
  • The data contained is stack is used only at runtime.
  • The data is entered into the structure using push operation that adds the data value at the top of stack and is removed using pop operation that deletes value from the top of stack.
  • Thus, push and pop operations enable the process’s address space to expand and shrink respectively.

4. Heap block

  • It is used to allocate more data values dynamically to the process address space.
  • Heap’s data is dynamic in nature and is used only at runtime.
  • The space allocations and deallocations are done in arbitrary order and size. The allocation and deallocation of space to heap expands and shrinks the address space of process.

Leave a Reply

Your email address will not be published. Required fields are marked *