The Wayback Machine - https://web.archive.org/web/20241120234321/https://www.geeksforgeeks.org/formation-of-process-from-program/
Open In App

Formation Of Process from Program

Last Updated : 21 Jan, 2022
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

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. 

Note: 
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 


Similar Reads

Difference Between Process, Parent Process, and Child Process
Running program is a process. From this process, another process can be created. There is a parent-child relationship between the two processes. This can be achieved using a library function called fork(). fork() function splits the running process into two processes, the existing one is known as parent and the new process is known as a child. Here
8 min read
Process Scheduler : Job and Process Status
When the jobs moves through the system and makes progress, it changes it's states from HOLD to FINISH. When the job is being processed by the job manager and the process manager, it is always in one of these 5 states: HOLD: When a user submits a job and it accepts the job, the job is put on HOLD and placed in a queue. READY: A job is in READY state
2 min read
Difference between Process Image and Multi Thread Process image
1. Process Image : Process image is an executable file required during the execution of any process. It consists of several segments related to the execution of the process. Following are the contents of the process image - 1. Process Control Block 2. Stack 3. Data 4. Code 2. Multi Thread Process Image : Multi thread process image is an executable
2 min read
Process states and Transitions in a UNIX Process
Process is an instance of a program in execution. A set of processes combined together make a complete program. There are two categories of processes in Unix, namely User processes : They are operated in user mode. Kernel processes : They are operated in kernel mode. Understanding the distinction between user and kernel processes is essential for c
4 min read
Process Table and Process Control Block (PCB)
While creating a process, the operating system performs several operations. To identify the processes, it assigns a process identification number (PID) to each process. As the operating system supports multi-programming, it needs to keep track of all the processes. For this task, the process control block (PCB) is used to track the process’s execut
7 min read
Difference between Program and Process
In Computer Science, there are two fundamental terms in operating system: Program and Process. Program is a set of instructions written to perform a task, stored in memory. A process is the active execution of a program, using system resources like CPU and memory. In other words, a program is static, a process is dynamic, representing the program i
4 min read
Operating Systems | Process Management | Question 6
Consider the following code fragment: if (fork() == 0) { a = a + 5; printf("%d,%d\n", a, &a); } else { a = a –5; printf("%d, %d\n", a, &a); } Let u, v be the values printed by the parent process, and x, y be the values printed by the child process. Which one of the following is TRUE? (A) u = x + 10 and v = y (B) u = x +
2 min read
Operating Systems | Process Synchronization | Question 5
The atomic fetch-and-set x, y instruction unconditionally sets the memory location x to 1 and fetches the old value of x in y without allowing any intervening access to the memory location x. consider the following implementation of P and V functions on a binary semaphore . void P (binary_semaphore *s) { unsigned y; unsigned *x = &(s->value)
2 min read
Operating Systems | Process Management | Question 6
Three concurrent processes X, Y, and Z execute three different code segments that access and update certain shared variables. Process X executes the P operation (i.e., wait) on semaphores a, b and c; process Y executes the P operation on semaphores b, c and d; process Z executes the P operation on semaphores c, d, and a before entering the respecti
2 min read
Operating Systems | Process Management | Question 6
A shared variable x, initialized to zero, is operated on by four concurrent processes W, X, Y, Z as follows. Each of the processes W and X reads x from memory, increments by one, stores it to memory, and then terminates. Each of the processes Y and Z reads x from memory, decrements by two, stores it to memory, and then terminates. Each process befo
2 min read
Operating Systems | Process Management | Question 6
A shared variable x, initialized to zero, is operated on by four concurrent processes W, X, Y, Z as follows. Each of the processes W and X reads x from memory, increments by one, stores it to memory, and then terminates. Each of the processes Y and Z reads x from memory, decrements by two, stores it to memory, and then terminates. Each process befo
1 min read
Operating Systems | Process Management | Question 6
A certain computation generates two arrays a and b such that a[i]=f(i) for 0 â‰Ī i < n and b[i]=g(a[i]) for 0 â‰Ī i < n. Suppose this computation is decomposed into two concurrent processes X and Y such that X computes the array a and Y computes the array b. The processes employ two binary semaphores R and S, both initialized to zero. The array a
2 min read
Process-Based and Thread-Based Multitasking
Multitasking operating system is an operating system that gives you the perception of two or more tasks/jobs/processes running simultaneously. It does this by dividing system resources amongst these tasks/jobs/processes and switching between the tasks/jobs/processes while they are executing over and over again. The CPU processes only one task at a
2 min read
Communication between two process using signals in C
Prerequisite : C signal handling In this post, the communication between child and parent processes is done using kill() and signal(), fork() system call. fork() creates the child process from the parent. The pid can be checked to decide whether it is the child (if pid == 0) or the parent (pid = child process id).The parent can then send messages t
3 min read
Union process in DFA
Prerequisite - Designing finite automata To perform the union operation on two deterministic finite automata (DFAs), the following steps can be taken: Create a new DFA with a new set of states, consisting of all the states from both original DFAs.Define the initial state of the new DFA to be the tuple (q1, q2), where q1 and q2 are the initial state
5 min read
Concatenation process in DFA
Prerequisite - Designing finite automata Designing a DFA for the set of string over {a, b} such that string of the language start with "a" and end with "b". There two desired language will be formed: L1 = {a, aab, aabab, .......} L2 = {b, bbab, bbabab, .......} In L1, starting element is "a" and in L2, ending element is b. State Transition Diagram
2 min read
Message based Communication in IPC (inter process communication)
Prerequisites - Cloud computing, Load balancing in Cloud Computing, Inter-process Communication In the development of models and technologies, message abstraction is a necessary aspect that enables distributed computing. Distributed system is defined as a system in which components reside at networked communication and synchronise its functions onl
5 min read
Get/Set process resource limits in C
The getrlimit() and setrlimit() system calls can be used to get and set the resource limits such as files, CPU, memory etc. associated with a process. Each resource has an associated soft and hard limit. soft limit: The soft limit is the actual limit enforced by the kernel for the corresponding resource. hard limit: The hard limit acts as a ceiling
3 min read
Complementation process in DFA
Prerequisite – Design a Finite automata Suppose we have a DFA that is defined by ( Q, [Tex]\Sigma [/Tex], [Tex]\delta [/Tex], q0, F ) and it accepts the language L1. Then, the DFA which accepts the language L2 where L2 = Ė…L1', will be defined as below: ( Q, [Tex]\Sigma[/Tex], [Tex]\delta[/Tex], q0, Q-F ) The complement of a DFA can be obtained by m
2 min read
Process Scheduler : PCBs and Queueing
When the job scheduler accepts a job, it creates the job's PCB (Process Control Blocks) and updates it throughout the execution. These PCBs, and not the jobs, are linked to form the queues and are used to track the respective jobs. Note: The PCB store all of the data about the job being processed, like it's progress in the system. This data is need
1 min read
Two State Process Model in Operating System
Pre-requisite: States of a Process in Operating Systems The process in an operating system passes from different states starting from its formation to its completion. A process consists of program data and its associated data and a process control block (PCB). A process may change its state because of the following events like I/O requests, interru
3 min read
Process Creation and Deletions in Operating Systems
Prerequisite - States of a Process in Operating Systems There are two basic operations that can be performed on a process: Creation and Deletion. They are explained as Process creation: 1. When a new process is created, the operating system assigns a unique Process Identifier (PID) to it and inserts a new entry in the primary process table. 2. Then
2 min read
Difference between Process and Kernel Thread
1. Process: Process is an activity of executing a program. Process is of two types - User process and System process. Process control block controls the operation of the process. 2. Kernel Thread: Kernel thread is a type of thread in which threads of a process are managed at kernel level. Kernel threads are scheduled by operating system (kernel mod
1 min read
Difference between Process and User Level Thread
1. Process : Process is an activity of executing a program. Process is of two types - User process and System process. Process control block controls the operation of the process. 2. User Level Thread : On the basis of level, threads are of two types: User level Kernel Level User level thread is a type of thread in which threads of a process are ma
2 min read
Message Passing Model of Process Communication
So message passing means how a message can be sent from one end to the other end. Either it may be a client-server model or it may be from one node to another node. The formal model for distributed message passing has two timing models one is synchronous and the other is asynchronous. The fundamental points of message passing are: In message-passin
3 min read
FIFO Barbershop in Process synchronization
Overview :In process synchronization, there exists a Sleeping Barber problem, as discussed here. But in the above solution, there is no guarantee that the customers are served in the order they arrive in the barbershop, i.e. there is no guarantee that the customers enter a FIFO manner(First-in First-out). In the solution discussed above. Up to n cu
5 min read
Difference between Process Contention Scope and System Contention Scope
1. Process Contention Scope :In an operating system the thread library is schedules by an operating system known as kernel thread that is managed by a thread library for user level thread to runs off an available light weight process. This is often referred to as process contention scope.Process contention scope is executed accordingly to the prior
3 min read
Difference between Routine and Process
In this article, we are going to discuss the difference between routine and process. Before differentiating between both, first, let us understand what they are. Routine :In computer programming, a routine is nothing but a sequence of code, intended for the execution of user programs and input/output operations. It can range from a subroutine, co-r
3 min read
N process Peterson algorithm
Prerequisites for this topic include an idea about synchronization among processes and how to obtain it. Also, some knowledge of the producer-consumer problems along with an idea of Peterson's algorithm is of utmost importance. Overview :Synchronization among the execution of various processes in any operating system is of utmost importance. Which
8 min read
Difference between a process stack and a CPU stack
Temporary data like as method/function arguments, return address, and local variables are stored on the process Stack, whereas on the other hand, the CPU stack consists of a collection of data words. It employs the Last In First Out (LIFO) access technique, which is the most common in most CPUs. In this article we are going to find out the detailed
3 min read
three90RightbarBannerImg