Open In App
Related Articles

Formation Of Process from Program

Improve Article
Save Article
Like Article

Process: A Process is a program in execution is called as Program. 

But the conversion of a program into process involves various stages which are clearly defined in this article. Further more after the program is converted into the process memory has to be allocated to these process in the main memory and these memory allocations are handled by O.S using various methods and algorithms explained towards end of this article. 

Initially when we write our code in the text editor (be it any language) is stored in the main memory.And when we call the compiler it takes this code and converts into assembly code i.e it converts the High level code int Low level Code. Then the assembler take this assembly code generated after compilation and converts into object code. This object code is of 0’s and 1’s but this code cannot be executed directly. 

To execute the code the explained below steps are adopted sequentially. The process of conversion of High level code to Low level code is done by compiler and those steps are defined clearly in Compiler Design course rest all steps are handled by O.S. The assembler is different for different platforms. 

In modern days, the compiler does all of the below listed work for us .Thus we don’t face the trouble of separately compiling, after that linking and Loading to the main memory . 

During the Compilation Of Code it under goes steps defined below: 

The Object Code Produced After All the above steps has the following sections namely:  

1. Header
2. Text/Code Segment
3. Data Segment
4. Relocation Information
5. Symbol Table
6. Debugging Information 

These are explained as following below. 

  1. Header: 
    It says what are the sections available in the Object Code and what are the locations at which various sections are present in the main memory. It is like it keeps a pointer to the locations of all sections. 
  2. Text/Code Segment: 
    It is the part of the object code which contains the actual code written . 
  3. Data Segment: 
    It is the part of the object code which contains the data members . 
  4. Relocation Information: 
    There are 2 kinds of address – 
    • i. Relocatable Address – 
      The address is relative to 0 as the actual place where program is to be loaded is not known in the compile time. 


    • ii. Absolute Address – 
      The Relocatable Address is converted to Absolute address when the program is finally loaded in the main memory as that point the exact location where the program is loaded would be known. 


  1. Symbol Table: 
    Contains all the Symbols i.e all the variables used and all the functions used.It also keeps track of the addresses of functions that are defined by us or functions which are default . 

    The symbol table contain the address of functions defined by us but it might lack the address of the default functions because in our program we don’t define again and again the default functions. Thus, the address of the default functions would remain un-resolved in the symbol table. 

    Now this un-resolved addresses would be resolved by Linker in the later steps. 

    The programs are designed in such a way that never a single object code is self sufficient rather various object codes are taken in to count to convert into correct executable code. So, each object code takes help of several other Object codes. 

    Now it is the linker which re-solves all the un-resolved addresses in the symbol table by taking help from various other object codes where the specific functions would be defined.The Linker to find sources to resolve the addresses would initially look into the same directory as of the program then if not found would go to the directory specified by compiler. 

Linker Works in 2 Phases: 

I. First Phase: 
Here it find what are the segments that are present and which segments are to be loaded. It uses 2 tables: Segment Table, and Symbol Table. 

  • 1. Segment Table – It is used to find the segments that are to be loaded. 
  • 2. Symbol Table – It is used to find the symbols that are un-resolved in the Symbol Table and are to be resolved . 


II. Second Phase: 
Here in this phase the Linker actually resolves all the un-resolved Symbols in Symbol Table. 

As mentioned above that still some symbols are left un-resolved intentionally because these are commonly used by the program so it kept in the main memory directly. So, when we need to resolved we directly ask for the address present in the main memory instead repeatedly keeping the same code. This part of code is called as Stub Code

So, the Linker combines all the Object code to produce a single Object code where all the addresses would be resolved (except a few which are commonly used). So, the main functions that Linker Performs are :-  

1. Relocation
2. Symbol Resolution 

Thus the Linker outputs a Relocatable Code

Now the Loader will come in to the picture.Function of the Loader is to the program in to main memory.The loader knows where the program is to be loaded. Now when the process is loaded on the main memory the memory allocation can be :- 

1. Contiguous Memory allocation: 

i. Static allocation
ii. Dynamic allocation 

2. Non-Contiguous Memory allocation: 

i. Paging
ii. Segmentation
iii. Segmented Paging 
Last Updated : 21 Jan, 2022
Like Article
Save Article
Similar Reads