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 complier 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.
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.
- Text/Code Segment:
It is the part of the object code which contains the actual code written .
- Data Segment:
It is the part of the object code which contains the data members .
- 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.
- i. Relocatable Address –
- 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
i. Paging ii. Segmentation iii. Segmented Paging
- Process states and Transitions in a UNIX Process
- Pass the value from child process to parent process
- Process Table and Process Control Block (PCB)
- Process Scheduler : Job and Process Status
- Reversal process in DFA
- TCP 3-Way Handshake Process
- Concatenation process in DFA
- Process Synchronization | Set 2
- Complementation process in DFA
- Union process in DFA
- Difference between Process and Thread
- Get/Set process resource limits in C
- Semaphores in Process Synchronization
- Monitors in Process Synchronization
- Inter Process Communication (IPC)
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.