Kernel Basic
Last updated
Was this helpful?
Last updated
Was this helpful?
Kernel is the innermost or core internals, the software which provides basic services for all parts of the system, manages hardware, and distributes system resources.
Typical component of Kernel
Interrupt Handlers to serve interrupt requests
Scheduler, to share processor time along multiple processes
Memory management system for managing process addresses spaces
System Services like networking and interprocess communication
Talking about modern systems i.e., OS has kernel in elevated state i.e., full access to hardware and memory whereas normal user application has lesser privileges.
space, The system state and memory space, is known as kernel space
and under this all kernel code execution takes places.
Whereas user-space
is used for executing the user application, this only uses allotted resources and memory by kernel, this helps in protecting application to misbehave for stability. This application can only access certain system-level functions.
The communication of Application
running on the System
with kernel
is via system calls
Application
→ calling func in a library
→system call
This ask kernel to execute task on behalf of applicationfrom misbehavinghip between application, kernel, and hardware
Some library calls provide many features than system call like printf()
provides formatting and buffering of the data. Only one step in its work is invoking write()
for writing data in the console.
Some library calls have one-to-one relationship with kernel, like open()
it does little except call the open() system call.
strcpy()
should make no direct use of the kernel at all.
Major issue of strcpy()
is it can lead to buffer overflow.
More about security issues of strcpy
When an application is said to be executing a system call
in kernel space
, and the kernel is running in process context
What is interrupt ?
It’s a way for hardware to communicate with system, so whenever hardware wants to communicate with system, it issues an interrupt. Which literally interrupts the processor and so it turns interrupt to kernel.
These interrupts are identifies using a number, this number is used by kernel to execute a specific interrupt handler to process and respond to interrupt
For providing synchronization, the interrupts can be disabled by kernel, it can be either all interrupts or just one specific interrupt number
Interrupt run in interrupt context
and not associated to any process. It is only for interrupt to respond faster.
**Unix kernel
**is typically a monolithic static binary , which means it is a single large executable image that runs on single address space. It require a system with paged memory management unit (MMU)
. This allow hardware to enforce memory protection and to provide a unique virtual address space to each process.
In context of Linux Kernel
, it do also require MMU
, but incase of special version it can run without one . This allow linux to run on very small MMU-less
embedded system.
Monolithic kernels
exists on disk as single static binaries and implemented entirely as a single processes running in a single address space. Communication within is trivial as everything runs in kernel mode in same address space. The kernel can invoke functions directly as a user space application
MicroKernel
functionality are broken down into separate processes usually know as servers
This helps in running only servers required to run in privileged execution mode and rest serves in user-space, are separated in different address space. Due to this directly function can’t be invoked.
Instead this it uses IPC(Inter Process Communication)
for communication which is built in the system. Server use this to communicate and invoke services. Due to separation of various servers accordingly , prevents failure in one server from bringing down another.
Some notable difference b/w Linux kernel and Classic Unix systems
Dynamically load kernel modules
Supports Symmetrical multiprocessor (SMP)
Linux kernel is preemptive, even task is executed in kernel can be preempt
All processes are same
Ignored STREAMS or standard, impossible to implement cleanly
First value major release
Second value minor release
Third value revision
Fourth value optional for stable version
An even number is stable, where as an odd number is development