In this article we are getting into Process Management and how the CPU management delegates into and their interactions with the kernel as well. So let’s continue with it.
Process Management :
Let’s first learn whether in a single core machine, are all the processes running at the same time? as we all know the answer i.e. No. Multiple processes can access the CPU in a given time span. But only one process may actually have the CPU at a given moment so single core.
How does this process management occur? we are going to explain it with a Process management example : –
- Suppose there is a process X, it will utilize the CPU for a predetermined amount of time which is time slice. Time Slice i.e. enough time for a significant calculation, usually a few milliseconds.
Here, Kernel controls the amount of time that’s allocated.
- Once the time’s up, process X is paused.
- Process Y starts etc.
Here is a core thing: – What occurs in the time between X and Y? Now is Kind of time to get in-depth here i.e. Context Switch.
Context Switch is a switching of one process to another. It is controlled by Kernel.
For Example – A Process time slice just finished then: 1. The CPU stops the current process and switches the CPU from user mode to Kernel mode i.e. Ring 3 to Ring 0.
The kernel records the current state of the CPU and memory. This is utilized when the process is returned.
- The kernel performs any tasks that come up during the previous time slice i.e. collecting I/O etc.
- Once completed, the Kernel’s Process Scheduler looks at the list of processes that needs to run and picks a process based on an algorithm.
- The kernel prepares the CPU into user mode so Ring 0 to Ring 3 and
- Execution of the next process begins.
More complicated i.e. Kernel doesn’t need to give away control of the CPU in order to allow a process to run. Why ? Because the process can run on a different CPU. However, this typically doesn’t occur because it can diminish system performance.
RAM Management : – Another huge thing that a Kernel does i.e. the Kernel keeps track of all RAM and how it’s shared between processes.
The Kernel splits RAM into many subdivisions that is Pages and maintains state information about these subdivisions at all times. Earlier we discussed about Pagetable and why we only utilize those rings 0 and 3.
In more common operating systems architecture How do we start to get into what is held in those Pagetables? The answer is simple : It is Pages.
-So, each process gets its own portion of RAM and the Kernel makes sure that each process doesn’t utilize the memory of other processes, i.e. Sandboxing that means a private memory. We have seen before that there are certain ways that user processes can actually share a common memory area but for all processes right now, the Kernel is making it sure that each process doesn’t utilize the Private memory of other processes.
Thus when does RAM management occurs? When does the Kernel take control? The answer is – During the Context Switch. The Kernel upholds the following conditions:
The Kernel must have its own private area in memory that the user processes can’t directly access. Then What this area is called? Each user process needs its own section of memory which can’t access the private memory of other user processes. So again what is this general idea called? As we just spoke about it pretty recently i.e. Sandboxing.
-Kernel upholds the following conditions :
If requested, user processes can share a memory with each other in a common area. Shared memory doesn’t come from a user process, that memory is always private. Shared memory comes from the system’s free memory pool.
Some memory in the user process can be flagged as ” Read Only”.
The system can use more memory that is physically present by using disk space. So it’s another thing that the Kernel helps to deal with. So how does it work? as it is very important and this has huge implications for memory management and particularly Sandboxing.
So, let’s See- Why memory management? or In general, why do we need memory management and particularly Sandboxing ?- The answer is – For security implications because a shared address space allows us to not be inhibited by the physical memory allotment.