From how computer works to how code compiles : A complete mental model

·

4 min read

There are many devices we use such as mobile phones, laptops, computers etc and for us to use these devices we download an operating system software. It manages the computer's memory and processes, as well as all of its software and hardware.
The most common types of operating systems are Microsoft Windows, macOS, Andriod OS and Linux.

So now we download tools and applications for different usage purposes on our devices.
To understand it better we consider these tools and applications as people and for those people to live in we need a house and here the house is the operating system.

Tools: A tool is a computer program used by software developers to create, debug, maintain, or support other programs and applications. Tools have no user interphase, and it runs on a specific set of code that is called software.
Examples of tools are JVM(Java Virtual Machine), JSEngine etc.

Applications: An application is a computer program designed to carry out a specific task other than one relating to the operation of the computer itself, typically to be used by end-users. Applications have user interphase.
Examples of Applications are Google Chrome, VS code, CodeBlocks, eclipse, Anaconda, jupyter notebook etc.

So what is user interphase anyways?
User interphase allows the user to interact with the device's apps, features, content and functions.

When we use the applications, it generates a task (for example you search for images of tigers in google chrome a task is generated) and then the task is generated into subtasks by the operating system and threads are assigned to the subtasks to attach them to the cores in the CPU.

What is a core?
A core is a small CPU or processor built into a big CPU or CPU socket. It can independently perform or process all computational tasks. More the number of cores in the CPU more is the efficiency of the system.

Coming back to subtasks, after the subtasks get assigned to the core by the operating system, the core requires memory to run the task and we get this memory from RAM (random access memory), one point to keep in mind is that RAM stores the tasks as cache memory.

what is cache memory?
It is a temporary storage of memory, cache makes data retrieving easier and more efficient. It is the fastest memory in a computer and is typically integrated onto the motherboard and directly embedded in the processor or main random access memory (RAM).

To run any task we have two requirements: cores(CPU) and memory(RAM)
For understanding this better let us consider a few cases of running the subtasks

  • Case 1: Our CPU has 8 cores(octacore) and we have 8 subtasks, lets say the memory of the RAM is 2GB , threads are assigned to those 8 tasks and the memory is just sufficient for running the tasks .....

  • Case 2: Just as in case 1, 8 cores but 10 subtasks so the algorithm of our operating system selects 8 subtasks and attaches to 8 cores by threads but what about the rest 2 subtasks ??
    They either wait until a subtask is fully executed or until a subtask turns into an idle task.

idle task: Idle means inactive so an Idle task is a task that is waiting for a response from the .......

so once the subtask is fully executed it detaches with the core and its memory disappears from the RAM and the new subtask is attached to the freed up core.

  • Case 3: In this task, we consider that we've got sufficient cores for our subtasks but the problem arises at memory shortage in RAM. So when there is a memory shortage in RAM we use the memory from the hard disk but Hard disk data is static and remains in the computer even if the computer is switched off so its usage is not as efficient as RAM, depending upon the case we either use memory from hard disk or wait until a subtask is fully executed.

    Once all subtasks are executed we say that our task is done and the task disappears