Difference between a process stack and a CPU stack
Last Updated :
16 Jul, 2021
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 difference between both of these.
1. Example of a Process Stack :
C
#include <stdio.h>
int main() {
printf("Geeks for Geeks \n");
return 0;
}
Analysis : This code only prints out one line as this is only limited to a process, which gets terminated after its completion.
2. Example of a CPU Stack :
C
#include <stdio.h>
int GeeksforGeeks(int parameter1, char parameter2)
{
int local1 = 9;
char local2 = 'Z';
return 0;
}
int main(int argc, char* argv[])
{
GeeksforGeeks(7, '9');
return 0;
}
Output :
int main(int argc, char *argv[])
{
00401060 push ebp
00401061 mov ebp, esp
00401063 sub esp, 40h
00401066 push ebx
00401067 push esi
00401068 push edi
00401069 lea edi, [ebp-40h
0040106C mov ecx, 10h
00401071 mov eax, 0CCCCCCCCh
00401076 rep stos dword ptr [edi]}
Analysis : As you can see these all are the different CPU registers which are displayed on running this, as the CPU Stack is a bigger process.
Difference between a process stack and a CPU stack :
Process Stack
| CPU Stack
|
---|
Each process has its own Process Control Block (PCB) to save such information on a context switch, allowing the scheduling algorithm to function on a basic process ID. | Each process doesn't own its own PCB, hence status of a process is also contained in the registers to be stored for eviction. |
The PCB associated with that ID is restored when a process obtains the CPU. | The PCB associated with that ID is not restored unlike Process Stack. |
A stack is nothing more than a memory block. | It consists of several memory blocks grouped together. |
Each processor mode generally has its own stack in a process. Each thread in multithreading has its own stack. | Each CPU mode generally posses a unique stack. There can be several stacks in a process. |
When a context transition happens, the kernel "kicks out" the old process and brings in a new one. | When context transition happens, its prior state is restored in order for it to resume execution where it left off. |
There are a finite number of registers in every architecture. | Saving registers on the stack is for efficiency's sake, so all you have to do now is re-enter the values. |
Local variables are stored in the Stack. When local variables are declared, space on the stack is set aside for them. | The stack pointer increases to the next physical memory location when a new data item is inserted or "pushed" onto the top of a stack, and the new item is copied to that address. |
Counting on all of the above, those were the differences, hope this article helped you in identifying them, also do note that though the two may sound somewhat similar, but the small changes make it ubiquitous.
Similar Reads
Difference between Job, Task and Process In operating system the concept of job, process, and task revolves around each other.Job is work that needs to be done. A task is a piece of work that needs to be done. The process is a series of actions that is done for a particular purpose. Job and task define the work to be done, whereas process
6 min read
Difference between MEAN Stack and MEEN Stack What are stacks? What is a stack, if you are familiar with full-stack development you might have come across the terms MEAN, MERN, MEVN, MEEN, etc. These are web stacks consisting of a collection of software and frameworks used for building a web application from the front-end and back-end. You can
4 min read
Difference between Process and Thread Process and threads are the basic components in OS. Process is a program under execution whereas a thread is part of process. Threads allows a program to perform multiple tasks simultaneously, like downloading a file while you browse a website or running animations while processing user input. A pro
7 min read
Difference between Software and Processor 1. Software : Software, as name suggest, are simply computer programs or set of instructions that are used to control computer, develop and run applications and are originally written by computer programmers. 2. Processor : Processor, as name suggests, is simply an integrated electronic circuit that
2 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
4 min read