Backend Engineering

Kernel, Thread VS Process

brian | Published: Feb. 29, 2024, 4:10 p.m. | Updated: May 25, 2025, 7:37 p.m.

Profile Picture

 

What is kernel? 

The kernel is a computer program at the core of the computers operating system, and generally has control over everything in the system. The kernel acts as a bridge between software and hardware, and manages things such as the CPU by helping to translate and give instructions. The kernel also manages IO devices such as: Keyboard, mice, USB, printer, etc. In RAM, the kernel is responsible for deciding which memory each process can use, and determining what to do when not enough memory is available. The important code of the kernal is stored in another  location, seperate from the rest of the applications. If you look above, the things stored in the "Application" portion can include things like Google Chrome, video player, and Microsoft Word.

 

Types of kernels

1. Monolithic Kernel

In a monolithic kernel all the os services run along side the kernels thread, and so it resides in the memory area. 

 

pros:  rich and powerful hardware access,  monolithic Kernal is fast

cons: a bug in the device driver can cause the entire system to fail

 

2. Hybrid Kernel

combines the speed of monolithic kernel, and the execution safety of the microkernel

 

 

 

Process

 

A Process is an instance of a computer program (ie. a python program you have wrote) which is being executed by one or more threads. When a program is ran, there will be one process or multiple that will be created. A process is basically the execution of the computer program instructions.

Things to Note:

1. Processes get scheduled in the CPU for execution

2. Every single process has a unique identifier/memory address that the OS assigns to it

3. One process cannot corrupt the memory space of another process, in basic terms if one process malfunctions and stops running, the other one is unaffected. So let's say you had two instances of notepad opened and one crashed, the other one would be fine. In chrome when we have multiple tabs opened, each tab runs its own process, so if there is a bug in one tab or something happens, the rest are unaffected

4. A process will always have at least one thread ("main thread")

5. each process has its own address space

 

Process State

1. Program is launched, then loaded and given an address in main memory from our harddisk

2.Then its scheduled on to an available cpu

3. execution begins sequentially, one by one

4. A process is an active entity, if you launch the same program twice, it will create multiple processes

 

 

 

Thread

A thread is the smallest unit of execution within a process. Threads share the same memory space and resources within the process including (code, data, resources), allowing for more efficient communication and coordination compared to separate processes because they can access and modify shared data directly. 

 

Things to Note:

1.Since threads exists as a subset of a process, they share their address space

2.Unlike process, if one thread misbehaves, it can disrupt or bring down the entire process.

 

MultiThreading

Multithreading is the concurrent execution of multiple threads within the same process.

 

 

 

1. All three threads in Variable x can read and write to the memory location where variable x is located

 

Synchronization Construct: Mutex enforces synchronization between threads and prevents a state from being accessed/modified by multiple threads at the same time, by essentially locking it. Above lets say thread 1 is currently updating process 2 variable x with a new value, no other thread at that time will have access to variable x, except thread 1.

pros: helps maintain data integrity

cons: introduce some overhead due to locking and unlocking operations,

 

Example of multithreading in a webserver