Concept of process, program counter, heap, stack and data section in OS (Operating System)
Program in Operating system:
Set of instructions to perform specific task is called program. Program is a passive entity. It contains all the logics and data to perfrom any task.
Process in Operating system:
When a program executes to perform the task it becomes the process. Process needs some kind of data which was writen in the instruction of the program to perform any task.
Attributes of the Process:
To save that data process have attributes or I say pockets where it saves the data.
The names and working of the attributes is as following:
Program Counter: It saves the next instruction which will executes after the instruction currently being executed.
Stack: You might be familier with the concept of varriable if you have programming experiance. When you make a program you declare some local varriables.
When your program will become the process those local varriable will be placed in the stack.
Data Section: What about the global varriables? which you made in your program those all gona stay here.
Heap: So heap is referd to the dynamic memory allocation.
What is Dynamic Memory allocation?
Let me answer it with a scenario. suppose you code a program with an array of size 4 you run the program and start giving data to array as input but suddenly you realise that you have few more reamaing values and array is not enough to accomudate all.
Now the one option is stop the program and increase the size of the array and the other option is increase the size at run time.
When you will increase the size of array at run time it will demand the memory in the system as well so you will provide the memory at run time.
This memory allocation at the run time is known as dynamic memory allocation.
How someone can increase the size of array at run time?
You must be thingking like this, You should think but let me tell you we have some features available which can provide the more memory to your program at run time you can implement those features in C++.
in case if you are intrested in learning those funtion let me give you himt.
Google the concept of malloc() Function in which the m = memory and alloc = allocation .
I must refer you to this article for the learning of malloc.
Example:
This is a simple C++ program with a function which returns the sum of 2 global varriables.
When we run this program, It will become the process there The global varriables of the program will go to the data section.
Local varriable of the program i.e sum will go to the stack. and program counter will keep trace of the lines of these instructions that which one line is currently being executed and which one is the next.
1 comment:
Thank u sir
Post a Comment