Operating System (OS)
GTU # 3140702
Unit-1
Introduction to Operating
System
Computer system overview Basic
elements of computer Processor
I/O
Memory
System Bus
Modules
Processor
Referred to as the
Central Processing
Unit (CPU)
Arithmetic & Logic Unit Control Unit
functions
Performs the
Controls the
data
operation of
processing
the computer
Memory
Memory is device
that is used to store
data/information
Primary Memory Secondary Memory
HDD, CD &
• Volatile
DVD
• RAM & ROM
• Non-Volatile •
I/O Module (Input/Output Module)
�Input/output module is a device that acts as the connective bridge between a
computer system at one
end and an I/O or peripheral device at the other, such as a printer, webcam or
scanner.
�An I/O module is a mediator
between the processor/memory
and an I/O devices.
�It controls the data exchange
between the external devices
and main memory or external
devices and CPU registers.
System Bus
�Provides communication among processors, main
memory, and I/O devices.
�The system bus is a pathway composed of cables and
connectors used to carry data between a computer
microprocessor and the main memory.
�Types of buses
� Address bus - carries memory addresses from the processor to other
components such as primary storage and input/output devices.
� Data bus - carries the data between the
processor and other components. � Control bus -
carries control signals from the processor to
other components.
Computer system
architecture
Input unit
�It provides data and instructions
to the computer system.
�Commonly used input devices are
keyboard, mouse, magnetic tape etc.
�Input unit performs following tasks:
� Accept the data and instructions from
the outside environment.
� Convert it into machine language.
� Supply the converted data to
computer system.
Output unit
�It connects the internal system of
a computer to the external
environment.
�It provides the results of any
computation, or instructions to the
outside world.
�Some output devices are printers,
monitor etc.
Storage unit
�This unit holds the data and
instructions.
�It also stores the intermediate
results before these are sent to the
output devices.
�It also stores the data for later use.
�The storage unit of a computer
system can be divided into two
categories: � Primary Storage
� Secondary Storage
Primary storage (memory) vs Secondary storage
(memory)
Primary storage Secondary storage
Examples: RAM, ROM, Cache Examples: Hard Disk, Floppy Disk,
memory, PROM, EPROM, Registers, Magnetic Tapes, etc.
etc.
It is temporary and volatile. It is permanent and Non-volatile.
Primary memory is directly Secondary memory is not directly
accessible by Processor/CPU. accessible by the CPU.
Primary memory devices are expensive. Secondary memory devices are cheaper.
The memory devices used for primary The secondary memory devices are
memory are semiconductor memories. magnetic and optical memories.
Primary memory is also known as Secondary memory is also known as
Main memory or Internal External memory or Auxiliary memory.
memory.
CPU (Central Processing Unit)
�The Arithmetic Logical Unit and
Control Unit are together known
as CPU.
�CPU is the brain of computer
system. �It performs following
tasks:
� performs all operations.
� takes all decisions.
� controls all the units of computer.
ALU (Arithmetic Logical Unit)
�All the calculations are performed
in ALU of the computer system.
�The ALU can perform basic
operations such as addition,
subtraction, division, multiplication
etc.
�Whenever calculations are
required, the control unit
transfers the data from storage
unit to ALU.
�When the operations are done, the
result is transferred back to the
storage unit.
CU (Control Unit)
�It controls all other units of the
computer.
�It controls the flow of data and
instructions to and from the storage
unit to ALU.
�Thus it is also known as central
nervous system of the computer.
Definition of Operating System (OS)
�An Operating System (OS) is a collection of
software that � manages hardware resources
� provides various service to the users
� Interface between application and hardware
�Examples of OS
� Windows, android, linux ,Unix, Mac OS
Function of Operating System (OS)
�Function of OS
� Efficient use of a computer
proper scheduling of resources
� User convenience
Good service , Ease of use , New programming model , Evolution , User friendly
� Ability to evolve
effective development , testing
� provides a set of basic commands
instructions for read, write, modify, save or close.
� hides the complexity of hardware and present a beautiful interface to the users.
Where OS lies? (Interaction of OS & Hardware)
�OS lies between hardware and user program.
�Simplifies the programmer job like editing ,coding
creation 2. User Mode
�It acts as an � has limited access to
intermediary betweenlimited hardware
the user and the � can execute only Hardware User
subset (few) of the Program
hardware. E-mail
machine instructions reader
�Modes of operation � has less privileged
of computer (rights)
1. Kernel Mode Web
� has complete access browser Operating System
to all the hardware
� can execute any
instruction that a machine Music
player
is capable of executing Software
� has high privileged
(rights) User
Mode Mode
Kernel
Objectives / Goals of Operating System (OS)
�Make the computer system convenient to use in an efficient manner.
�Hide the details of the hardware resources from the users.
�Provide users a convenient interface to use the computer system.
�Act as an intermediary between the hardware and its users, making it easier for the
users to access and use other resources.
�Manage the resources of a computer system.
�Keep track of who is using which resource, granting resource requests, and
mediating conflicting requests from different programs and users.
�Provide efficient and fair sharing of resources among users and
programs. �OS controls these I/O devices and provides to program
as per requirement.
�It manages the memory to keeps the track of free and used memory and allocation
and deallocation of the memory
Services Of Operating System
1. Program development
� It provides editors and debuggers to assist (help) the programmer in creating programs.
1. Program execution
▪ Following tasks need to be perform to execute a program:
• Instructions and data must be loaded into main memory.
• I/O devices and files must be initialized.
1. Access to I/O devices (Resource allocation)
� A running program may require I/O, which may involve file or an I/O device.
� For efficiency and protection, users cannot control I/O devices directly.
4. Memory management
� OS manages memory hierarchy and keeps the track of which part of memory area in use and
free memory. � It allocates memory to program when they need it.
� It de-allocate the memory when the program finish execution.
Services Of Operating System
5. Controlled access to file
� OS provides a directory hierarchy for easy access and management of file.
6. Communication
� Operating system performs the communication among various types of processes in the form of
shared memory.
7. Error detection and response
� major activities of an operating system with respect to error handling −
▪ The OS constantly checks for possible errors.
▪ The OS takes an appropriate action to ensure correct and consistent computing.
8. Accounting
� Keeping a track of which users are using how much and what kinds of computer resources can
be used for accounting or simply for accumulating usage statistics.
OS as Resource Manager
�It is the job of OS to allocate these resources to the various
applications so that: � The resources are allocated fairly (equally)
� Access to the resources is synchronized so that operations are correct and consistent
P4
Wants to print 50
lines After printing
10 lines of P1
Wants to print 20
lines After printing
P1 20 lines of P1Wants
to print 15 lines
P2 P3
lines
Wants to print 15
OS as Resource Manager
�It is the job of OS to proper allocate these resources to the various
applications so that: � Deadlock are detected, resolved and avoided.
OS as Resource Manager
TYPE OF RESOURCE SHARING
1. In time sharing/multiplexing (i.e CPU) - Time slot is allocated to each program first one
gets to use the resource then another and so on
2. In space sharing/multiplexing. (i.e Memory)- main memory is divided among several
running program
Why and How switch occur?
Hardware
Web
browser
E-mail User
reader Program
Software
performs trap instruction
▪ To execute this
▪ User is writing program program
in C. ▪ Once finish 1. Load program into RAM
Operating System writing will execute it. 2. Program is executed by
processor
User
Mode
Kernel
Music
Mode
player
user-mode program
INTERRUPTS
�Event external to the currently executing process that causes a change in
normal flow of instruction execution
�generated by hardware device like CPU
TYPE OF INTERRUPT
TYPE OF INTERRUPT
Hardware interrupts:The interrupt signal generated from
external devices Example: pressing of key in keyboard
● Maskable Interrupt − interrupts that can be delayed when a highest priority
interrupt ● Non Maskable Interrupt − cannot be delayed and immediately be
serviced by the processor.
Software interrupts:The interrupt signal generated from internal devices and software
programs
● Normal Interrupts − The interrupts that are caused by the software
instructions ● Exception − an unplanned interruption while executing a
program.
spurious interrupt : is a hardware interrupt for which no source can be found. The
term "phantom interrupt" .Such interrupts difficult to identify when a system
misbehaves.
What is System calls?
�A system call is a way for programs to interact with the operating system.
�A system call is a mechanism that provides the interface between a process and the
operating system.
�A computer program makes a system call when it makes a request to the operating
system's kernel.
�It is a programmatic method in which a computer program requests a service from
the kernel of the OS.
�System call provides the services of the operating system to the user programs via
Application Program Interface(API).
�System calls are the only entry points for the kernel system.
Example of system � count = read(fd, buffer, nbytes)
▪ fd is a file descriptor.
calls (Read system
call)
Library
�Example: In Unix Read system procedure
call Return to caller Trap to the kernel
is
• When a file is • Then file can be
opened, 6
read/written. ▪ Call to library
permissions are
checked. nbytes is number proc
User spac e Increment SP
• If access is of bytes to read ▪
allowed, a number buffer is where 5 4
(fd) is returned. read deposits Put code for read in
register
Call read read User
10
11
(stores) the data
Push fd
3
Push &buffer
Push parameter
2
onto stack
1 9
Push nbytes Dispatch Sys call handler
program
Kernel calling read
7 8
space
Steps involved in making a system call (Read system call)
�Steps involved in making a system call
� In steps 1-3, the calling program pushes the parameters onto the stack. The first and third
parameters are called by value, but the second one is called by its address as denoted by the &
symbol.
� In step 4, the actual call to the library procedure is made. This instruction is the normal procedure
call instruction used to call all procedures.
� In step 5, the library procedure places the system call number in a place where the operating
system expects it, such as a register.
� In step 6, the library procedure executes a TRAP instruction to switch from user mode to kernel
mode and start execution at a fixed address within the kernel.
� In step 7, the kernel examines the system call number and then dispatches it to the correct
system call handler. This correct number is given in the table of system call handlers by pointers
referenced at the system call number.
� In step 8, the system call handler runs.
� In step 9, the operation is completed, and the user is given back control once the TRAP
instruction is set. � In step 10, this procedure returns to the user program, like how all normal
library procedures do. � In step 11, the operating system has to clear the stack, so it
increments it enough so that it is empty.
Types of system calls
�Process Control: This system calls perform the task of process creation, process
termination, etc.
� Functions:
▪ End and abort
▪ Load and execute
▪ Create process and terminate process
▪ Wait and signed event
▪ Allocate and free memory
▪ Debugging process to correcting the bug
�File Management: File management system calls handle file manipulation jobs like
creating a file, reading, and writing, etc.
� Functions:
▪ Create a file
▪ Delete file
▪ Open and close file
▪ Read, write and reposition
▪ Get and set file attributes
Types of system calls
�Device Management: Device management does the job of device manipulation like
reading from device buffers, writing into device buffers, etc.
� Functions
▪ Request and release device
▪ Logically attach/ detach devices
▪ Get and Set device attributes
�Information Maintenance: It handles information and its transfer between the OS
and user program.
� Functions:
▪ Get or set time and date
▪ Get system data
▪ Get process and device attributes
▪ Transferring information from user to operating system
Types of system calls
�Communication: These types of system calls are specially used for interprocess
communications (IPC).
� Functions:
▪ Create, delete communications connections
▪ Send, receive message
▪ Help OS to transfer status information
▪ Attach or detach remote devices
▪ Message passing between two process
▪ Sharing memory that create by one and shared by other
Types o peratng ystems
� SINGLE USER
� BATCH SYSTEM
� MULTIPROGRAMMING
� MULTITASKING
� TIME SHARING
� PARALLEL OS
� DISTRIBUTED SYSTEM
� REAL TIME OS
� SERVER OS
� MULTIPROCESSOR
� EMBEDDED OS
� SENSOR NODE OS
� SMART CARD OS
1. Single User operating systems
� The operating systems installed on our personal computer and laptops are
personal OS. � provide good support to single user.
� This OS is widely used for word processing, spreadsheet and
internet access. � Examples: Linux, Windows vista and Macintosh.
Advantages
● This operating system occupies less space in memory.
Disadvantages
● It can perform only a single task at a time.
2. Batch System operating systems
� operating system does not interact with the computer directly.
� Firstly, user prepares his job using punch cards.
� Then, he submits the job to the computer operator.
� Operator collects the jobs from different users and sort the jobs into batches with
similar needs. � Then, operator submits the batches to the processor one by one.
� All the jobs of one batch are executed together.
Advantages
● increase the performance as one job start as soon as the previous job
finished ● Move much work to the operator
to the computer
Disadvantages
● Priority can not be set for the jobs.
● There is a lack of interaction between a
user and his job.
● program debugging is difficult
3. Multiprogramming operating systems
� CPU remain idle in batch system to keep it busy one program must be loaded in it
� Monitor the state of all active programs and system resources using memory management
programs to ensures that the CPU is never idle, unless there are no jobs to process.
� store the multiple programs and provide the resource management
� two or more program share the processor is referred as
multiprogramming operating system � This set of jobs is a subset of the
jobs kept in the job pool.
� The operating system picks and begins to execute one of the jobs in
the memory.
Advantages
● High and efficient CPU utilization.
● helps to optimize the total job throughput of the computer.
● The resources are utilized smartly.
Disadvantages
● CPU scheduling is required.
● To accommodate many jobs in memory, memory management is required.
4. Multitasking operating systems
� process of performing multiple task at the same time
� computer can work with more than one program at the same time
� It is logical extension of multiprogramming supports multiple program to run concurrently
Advantages
● more suited to supporting multiple users simultaneously, and multiple apps can run smoothly without
interfering with system performance.
● Good reliability
● Background processing
● optimize resources
Disadvantages
●The multiple processors are busier at the same time to
complete any
task in a multitasking environment, so the CPU generates
more heat.
.
Difference between
multiprogramming and multitasking
MULTIPROGRAMMING MULTITASKING
The concurrent residency of more than The execution of more than one task
one program in the main memory is simultaneously is called as
called as multiprogramming. multitasking.
It uses batch OS. The CPU is It is time sharing as the task
utilized completely while assigned switches regularly.
execution.
Improvement in CPU utilization. Minimize the response time
Occurs when the currently running Carried out each time after the time slice
process stops. of process is finished.
5. Time Sharing operating systems
� It allows the user to perform more than one task at a time, each task getting the same amount of
time to execute
� It is the division of CPU time for each process when more than one task are given by the user. �
Multiple jobs are implemented by the CPU by switching between them, but the switches occur so
frequently. So, the user can receive an immediate response.
Advantages
● It provides the advantage of quick response.
● This type of operating system avoids duplication of software.
● It reduces CPU idle time.
Disadvantages
● Time sharing has problem of reliability.
● Question of security and integrity of user programs and
data can be raised.
● Problem of data communication occurs.
Difference between Time Sharing and multiprogramming
OS
Time Sharing Multiprogramming
Enables the execution of multiple task Multiple programs reside in the
and process at the same to execute main memory utilization
CPU performance simultaneously to improve CPU
utilization
base on concep of time sharing base on concept of context switching
allow multiple processes to run reduce the CPU idle time
simultaneously
takes less time to execute the more time to execute the process
task allocation
minimize response time maximize processor use
[Link] operating systems
� Collection of processing elements that cooperate to solve large
problem fast � it is group of interconnected computer like cluster
� divide task over multiple processor in order to run faster
Advantages
● Saves time allowing execution of applications in a
shorter time ● Solve larger problem
● Quick data computation
Disadvantages
● Extra cost incurred due to data transfers ,communication
Power consumption is huge by multicore architecture
.
7. Distributed operating systems
� Collection of autonomous hosts that are connected through a computer network
through a network � appears as single coherent system to users
� has a middle ware that coordinate the services
� consists of any number of possible configuration such as mainframe ,personal or minicomputers
� Processors communicate with each other through various communication lines (like high-speed
buses or telephone lines). These are known as loosely coupled systems or distributed systems.
Processors in this system may vary in size and function. They are referred as sites, nodes,
computers, and so on
Advantages
● Resource sharing ,higher reliability ,higher throughput
Disadvantages
● underlying software is extremely complex and is not understood
very well compared to other systems
● Gathering, processing, presenting, and monitoring hardware use
metrics for big clusters can be a real issue.
7.1 Client Server Computing
� In client server computing, the clients requests a resource and the server provides that resource.
� A server may serve multiple clients at the same time while a client is in contact with only one
server. � works with a system of request and response. The client sends a request to the server
and the server responds with the desired information.
� should follow a common communication protocol so they can easily interact with each other.
Advantages
All the data is concentrated in the server. So provide authorisation and
●
authentication. ● The server need not be located
physically close to the clients.
● It is easy to replace, upgrade or relocate the nodes
Disadvantages
● server may get overloaded.
● If the server fails leads of failure of the client server
network.
.
7.2 Peer to Peer System
� IThe peer to peer computing architecture contains nodes that are equal participants in data
sharing. All the tasks are equally divided between all the nodes. The nodes interact with each
other as required as share resources.
� he nodes in peer to peer networks both use resources and provide resources. So, if the nodes
increase, then the resource sharing capacity of the peer to peer network increases.
Advantages
� the network is quite easy to set up and
[Link].
� It is easy to scale the peer to peer network and add
more nodes.
� This only increases the data sharing capacity of the
system.
Disadvantages
� It is difficult to backup the data as it is stored in
different
computer systems and there is no central server.
� It is difficult to provide overall security in the peer to peer network
as each system is independent and contains its own data.
8. Real Time operating systems
� Real time OS has well defined fixed time constraints.
� Processing must be done within defined time constraints otherwise system fails.
� Two types of real time OS:
▪ Hard real time – missing an occasional deadline can cause any permanent damage. Many of
these are found in industrial process control, car engine control system.
▪ Soft real time – missing an occasional deadline does not cause any permanent damage.
Used in digital audio, multimedia system.
Advantages.
● Focus on running applications and less importance to applications that are in
the queue. ● the maximum utilization of devices and systems.
● These types of systems are error-free.
● Memory allocation is best managed in these types of systems.
Disadvantages
● have complicated layout principles
9. Multiprocessor operating systems
� A computer system consist two or more CPUs is called multiprocessor.
� A motherboard is capable of handling multiple processors in a multiprocessing operating
system. � Processors are also capable of being used in a multiprocessing system.
� They need special OS or some variations on server OS with special features for
communication, connectivity and consistency.
� Examples: Windows and Linux
Advantages
● This increases reliability as if one processor fails; the task can be
given to another processor for completion. ● Increased throughout
Disadvantages
● Operating system of multiprocessing is more complex
and sophisticated as it takes care of multiple CPUs at the same
time.
.
10. Handhelds computer operating systems
� A handheld computer or PDA (Personal Digital Assistant) is small computer that fit in a Pocket
and perform small number of functions such as electronic address book, memo pad.
� The OS runs on these devices are handheld OS.
� These OS also provides ability to handle telephony, digital photography and other
functions. � Examples: Symbian OS, Palm OS.
11. Embedded operating systems
� This OS is installed in ATMs, printers, calculators and washing machine.
� It runs on the computer that control devices.
� It neither allow to download new software nor accept user installed software. So there is
no need for protection.
� Examples: QNX, VxWorks.
12. Sensor node operating systems
� Network of tiny sensor nodes are being developed for numerous purpose.
� Each nodes are tiny computers with a CPU, RAM, ROM and one or more
environmental sensors. � The OS installed in these nodes are sensor node OS.
� They communicate with each other and with base station using wireless communication. �
These sensor network are used to protect area of building, detect fires in forest, measure
temperature. � Examples: TinyOS.
13. Smart card operating systems
� Smallest OS run on smart cards which are credit card sized devices containing CPU
chip. � These OS are installed on electronic payments cards such as debit card, credit card
etc. � They have limited processing power.
� Some smart cards are Java oriented. ROM on smart card holds an interpreter for the
JVM – small program.
Operating Systems (OS) structure
1. Simple Structure
� Such operating systems do not have well defined structure and are small, simple and
limited systems. � The interfaces and levels of functionality are not well separated.
� MS-DOS is an example of such operating system.
� These types of operating system cause the entire system to crash if one of the user programs fails.
2. Layered Structure
� The layered structure approach breaks up the operating system into different layers and retains
much more control on the system.
� The bottom layer (layer 0) is the hardware, and the topmost layer (layer N) is the
user interface. � These layers are so designed that each layer uses the functions of
the lower-level layers only. � It simplifies the debugging process
Advantages of Layered structure:
● Layering makes it easier to enhance the operating system as
implementation
of a layer can be changed easily without affecting the other layers.
● It is very easy to perform debugging and system verification.
Disadvantages of Layered structure:
● Inthis structure the application performance is
degraded as compared to simple structure.
● careful planning for designing the layers as higher layers
use the functionalities of only the lower layers
Layer Function Description
5 Operator Operator was located.
4 User programs User programs were found.
3 Input / Output Takes care of managing the I/O devices.
management Buffering the information.
2 Operator-process Handles communication between each process and the
communication operator console (i.e. user).
1 Memory and drum Did the memory management.
management Allocated space for process in main memory and on a 512K word
drum used for holding parts of processes for which there was no
room in memory.
0 Processor allocation Provided the basic multiprogramming of the CPU.
and Dealt with allocation of the processor, switching between
multi-programming processes when interrupts occurred or timers expired.
3. KERNEL
� Reside in the central core of the OS and has the complete control over the system
� it is the first part of the system to load into the memory it is usually loaded into the
protected area of the memory
Objectives of Kernel :
● To establish communication between user level application and hardware.
● To decide state of incoming processes.
● To control disk management.
● To control memory management.
● To control task management.
● handling the interrupt
Monolithic systems
� It is one of types of kernel where all operating system
services operate in kernel space. It has dependencies between systems components. It has
huge lines of code which is complex.
� most of operation performed via system call
� Example :Unix, Linux, Open VMS, XTS-400 etc.
Advantage :
● simple to design
● it has good performance
Disadvantage :
.
● runtime loading and unloading is not possible
● fault tolerance is low
It has dependencies between system component and lines of code in millions
Microkernel
� provide minimal services like IPC and process management
� facility to various services which are running in user space
� it run in kernel mode and rest run in normal user processes
� The microkernel design provides high reliability by splitting OS up into small well defined
modules, only one module run in kernel and rest of all run in user mode.
� As each device driver runs as a user process, a bug in audio driver will cause the sound to be stop,
but not crash the computer.
� Examples: Integrity, K42, QNX, Symbian and MINIX 3.
Advantage :
It is more stable.
Disadvantage :
There are lots of system calls and context switches.
Hybrid
� It is the combination of both monolithic kernel and mircrokernel. It has speed and design of
monolithic kernel and modularity and stability of microkernel.
� Example : Windows NT, Netware, BeOS etc.
Advantage :It combines both monolithic kernel and microkernel.
Disadvantage :It is still similar to monolithic kernel.
Exokernels
� It is the type of kernel which follows end-to-end principle. It has fewest hardware abstractions as
possible. It allocates physical resources to applications.
� Example :Nemesis, ExOS etc.
Advantage :It has fewest hardware abstractions.
Disadvantage :There is more work for application developers.
Difference between monolithic and
microKernel MICROKERNEL MONOLITHIC
In monolithic kernel, both user services and kernel
In microkernel user services and kernel, services
services are kept in the same address space.
are kept in separate address space.
OS is complex to design. OS is easy to design and implement. Microkernel are smaller in
size. Monolithic kernel is larger than microkernel. Easier to add new functionalities. Difficult
to add new functionalities. Execution speed is low. Execution speed is high. It is easy to
extend Microkernel. It is not easy to extend monolithic kernel. Example : Mac OS X.
no
Example : Microsoft Windows 95. Require message passing and context switching
message passing and context switching are
Questions asked in GTU
1. What is Kernel? Differentiate between Monolithic Kernel and Micro
Kernel. 2. Explain different service/functions provided by operating
system. 3. Discuss role of OS as a resource manager.
4. Explain the features of Time sharing system.
5. What is operating system? Give the view of OS as a resource
manager. 6. What is system call? Explain steps for system call
execution.
7. Write different types of system call.
8. List out types of operating system and explain batch OS and time sharing OS in brief.