0% found this document useful (0 votes)
9 views26 pages

Operating System(Unit -1)

This document provides an introduction to key concepts in computer programming and operating systems, including definitions of programs, processes, and programming languages. It outlines the functions of operating systems, such as process management, memory management, and file system management, as well as different types of operating systems like batch, interactive, and real-time systems. Additionally, it discusses the structure and components of operating systems, highlighting their roles in managing hardware and software resources.

Uploaded by

c3820854
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views26 pages

Operating System(Unit -1)

This document provides an introduction to key concepts in computer programming and operating systems, including definitions of programs, processes, and programming languages. It outlines the functions of operating systems, such as process management, memory management, and file system management, as well as different types of operating systems like batch, interactive, and real-time systems. Additionally, it discusses the structure and components of operating systems, highlighting their roles in managing hardware and software resources.

Uploaded by

c3820854
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

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.

Functions of Operating System


a) Process Management
 Manages creation, scheduling, and termination of processes.
 Handles synchronization and communication between
processes.
 Allocates CPU time to processes (using algorithms like FCFS,
Round Robin).
b) Memory Management
 Keeps track of each byte in a computer’s memory.
 Allocates/deallocates memory space as needed by programs.
 Manages swapping between main memory and disk (virtual
memory).
c) File System Management
 Organizes, stores, retrieves, names, shares, and protects files.
 Maintains directories and access permissions.
d) Device Management
 Controls and coordinates input/output devices (keyboard,
printer, etc.).
 Uses device drivers and I/O scheduling.
UNIT – 1
INTRODUCTION
e) Security and Protection
 Prevents unauthorized access to data and programs.
 Implements authentication, authorization, and encryption.
 User Interface
 Provides command-line interface (CLI) or graphical user
interface (GUI).
 Allows users to interact with the system.
f) Job Scheduling
 Decides the order in which jobs are processed.
 Uses scheduling algorithms to ensure efficient CPU use.

Classification of Operating Systems


1. Batch Operating System
 Users don’t interact directly with the system.
 Jobs are grouped together (batch) and processed sequentially.
 In Batch Operating System, The batches are made of the same
types of jobs and the batches are executed one by one.
 An example of batch processing is the way that credit card
companies process billing. The customer does not receive a
bill for each separate credit card purchase but one monthly
bill for all of that months purchases? The bill is created
through batch processing, where all of the data are collected
and held until the bill is processed as a batch at the end of the
billing cycle.
Example: Early IBM systems.
Advantage: Efficient for large, repetitive tasks.
Disadvantage: No user interaction during execution.
UNIT – 1
INTRODUCTION

2. Interactive Operating System


 Allows direct communication between user and system.
 Responds quickly to user commands.
 In an Interactive Operating system, the user interacts
directly with the operating system to supply commands and
data as the application program executes and the user
receives the results of processing immediately.
 Examples of Interactive operating system is ATM machine,
Macintosh and Windows the prime examples of graphical
interactive systems.
Example: Windows, Linux with terminal.
Advantage: Real-time feedback.
Disadvantage: Can be slower due to constant interaction.

3. Time-Sharing Operating System


 Allows multiple users to use the system simultaneously.
 CPU time is divided into small slices and shared.
 Multitasking, in an operating system, is allowing a user to
perform more than one computer task (such as the
operation of an application program-preemptive) at a time.
Example: UNIX.
Advantage: Efficient utilization of resources.
UNIT – 1
INTRODUCTION
Disadvantage: Complex to manage.

4. Real-Time Operating System (RTOS)


 Responds to input instantly.
 In real Time System we directly communicate with the
deterministic nature like Traffic Management etc. The
components of real Time System are explained below:
▪ Sensor: It is a hardware device, that senses the live
environment.
▪ Controlling Agent: It is a software that takes decision
from according to the sensor.
▪ Database: It keeps track of all the information.
▪ Actuator: It produce result back to the environment.
 Used in embedded systems like robots, medical systems.
 Two types:
▪ Hard Real-Time: Strict timing constraints (e.g., pacemakers).
▪ Soft Real-Time: Less strict (e.g., video streaming).
Advantage: Predictable timing.
Disadvantage: Limited multitasking.

5. Multiprocessor Operating System


 Supports systems with more than one processor (CPU).
 All CPUs share memory and devices.
 Multiprocessor system means, there are more than one
processor which work parallel to perform the required
UNIT – 1
INTRODUCTION
operations. It allows the multiple processors, and they are
connected with physical memory, computer buses, clocks, and
peripheral devices.
Example: Symmetric Multiprocessing (SMP).
Advantage: Faster execution, parallel processing.
Disadvantage: Complex architecture.

6. Multiuser Operating System


 Allows multiple users to access the computer
simultaneously.
 Resources are shared but users are isolated.
 Allows two or more users to run programs at the same time.
Example: UNIX, Mainframe OS.
Advantage: Resource sharing.
Disadvantage: More complex to maintain.

7. Multiprogramming Operating System


 Multiple programs are loaded in memory and CPU executes
them one by one.
 Enhances CPU utilization.
 Multiprogramming OS is an ability of an operating system
that executes more than one program (non-preemptive) using
a single processor machine.
Advantage: Maximizes resource usage.
Disadvantage: Requires proper job scheduling.
UNIT – 1
INTRODUCTION

8. Multithreaded Operating System


 Supports multiple threads (lightweight processes) within a
single process.
 Threads share the same memory space.
Example: Windows, Linux.
Advantage: Efficient task handling.
Disadvantage: Difficult to debug.

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

Operating System Components


An OS has several key components, each responsible for managing
a specific part of the system.
a) Process Management
 Handles creation, scheduling, termination of processes.
 Ensures proper synchronization and communication between
processes.
 A process is a program in execution. A program itself is not a
process rather it is a passive entity.
UNIT – 1
INTRODUCTION
 A process needs certain resources, including CPU time, memory,
files, and I/O devices, to accomplish its task. These resources
are either given to the process when it is created or when it
is running. When the process completes, the OS reclaims all the
resources.
 The operating system is responsible for the following
activities in connection with process management.
a) Process creation and deletion.
b) Process suspension and resumption.
c) Provision of mechanisms for:
▪ Process synchronization
 Implements algorithms like Round Robin, FCFS etc.
b) Memory Management
 Manages RAM allocation for processes.
 Handles paging, segmentation, and virtual memory.
 Keeps track of which memory is free or in use.
 Memory is a large array of words or bytes, each with its own
address. It is a repository of quickly accessible data shared by
the CPU and I/O devices.
 The operating system is responsible for the following
activities in connections with memory management:
▪ Keep track of which parts of memory are currently being
used and by whom.
▪ Decide which processes to load when memory space becomes
available.
▪ Allocate and deallocate memory space as needed.
c) File System Management
 Organizes files on storage devices using directories.
 Manages file creation, deletion, access, and permissions.
 Handles file naming and security.
 Most visible component of OS. Computers can store
information on several different types of physical media
(e.g. magnetic tap, Hard disk etc).
UNIT – 1
INTRODUCTION
 A file a logical storage unit. A file is a collection of related
information defined by its creator. Commonly, files represent
programs (both source and object forms) and data.
 The operating system is responsible for the following
activities in connections with file management:
▪ File creation and deletion.
▪ Directory creation and deletion.
▪ Support of primitives for manipulating files and
directories.
▪ Mapping files onto secondary storage.
▪ File backup on stable (non volatile) storage media.
d) I/O System Management
 Controls and manages input/output devices like keyboard,
mouse, printer.
 Uses device drivers to communicate with hardware.
 Buffers and queues I/O requests.
 The I/O system consists of:
▪ A buffer-caching system
▪ A general device-driver interface
▪ Drivers for specific hardware devices
e) Secondary Storage Management
 Manages hard disk space for files and programs.
 Handles disk scheduling algorithms (e.g., SSTF, SCAN).
 Ensures data is stored and retrieved efficiently.
 Most modern computer systems use disks as the principle on-
line storage medium, for both programs and data.
 Since main memory (primary storage) is volatile and too
small to accommodate all data and programs permanently,
the computer system must provide secondary storage to
back up main memory.
 The operating system is responsible for the following
activities in connection with disk management:
▪ Free space management
UNIT – 1
INTRODUCTION
▪ Storage allocation
▪ Disk scheduling
f) Networking
 Manages network protocols and communication between
systems.
 Ensures data transfer, remote login, file sharing, etc.
 Distributed System is a collection of autonomous computer
systems that are physically separated but are connected by a
centralized computer network that is equipped with
distributed system software.
 The processors in the system are connected through a
communication network.
 Communication takes place using a protocol.
 A distributed system provides user access to various system
resources.
 Access to a shared resource allows:
▪ Computation speed-up
▪ Increased data availability
▪ Enhanced reliability
g) Security and Protection
 Protects system resources from unauthorized access.
 Uses techniques like authentication (login), encryption,
firewalls.
 Ensures data integrity and confidentiality.
 Protection refers to a mechanism for controlling access by
programs, processes, or users to both system and user
resources.
 The protection mechanism must:
▪ Distinguish between authorized and unauthorized usage.
▪ Specify the controls to be imposed.
▪ Provide a means of enforcement.
h) Command Interpreter System
 Acts as the interface between user and OS (Shell).
UNIT – 1
INTRODUCTION
 Parses user commands and passes them to the OS.
 The command interpreter is the primary interface between
the user and the rest of the system.
 Command Interpreter System executes a user command by
calling one or more number of underlying system programs
or system calls.
▪ Process creation and management
▪ I/O handling
▪ Secondary-storage management
▪ Main-memory management
▪ File-system access
▪ Protection
▪ Networking
 The program that reads and interprets control statements:
▪ Command-line interpreter
▪ Shell (in UNIX)
 Its function is to get and execute the next command
statement.
Summary
Component Role
Process Management Manages CPU and processes
Memory Management Allocates and deallocates memory
File System Manages files and directories
I/O Management Handles input/output devices
Storage Management Manages disk storage
Security Protects system from threats
Networking Manages communication
Command Interpreter User interface for commands
UNIT – 1
INTRODUCTION
Operating System Services
The operating system provides a set of essential services that
are useful to both the users and programs. These services help in
the effective and secure execution of programs.
Services Provided to Users
1. User Interface
Most OSes offer a User Interface (UI), which may be:
a) CLI (Command-Line Interface) – e.g., Linux terminal, Windows
command prompt.
b) GUI (Graphical User Interface) – e.g., Windows, Ubuntu with
GNOME.
• This interface allows users to interact with the system
easily.
2. Program Execution
• OS provides an environment for writing, loading, and
executing programs.
• It includes loading programs into memory, running them,
and handling execution errors.
3. I/O Operations
• Programs often need to read/write data from input/output
devices.
• The OS manages these I/O operations and provides a standard
way to perform them.
4. File System Manipulation
• Programs must read/write data to files.
• OS provides functions to create, delete, open, close, read, and
write files.
• It also manages directory structures and access permissions.
5. Communication Services
• In a multi-process environment, processes often need to
communicate.
• OS facilitates Inter-Process Communication (IPC) using:
UNIT – 1
INTRODUCTION
▪ Message passing
▪ Shared memory
6. Error Detection and Handling
 OS constantly monitors the system to detect and correct
errors.
 It may include hardware errors (e.g., disk failures) or
software errors (e.g., illegal memory access).
7. Security and Protection
 Protects data from unauthorized access.
 Ensures user data and process boundaries are isolated.
 Implements authentication (login), authorization, and
encryption mechanisms.
Services Provided to System Itself
1. Resource Allocation
 Manages CPU time, memory, and I/O devices.
 Ensures efficient and fair resource distribution among
processes.
2. Accounting
 Keeps records of resource usage (CPU time, memory used, etc.).
 Useful for billing in commercial systems and performance
monitoring.
3. Protection
 Controls access to resources in multi- user/multiprocess
environments.
 Ensures that one process cannot interfere with another.
UNIT – 1
INTRODUCTION
System Program and System Call
System Program can be defined as the act of building Systems
Software using System Programming Languages. Program
Development and Execution can be done conveniently in System
Programs.
A system call is the programmatic way in which a computer
program requests a service from the kernel of the operating
system it is executed on. A computer program makes a system call
when it makes a request to the operating system's kernel. System
call provides the services of the operating system to the user
programs via Application Program Interface (API).

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.

C. Many to Many Model:


 The many-to-many model multiplexes many user-level
threads to a smaller or equal number of kernel threads.
 If a user thread is blocked we can schedule others user
thread to other kernel thread.
 The one-to-one model allows for greater concurrency.
UNIT – 1
INTRODUCTION

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.

You might also like