Components of OS
Kernel
- A kernel is that part of the operating system which
interacts directly with the hardware
and performs the most crucial tasks. - Heart of OS/Core component
- Very first part of OS to load on start-up.
- A kernel is that part of the operating system which
User space
- Where application software runs,
apps don’t have privileged access
to the underlying hardware. It interacts with kernel. - App: GUI, CLI
- Where application software runs,
User Mode & Kernal Mode
- To prevent the application software from accessing the hardware directly
- The modern OS have
two basic modes
in which they can execute a certain programUser-mode
Kernel-mode
Kernel-mode
- The OS runs in kernel mode, also known as
supervisor mode
orprivileged mode
- The Kernel mode is the privileged mode where the process
has unrestricted access
to system resources like hardware, memory, etc - It will have to first go
through the OS kernel by using syscalls
User mode
- The User mode is normal mode where the process
has limited access
- All the User application runs in User Mode and direct access to the hardware is prohibited.
- To get access to restricted resources the kernel
provides System Call(syscalls)
through which a process get the required access - Mode Detail
- Moving between the user mode and the kernel mode is referred to as
context switching
- Context switching occurs when a user process makes a request to the underlying system API
using syscalls
- The switch does not occur automatically; rather, an
interrupt is generated
- An interrupt handler then saves the state of the CPU, switches to the kernel mode where the CPU can execute the instructions, and then restores the state of the CPU and returns to user mode.
- Moving between the user mode and the kernel mode is referred to as
Functions of Kernel:
Process management
- Scheduling processes and threads on the CPUs.
- Creating & deleting both user and system process.
- Suspending and resuming processes
- Providing mechanisms for process synchronization or process communication.
Memory management
- Allocating and deallocating memory space as per need.
- Keeping track of which part of memory are currently being used and by which process.
File management
- Creating and deleting files.
- Creating and deleting directories to organize files.
- Mapping files into secondary storage.
- Backup support onto a stable storage media.
I/O management
- To manage and control I/O operations and I/O devices
- Buffering (data copy between two devices), caching and spooling.
- Spooling
- Within differing speed two jobs.
- Eg. Print spooling and mail spooling.
- Buffering
- Within one job.
- Eg. Youtube video buffering
- Caching
- Memory caching, Web caching etc.
Types of Kernels:
Monolithic kernel
All functions are in kernel itself
- Bulky in size.
- Memory required to run is high.
- Less reliable, one module crashes -> whole kernel is down.
- High performance as communication is fast. (Less user mode, kernel mode overheads)
- Eg. Linux, Unix, MS-DOS.
Micro Kernel
- Only major functions
Memory mgmt and Process mgmt are in kernel
File mgmt. and IO mgmt. are in User-space
- Smaller in size.
- More Reliable
- More stable
- Performance is slow.
- Overhead switching b/w user mode and kernel mode.
- Eg. L4 Linux, Symbian OS, MINIX etc.
- Only major functions
Hybrid Kernel
- Advantages of both worlds. (File mgmt. in User space and rest in Kernel space)
- Combined approach.
- Speed and design of mono.
- Modularity and stability of micro.
- Eg. MacOS, Windows NT/7/10
- IPC also happens but lesser overheads
Nano/Exo kernels
Inter process communication (IPC)
- Two processes executing independently, has independent memory space (Memory protection), But some may need to communicate to work.
- IPC is the way by which
multiple processes or threads communicate among each other
- IPC in OS obtains modularity, computational speedup and data sharing.
- Different ways to implement IPC are
- pipe, message passing, message queue, shared memory
- direct communication, indirect communication, FIFO.
- It is important to obtain synchronization among processes in IPC to maintain data consistency.
Semaphore and mutex
are two ways to do so.
System calls
- System calls are implemented in C.
- A system call is a mechanism using which a user program can request a service from the kernel for which it does not have the permission to perform.
- User programs typically do not have permission to perform operations like accessing I/O devices and communicating other programs.
- System Calls are the only way through which a process can go into kernel mode from user mode.
Types of System Calls:
- Process Control
- end, abort
- load, execute
- create process, terminate process
- get process attributes, set process attributes
- wait for time
- wait event, signal event
- allocate and free memory
- File Management
- create file, delete file
- open, close
- read, write, reposition
- get file attributes, set file attributes
- Device Management
- request device, release device
- read, write, reposition
- get device attributes, set device attributes
- logically attach or detach devices
- Information maintenance
- get time or date, set time or date
- get system data, set system data
- get process, file, or device attributes
- set process, file, or device attributes
- Communication Management
- create, delete communication connection
- send, receive messages
- transfer status information
- attach or detach remote devices
Examples of Windows & Unix System calls
- Process Control
- Windows: CreateProcess(), ExitProcess(), WaitForSingleObject()
- Unix: fork(), exit(), wait()
- File Management
- Windows: CreateFile(), ReadFile(), WriteFile()
- Unix: open(), read(), write()
BIOS/UEFI
- Basic Input/Output System
- BIOS chip is a ROM chip found on mother board that allows to access & setup computer system at most basic level
- BIOS
tests and initializes system hardware
which is backed byCMOS battery
- Unified Extended Firmware Interface
- UEFI is an
upgraded version on BIOS
- UEFI can do a lot more than just initialize hardware; it’s really a tiny operating system.
- For example
- Intel CPUs have the Intel Management Engine.
- This provides a variety of features, including powering Intel’s Active Management Technology, which allows for remote management of business PCs
- UEFI is an
CMOS battery
- CMOS stands for Complementary Metal Oxide Semiconductor
- The CMOS battery powers the BIOS firmware in your laptop
- The CMOS battery gets charged whenever your laptop is plugged in.
- Most batteries will last 2 to 10 years from the date they’re manufactured.
What happens when you turn on your computer?
- PC On
CPU initializes itself
and looks for a firmware program (BIOS/UEFI) stored in BIOS/UEFI ChipCPU runs the BIOS
which tests and initializes system hardware- Bios loads configuration settings.
- If something is not appropriate (like missing RAM) error is thrown and boot process is stopped.
- This is called POST (
Power on self-test
) process.
- BIOS will handoff responsibility for booting your PC to your OS’s bootloader
- Bootloader loads the Full OS
- The bootloader is a small program that has the large task of booting the rest of the operating system
- Like: Boots Kernel then, User Space
- Windows uses a bootloader named
Windows Boot Manager
(Bootmgr.exe) - Most Linux systems use
GRUB
, and - Macs use something called
boot.efi