Concepts of Operating
Systems
Atul Kahate
Session 1: Introduction to
Operating Systems
Why Operating Systems?
• When we start our computer, a special program called operating
system is loaded from the disk into the main memory (RAM) of the
computer
Why Operating Systems?
• All our applications are on the • When we run an application, it is
disk in the form of files loaded by the operating system
into the main memory
Why Operating Systems?
• The instance of a program is a process
Introduction to OS Concepts
• An Operating System (OS) is a
program that acts as an
intermediary between a user of a
computer and the computer
hardware.
• Operating system goals:
• Execute user programs and make
solving user problems easier.
• Make the computer system
convenient to use.
• Use the computer hardware in an
efficient manner.
Operating System versus Application
Software Linux, Windows, Word, PowerPoint,
Firefox
Mac
An operating system is like the Application software makes use of
entry point into a computer: This is an operating system for
where the computer wakes up. performing various tasks.
The operating system is An application software allows the
responsible for handling all the user to create presentations, play
aspects pertaining to user games, browse the Internet, etc.
programs, process management,
memory management, disk An application software is specific,
management, working with the whereas an operating system is
CPU, etc. generic
Why are High-level Languages Portable?
Program
written in
C
C compiler for C compiler for C compiler for
Windows Linux Mac
Execute Execute Execute
Why is OS Hardware-dependent?
We have two major choices when writing
Hardware-
an OS:
dependent
Choice 1: Write the OS in the assembly
language of the chosen hardware
Hardware-
Choice 2: Write the OS in a high-level independent
language (such as C or C++ or Java)
Option 1: Writing OS in Assembly Language
Assembly language is
Operating System specific to the hardware
written in Assembly (CPU)
language
Example: Assembly
Assembler language for Intel x86
processors is different
from the Assembly
Hardware Level language for ARM
(Machine Language) processors used in smaller
devices
Option 2: Writing OS in a High Level
Language
If we write the operating
Operating System system code in a HLL such
written in C++, give as C++, we need to
source code recompile it on each target
environment
Compile it on the target
hardware Now the OS is
independent of the
Hardware Level hardware
(Machine Language)
Option 3: Writing OS in Java (Virtual
Machine Environment)
If we write the operating
Operating System system code a VM-based
written in Java, do not language such as Java, we
give source code can compile it only once
anywhere and give the
Compile it on any
generated bytecode
machine to generate
(object code), which can
bytecode, give bytecode
run on any machine in the
Hardware Level world that has Java
(Execute the bytecode Runtime Environment
on any machine that has installed
JRE)
Different Components of an OS
Computer System Structure – 4 Components
• Hardware – Provides basic computing resources
• CPU, memory, I/O devices
• Operating system - Controls and coordinates use of hardware among
various applications and users
• Application programs – Define the ways in which the system
resources are used to solve the computing problems of the users
• Word processors, compilers, web browsers, database systems, video games
• Users - People, machines, other computers
• See next slide for a diagram
Computer System – Four Components
Examples of OS
• Mobile OS: Android, iOS
• Embedded Systems OS: Embedded Linux, QNX, VxWorks – Generally
work on microwave ovens, TV, DVD, MP3 players, etc – Embedded in
ROM
• Real-time OS: eCos - Deadline-based work, Controlling machines,
Welding robots, etc
• Desktop OS: Windows, Linux, Mac – General-purpose OS
• Server machine OS: Windows server/Linux server – Need to handle
client-requests, load, security
Main Functions of Operating Systems
Provide abstraction Managing computer
to user programs resources
A modern computer consists of one or more
processors, some main memory,
disks, printers, a keyboard, a mouse, a display, network
interfaces, and various
Managing these resources
other input/output devices. If every application
in itself is a huge task!
programmer
had to understand how all these things work in detail,
no code would ever
get written.
Kernel
• “The one program running at all times on the computer” is the kernel.
• Everything else is either a system program (ships with the operating
system) or an application program.
User Mode and Kernel Mode (Diagram on
Next Slide)
• Most computers have two modes of operation: kernel mode and user
mode.
• The operating system runs in kernel mode (also called supervisor
mode).
• It has complete access to all the hardware and can execute any instruction
that the hardware supports
• The rest of the software runs in user mode, in which only a subset of
the machine instructions is available.
• Those instructions that affect control of the machine or do I/O (Input/Output)
cannot be used
User Mode and Kernel Mode
User Mode and Kernel Mode
• User mode has restricted access to
resources. Example: Text editor,
Media player. If a resource such as
disk or file is needed, a signal is sent
to the CPU via an interrupt to
switch to the kernel mode.
• Kernel mode (also called as
supervisor mode) has full access to
memory, I/O, and other resources.
Here, CPU has full access to the
hardware and can execute any
instruction.
User Space and Kernel Space
User space Kernel space
Area of memory where Area of memory where
all the user mode all the kernel mode
applications execute. applications execute.
This memory can be Strictly reserved for kernel
“swapped out” when background processes and has
full hardware access.
necessary.
User Mode to Kernel Mode Transition
Kernel Mode versus User Mode
Interrupt
• When the current processing needs to be temporarily stopped for
handling some event of a higher priority, an interrupt is generated
• Example: The operating system is reading a file and the user types
something on the keyboard
• This will generate a keyboard interrupt
• The operating system will handle this interrupt (i.e. handle the processing
related to the key) and then resume file reading
Interrupt Example
Handling interrupts
• An interrupt is a signal sent by hardware or software to the processor
for processing
• The process that runs when an interrupt is generated is the interrupt
handler
• The CPU saves the state of the ongoing process and shifts its attention to
the interrupt generated by giving access to the interrupt handler
• This entire process is called interrupt handling
• The interrupt handler is also known as Interrupt Service Routine (ISR)
• ISR handles the request and sends it to the CPU
• When the ISR is complete, the halted process is resumed
How does the CPU know which ISR to call?
• Each type of interrupt is assigned a unique interrupt number
• The interrupt number and its corresponding instructions set address
(or process’s base address) are stored in a vector table known as
Interrupt Vector Table (IVT), see next slide
• Using the interrupt number and IVT, the CPU comes to know about
the base address of the process that is needed to handle the
respective interrupt
• Now, the control is given to that process to handle the interrupt and
this process is known as Interrupt Service Routine (ISR)
Interrupt Vector Table
Interrupt Number Memory Address of Interrupt Handler Code
1 abcd:pqrs
2 wxyz:mnop
3 lmno:stuv
… …
… …
IVT in x86 Machines
• Using the emu8086 emulator, open memory view and change the
address to all 0s – the contents are the IVT
Understanding IVT
• In the emu8086 emulator, type • Emulate and Single step to run the int
instruction
this code:
Four addresses, • View-Memory, change address to
respectively for 0000:0000
• org 100h interrupts 1, 2, 3, and 4 -
So, each interrupt entry
takes four bytes
• Check CS (Code Segment) and IP
• int 0x00 (Instruction Pointer) registers
Little endian method is used,
which means 70 01 is actually 01 • They are the same as the first four bytes at
70 memory address 0000:0000, which means
• ret Also, offset is stored first, then the the CPU is ready to execute the code for
segment (We will discuss in that interrupt now, at memory address
segmentation), so full address is F400:0170
F400:0170
Interrupts and System Calls
• Example: a Network Interface card
(NIC) is a hardware interface between a
computer and a network. When the
NIC receives data over its network
connection, it interrupts (or wakes up)
the OS to handle the received data.
• Requests to the OS also come from
user applications when they need
access to protected resources. For
example, when an application wants to
write to a file, it makes a system call to
the OS, which wakes up the OS to
perform the write on its behalf.
In C/C++, we would write
this as:
Interrupts: Demo putchar (‘A’);
• Type the following program in the 8086 • org 100h = Load program in memory
assembler emulator (emu8086v408), then location 100 hex
press the Emulate button • mov ah, 0eh = Set the sub function for
interrupt 10h to 0eh, which means show
• org 100h character on the screen – another example
is 07h, which means scroll down, etc
• mov al, ‘A’ = Specify the character to be
• mov ah, 0eh displayed
• mov al, 'A' • int 10h = Now generate a software interrupt
number 10h that executes the sub-function
0eh, i.e. show character on the screen
• int 10h
• See
https://faculty.kfupm.edu.sa/COE/shazli/coe
• ret 205/Help/asm_tutorial_04.html
Interrupts Demo: Read a Character and
Display it Back
• org 100h • Note: Earlier we used interrupt
10h to display
• mov ah, 1h ; keyboard input
subprogram • However, interrupt 21h can be
• int 21h ; read character into al used for both input and output
• For input, place a value of 1h in
• mov dl, al ; copy character to dl
the ah register
• For output, place a value of 2h in
the ah register
• mov ah, 2h ; character output
subprogram
• int 21h ; display character in dl
• ret