Sunteți pe pagina 1din 53


Prachi Pandey
C-DAC, Bangalore

Managing all these varied components requires

a layer of software the Operating System (OS).

An Operating System is a program that acts as an

interface between a user of a computer and the
computer hardware.

Primary Goal Convenience

Secondary Goal - Efficiency

Or is it the other way round?

Source CodeCompilerObject CodeHardware

How do you get object code onto the hardware?
How do you print out the answer?
Once upon a time, had to Toggle in program in
binary and read out answer from LEDs!

Altair 8080

Control/execute user/application programs.

Make the computer system convenient to use.
Ease the solving of user problems.
Use the computer hardware in an efficient
Provide isolation, security and protection
among user programs.

Every piece of computer hardware different

Different CPU
o Pentium, PowerPC, ColdFire, ARM, MIPS
Different amounts of memory, disk,
Different types of devices
o Mice, Keyboards, Sensors, Cameras,
Fingerprint readers
Different networking environment
o Cable, DSL, Wireless, Firewalls,

Does the programmer need to write a single
program that performs many independent
Does every program have to be altered for
every piece of hardware?
Does a faulty program crash everything?
Does every program have access to all

Batch Operating Systems

Time Sharing Operating Systems
Multiprocessor Operating Systems
Network Operating Systems
Real Time Operating Systems

Users did not interact with computer directly.

Each user submitted his/her jobs to the operator

who in turn fed the programs to the computer.
User had to come back later to collect the output.

Early batch system

1. bring cards to 1401
2. read cards to tape
3. put tape on 7094 which does computing
4. put tape on 1401 which prints output

Lack of interaction between the user and job.

CPU is often idle, because the speeds of the

mechanical I/O devices is slower than CPU.
Difficult to provide the desired priority.

To understand time-sharing OS we need to understand a

concept called Multiprogramming.
Multiprogramming means sharing of resources
between more than one processes.
CPU time is not wasted, because, while one process
moves on some I/O work, the OS picks another process
to execute till the current one passes to I/O operation.
Goal of multiprogramming is to efficiently utilize all
of the computing resources.

Time sharing is a technique which enables many people,

located at various terminals, to use a particular computer
system at the same time.
Main computer; having a
CPU executing processes by
utilization of the OS, (e.g.

Terminals are
connected to the main
computer and used for
input and output. No
processing is made.
They do not have

Time-sharing or multitasking is a logical extension of


In Time Sharing OS

OS switches between users programs very quickly,

generally in round-robin fashion.
Switching between users is very fast.
Goal is to give the illusion that each user has his/her
own machine.
Response time is a priority.

Has multiple processors sharing memory and

peripheral devices.
With this configuration, they have greater
computing power and higher reliability.
Multiprocessor systems are classified into two as
tightly-coupled and loosely-coupled (distributed).
In the tightly-coupled one, each processor is
assigned a specific duty but processors work in
close association, possibly sharing the same
In the loosely coupled one, each processor has its
own memory and copy of the OS.

In network systems, each process runs in its own

machine but the OS have access to other machines.
In networks, users are aware of the fact that s/he is
working in a network and when information is
The user explicitly handles the transfer of

A real-time operating system is an operating system

that guarantees to process events or data within a
certain short amount of time.

A real-time operating system may be single- or multitasking, but when multitasking, it uses specialized
scheduling algorithms so that a deterministic nature of
behavior is achieved.

How to run multiple applications in such a way that
they are protected from one another
Keep User Programs from Crashing each other
Keep User Programs from Crashing OS
Keep Parts of OS from crashing other parts?
Simple Policy:
Programs are not allowed to read/write memory of
other Programs or of Operating System
Address Translation
Dual Mode Operation


Data 2


Stack 1
Heap 1
Code 1
Stack 2

Prog 1
Space 1

Prog 2
Space 2

Data 1
Heap 2
Code 2
OS code

Translation Map 1

OS data

Translation Map 2

OS heap &

Physical Address Space

Two modes:
o Kernel mode (or supervisor or protected)
o User mode: Normal programs executed
Some instructions/ops prohibited in user mode:
o Example: cannot modify page tables in user mode
Attempt to modify Exception generated
Transitions from user mode to kernel mode:
o System Calls, Interrupts, Other exceptions

Process Management

Main Memory Management

Storage Management

I/O System Management


Protection System

Command-Interpreter System

A process is a program in execution

Process needs resources to accomplish its task

Process termination requires reclaim of any reusable
Single-threaded process has one program counter
specifying location of next instruction to execute
Multi-threaded process has one program counter per
Typically system has many processes, some user,
some operating system running concurrently on one
or more CPUs
-Concurrency is achieved by multiplexing the CPUs among
the processes / threads

The operating system is responsible for the following

activities in connection with process management:
Creating and deleting both user and system
Suspending and resuming processes
Providing mechanisms for process
Providing mechanisms for process
Providing mechanisms for deadlock handling

Memory management activities

o Keeping track of which parts of memory are
currently being used and by whom
o Deciding which processes (or parts thereof) and
data to move into and out of memory
o Allocating and deallocating memory space as

OS provides uniform, logical view of information storage

Abstracts physical properties to logical storage
unit - file
Each medium is controlled by device (i.e., disk
drive, tape drive)
-Varying properties include access speed, capacity,
data-transfer rate, access method (sequential or

OS activities include
Creating and deleting files and directories
Primitives to manipulate files and directories
Mapping files onto secondary storage

One purpose of OS is to hide peculiarities of

hardware devices from the user.
I/O subsystem responsible for
(Efficiency, fairness, prioritized access)
(storing data temporarily while it is being
(storing parts of data in faster storage for
device-driver interface

The kernel is the central module of an operating

system (OS).
It is the part of the operating system that loads
first, and it remains in main memory.

The Unix kernel

Consists of everything below the system-call interface
and above the physical hardware

Kernel components
File Manager
Maintains information about the files that are available
on the system
Device Drivers
Software to communicate with peripheral devices or
Memory Manager
This unit is responsible for coordinating the use of the
machines main memory
Scheduler & Dispatcher
These units together manage processes

Roles of a kernel
responsible for the creation and destruction of
memory space which allows software to run
provides services so that programs can request
the use of the network card, the disk or any other
piece of hardware
manages the file system and sets interrupts for
the CPU to enable multitasking.
responsible for ensuring that faulty programs do
not interfere with the operation of others

System memory can be divided into two distinct

regions: kernel space and user space.
Kernel space is where the kernel (i.e., the core of the
operating system) executes (i.e., runs) and provides
its services.
User space is that set of memory locations in
which user processes (i.e., everything other than the
kernel) run.

Also called privileged mode, also referred to as

system mode.
Used mainly for Restriction/ Protection from
unauthorized user application program

When the CPU is in kernel mode, it is assumed to

be executing trusted software, and thus it can
execute any instructions and reference any
memory addresses (i.e., locations in memory).

all other programs(user applications) are

considered untrusted software.

A good example of this would be device drivers.
A device driver must tell the kernel exactly how to
interact with a piece of hardware, so it must be run in
kernel mode.
Because of this close interaction with the kernel, the
kernel is also a lot more vulnerable to programs
running in this mode, so it becomes highly crucial
that drivers are properly debugged before being
released to the public.

It is a non-privileged mode.
It is non-privileged in that it is forbidden for
processes in this mode to access those portions of
memory (i.e., RAM) that have been allocated to the
kernel or to other programs.
User mode is the normal mode of operating for
Code running in user mode must delegate to system
APIs to access hardware or memory.
Most of the code running on your computer will
execute in user mode.

When a user mode process wants to use a service

that is provided by the kernel, it must switch
temporarily into kernel mode, which has root privileges,
including root access permissions.
When the kernel has satisfied the process's request, it
restores the process to user mode.

Monolithic Kernel
Hybrid Kernels

All OS services run along with the main kernel

They also reside in the same memory area
This approach provides rich and powerful
hardware access
Linux and FreeBSD

Moves as much from the kernel into user space

Communication takes place between user modules

using message passing
Easier to extend a microkernel
Easier to port the operating system to new
More reliable (less code is running in kernel
More secure
Performance overhead of user space to kernel
space communication
AIX, BeOS, Hurd, Mach, Mac OS X, MINIX, QNX

They are similar to micro kernels, except they

include some additional code in kernel-space to
increase performance
This approach combines the speed and simpler
design of a monolithic kernel with the modularity and
execution safety of a microkernel.
MS Windows NT to 8.1, Mac OSX


Interrupt transfers control to the interrupt service routine

o determine action to be taken for each type of interrupt.

o Interrupt vector contains the address of service
OS preserves the state of the CPU

o stores registers and the program counter (address of

interrupted instruction).

o software generated interrupt caused either by an error

or a user request.

Types of interrupt
o Polling
o Vectored interrupt system

Incoming interrupts are disabled while another

interrupt is being processed to prevent a lost interrupt.

The only way an user space application can explicitly initiate a

switch to kernel mode during normal operation is by making
a system call such as open, read, write etc.

Whenever a user application calls these system call APIs with

appropriate parameters, a software interrupt/exception(SWI)
is triggered.

As a result of this SWI, the control of the code execution

jumps from the user application to a predefined location in
the Interrupt Vector Table [IVT] provided by the OS.

This IVT contains an address for the SWI exception handler

routine, which performs all the necessary steps required to
switch the user application to kernel mode and start
executing kernel instructions on behalf of user process.


Operating System Principles, by Galvin, Wiley

Berkley CS 162 course: Prof John Kubiatowicz

Operating System Gate lectures by Ravindrababu