ROTATE the screen to landscape
Controls
Current Process:
Current subsystem:
Subsystem instructions
Interrupt Handlers
Displays
CPU
Dialog
📋 Click the "Start" button in the 'Controls' section. |
What is context?
A process context refers to the current execution state and
information associated with a running process in an operating system. It represents a snapshot of
the process's execution at a particular point in time.
Process context can change dynamically while the process is executing on the CPU.
What is PCB?:
In order to virtualize the execution of a process, the OS needs to have an internal account of the
state of a process. This representation of the state of a process is stored in memory as a Process
Control Block(PCB).
The PCB is used primarily during context switches, but it doesn't actively reflect the process's
changing context while it's running. Instead, the changing process context is stored in various CPU
registers and memory locations, not within the PCB.
Program A: Simple addition program
#include
int main()
{
int a, b, c;
a = 5;
b = 10;
c = a + b;
return c;
}
Program B: Read and add program
#include
int main()
{
int a, b, c;
a = 15;
scanf("%d", &b);
c = a + b;
return c;
}
Here are few commands that will help you understand the context switching in linux OS.
$ grep ctxt /proc/$pid/status
The above command will give you the number of context switches that have happened for the process with
the given pid. You can get the pid of a process using the following command.
$ htop
Another good way to inspect a process on your system is using the vmstat
command. This will
give you a detailed overview of the number of context switches, number of interrupts, and further
information like the cache used etc.