Operating System(Unit -1)
Operating System(Unit -1)
INTRODUCTION
Some Basic Definitions -
Program
A program is a set of instructions written in a programming
language that tells the computer what tasks to perform and
how to perform them.
It is usually written in high-level languages like C, C++, Java,
Python, etc.
Before a program can be run, it is usually compiled
(translated) into machine code the computer understands.
Example: System.out.println("Hello, world!");
Process
A process is a program in execution. When you run a program, it
becomes a process.
It includes:
The program code (also called text section)
Current activity (Program Counter, CPU registers)
Memory (stack, heap, etc.)
Resources (files, I/O devices)
The operating system is responsible for managing processes.
For example, when you open a browser like Chrome, each tab may
run as a separate process.
Programming Language
A programming language is a formal language with a set of
rules used to write computer programs.
It allows developers to communicate instructions to the
computer.
Programming languages are of two types:
a) Low-level languages (Machine and Assembly language)
b) High-level languages (C, Java, Python, etc.)
A compiler or interpreter is needed to convert high-level
code to machine code.
UNIT – 1
INTRODUCTION
Software
Software is a general term used for programs, procedures,
and documentation related to the operation of a computer
system.
Software is of two main types:
a) System Software
b) Application Software
Software is intangible (cannot be touched), unlike hardware
(which is physical).
Difference between System Software and Application
Software
Feature System Software Application Software
Controls and manages
Designed to help users
Purpose hardware and system
perform specific tasks
resources
Operating System, MS Word, Excel, Web
Examples
Compiler, Device Drivers Browsers, Games
Works in background,
User Directly used by the end-
not directly used by
Interaction users
users
Depends on system
Dependency Works independently
software to run
Usually comes with the Needs to be installed as
Installation
operating system per user requirements
Manages system-level Performs user-level
Type of
tasks like memory and tasks like editing text
Operation
CPU or browsing
Introduction to Operating System
An Operating System (OS) is system software that acts as an
intermediary between users and computer hardware. It manages
hardware resources and provides services for application
UNIT – 1
INTRODUCTION
software. It ensures that hardware is used efficiently and users
can run programs conveniently.
An operating system is a program that manages the computer
hardware. It also provides a basis for application programs and
acts as an intermediary between the computer user and the
computer hardware.
9. Distributed System
A distributed operating system is system software over a
collection of independent software, networked,
communicating, and physically separate computational
nodes.
They handle jobs which are serviced by multiple CPUs.
Each individual node holds a specific software subset of the
global aggregate operating system.
UNIT – 1
INTRODUCTION
10. Embedded System
An embedded operating system is a specialized operating
system (OS) designed to perform a specific task for a device
that is not a computer.
Operating System Structure
The structure of an operating system defines how different
components interact and how the OS is designed to manage the
system's hardware and software resources. It determines
efficiency, maintainability, and extensibility.
Layered Structure of Operating System
In the Layered Approach, the operating system is divided into
layers (or levels), each built on top of the lower one. The bottom
layer (layer 0) interacts directly with the hardware, and the top
layer (highest) is the user interface.
The operating system is divided into a number of layers (levels),
each built on top of lower layers. The bottom layer (layer 0), is
the hardware; the highest (layer N) is the user interface.
The operations (routines) can be invoked by higher-level layers.
The layer itself can invoke operations on lower-level layers.
Advantages of Layered Structure
• Modularity: Each layer is independent, making debugging and
updating easier.
• Abstraction: Each layer provides services to the higher one
while hiding implementation details.
• Ease of Maintenance: Errors can be localized and fixed within
a specific layer.
Disadvantages
• May cause overhead due to layer-by-layer communication.
• Designing strict boundaries between layers can be complex.
UNIT – 1
INTRODUCTION
Example Layers:
Layer
Layer Name Description
No.
Physical devices (CPU,
0 Hardware
memory, I/O)
CPU Scheduling, Memory
1 Controls CPU and memory
Management
Manages input/output
2 I/O Management
operations
Manages files and
3 File System
directories
Interface for user-level
4 System Call Interface
programs
5 User Interface CLI/GUI for end users
Windows Unix
Process Control CreateProcess() fork()
ExitProcess() exit()
File CreateFile() open()
Manipulation ReadFile() read()
WriteFile() write()
CloseHandle() close()
Multithreading
Process means a program that is being executed. Processes are
further divided into independent units also known as threads. It
is a process that is small and light-weighted residing inside a
process.
It comprises a thread ID, a program counter, a register set,
and a stack.
UNIT – 1
INTRODUCTION
It shares with other threads belonging to the same process
its code section, data section, and files.
Multithreading Models
User Thread –
▪ Non atomic (with preemption)
▪ Un privileged mode
▪ User submitted program (HLL)
Kernel Thread –
▪ Atomic (without preemption)
▪ Privileged mode
▪ OS services /system call
A thread library provides the programmer with an API for
creating and managing threads
A. Many-to-One Model:
The many-to-one model maps many user-level threads to
one kernel thread.
UNIT – 1
INTRODUCTION
Thread management is done by the thread library in user
space.
Only one thread can access the kernel at a time, multiple
threads are unable to run in parallel on multiprocessors.
In this model when a user thread makes a blocking system
call entire process blocks.
B. One-to-One Model:
The one-to-one model maps each user thread to a
kernel thread.
It provides more concurrency than the many-to-one.
It also allows multiple threads to run in parallel on
multiprocessors.
If any user thread makes a blocking system call, the
other user threads won't be blocked.
Benefits of Threads:
A. Responsiveness: Multithreading an interactive application may
allow a program to continue running even if part of it is
blocked or is performing a lengthy operation.
B. Resource sharing: Sharing code and data allows an application
to have several different threads of activity within the same
address space.
C. Economy: Allocating memory and resources for process
creation is costly. It is more economical to create and context-
switch threads.
D. Utilization of multiprocessor architectures: The benefits of
multithreading can be greatly increased in a multiprocessor
architecture, where threads may be running in parallel on
different processors. A single threaded process can only run on
one CPU, no matter how many are available. Multithreading on a
multi-CPU machine increases concurrency.
Kernel
Kernel is central component of an operating system that manages
operations of computer and hardware.
It basically manages operations of memory and CPU time.
Kernel acts as a bridge between applications and data processing
performed at hardware level using inter-process
communication and system calls.
The word kernel is comes from an onion. The innermost part of
onion is called Kernel similar correlation is applied here. The
innermost crucial part of is called the Operating System as
UNIT – 1
INTRODUCTION
kernel, while the shell is part which covers the kernel so as to
hide its complexities.
A kernel is the core part of an operating system. When operating
system is loaded into memory and the kernel Ioads first and
remains in memory until the operating system is shut down
again.
The kernel is a software code that resides in the central code of
the operating system. It has complete control over the system. It
is responsible for low – level tasks such as task management
disk management and memory management.
The kernel is responsible for -
a) Process Management for application section
b) Memory Management, allocation and I/O
c) Device management through the use of device drivers.
d) System call control, which is essential for the execution of
kernel service.
Basic function of Kernel-
a) Resource Allocation
b) Memory Management
c) I/0 Device Management
d) Inter process communication
e) Process Management
f) Scheduling
g) System calls and Interrupt Handling
Types of Kernels-
Kernels can be broadly classified into two types:-
a) Monolithic kernels.
b) Micro kernels.
Monolithic vs. Microkernel Systems
The kernel is the core part of an operating system that interacts
directly with the hardware. There are two major types of kernel
architectures:
UNIT – 1
INTRODUCTION
Monolithic Kernel
A Monolithic Kernel is a single large process running
entirely in a single address space (kernel space). All
operating system components are tightly integrated.
The Monolithic operating System in which the kernel acts as
a manager by managing all things like file management,
memory management, device management, and operational
processes of the Operating System.
The kernel is the heart of a computer operating system (OS).
Kernel delivers basic services to all other elements of the
System. It serves as the primary interface between the
Operating System and the hardware.
Characteristics:
Contains everything in one large codebase:
a) File system
b) Device drivers
c) Memory management
d) Scheduler
e) Inter-process communication
Components can directly communicate with each other using
function calls.
Advantages:
Fast execution due to direct communication.
Simple design (historically easier to implement).
Layering is unnecessary and the kernel alone is responsible
for managing all operations, it is easy to design and
execute.
Disadvantages:
Difficult to debug and maintain – a bug in one component can
crash the entire system.
Less modular and less secure.
UNIT – 1
INTRODUCTION
The monolithic kernel's services are interconnected in one
address space and have an impact on one another, so if any
of them malfunctions, the entire system does as well.
It is not adaptable. Therefore, launching a new service is
difficult
Examples:
UNIX
Linux (early versions)
MS-DOS
Microkernel
A Microkernel only includes the most essential functions in
the kernel space, such as:
a) Inter-process communication (IPC)
b) Low-level memory management
c) CPU scheduling
All other services (like file system, device drivers) run in
user space as separate processes.
Kernel using microkernel approach (smaller kernels)
Remove all non-essential components from the kernel &
implementing them as system & user level programs.
Characteristics:
• Uses message passing for communication between kernel and
services.
UNIT – 1
INTRODUCTION
• Promotes separation of components for better stability and
security.
Advantages:
• Highly secure and stable – failure of one component doesn’t
crash the OS.
• Easier to extend or replace components (e.g., drivers, file
system).
• Better suited for distributed and embedded systems.
• Each Micro-Kernel is made independently and is isolated
from other Micro-Kernels. So this makes the system more
secure and reliable.
• If any Micro-Kernel fails, then the remaining operating
System remains untouched and works fine.
Disadvantages:
• Slower performance due to frequent context switching and
message passing.
• More complex design and development.
• Increased inter-module communication reduces system
performance/ system overhead.
• System is complex to be constructed.
Examples:
MINIX
QNX
L4 family of kernels
Early Mac OS X (hybrid microkernel)
UNIT – 1
INTRODUCTION
Comparison Table
Feature Monolithic Kernel Microkernel
Minimal kernel with user
Architecture Single large process
services
Slower (due to message
Performance Fast (due to direct calls)
passing)
Modularity Low High
Security Low High
Low (a bug can crash
Stability High (fault isolation)
whole system)
Maintenance Difficult Easier
Examples UNIX, Linux (early) QNX, MINIX, L4
Reentrant Kernels
A Reentrant Kernel is a special type of kernel designed to support
multiple processes accessing kernel code simultaneously
without interfering with each other. A Reentrant Kernel is the one
which allows multiple processes to be executing in the kernel
mode at any given point of time and that too without causing
any consistency problems among the kernel data structures.
Key Characteristics of Reentrant Kernels:
• Thread-Safe Code:
a) Kernel code does not modify shared data.
b) Data is either kept in local variables (stack) or protected
using locks/semaphores.
• Interruptible:
a) The kernel can be interrupted while executing.
b) It can safely resume execution later or be re-entered by
another process.
• Used in Multitasking Systems:
a) Required in systems where multiple processes/threads can
request services from the kernel at the same time.
UNIT – 1
INTRODUCTION
• No Global Variables:
a) Avoids using global data that might lead to conflicts.
Benefits of Reentrant Kernels:
• Improved performance in multi-threaded/multi-core
systems.
• Enables concurrent access to kernel services.
• Prevents data corruption and race conditions.