0% found this document useful (0 votes)
10 views

CS211 Lec 3

The document discusses various topics related to operating systems including hardware protection mechanisms, resource management, security and protection, virtualization, kernel data structures, and the user-operating system interface. Interrupts, traps, and signals and how they are handled by the operating system are also covered.

Uploaded by

Muhammad Rafay
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)
10 views

CS211 Lec 3

The document discusses various topics related to operating systems including hardware protection mechanisms, resource management, security and protection, virtualization, kernel data structures, and the user-operating system interface. Interrupts, traps, and signals and how they are handled by the operating system are also covered.

Uploaded by

Muhammad Rafay
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/ 33

Operating Systems

Course Code: CS211


Instructor: Dr. Sarah Iqbal

Lecture # 3
Agenda for Today
 Review of previous lecture
 Hardware (I/O, memory, and CPU) protection
 Resource Management
 Security and Protection
 Virtualization
 Kernel Data Structures
 User and Operating‐System Interface
 Operating System Services
 System calls

2
Interrupts, Traps, and Signals
 The occurrence of an event is usually signaled by an interrupt
from either the hardware or the software.
 Hardware may trigger an interrupt at any time by sending a
signal to the CPU usually through system bus.
 Interrupts are used for many other purposes as well and are
a key part of how operating systems and hardware interact.
 Software may trigger an interrupt by executing a special
operation called a system call.
 A process can generate a trap, for example, by dividing a
number by zero.
 A user or a process may generate a signal (an interrupt to a
process) 3
Interrupt Handling
 Interrupt transfers control to the interrupt service routine,
generally, through the interrupt vector, which contains
addresses of all the interrupt service routines.
 Interrupt architecture must save the address of the
instruction after the interrupted instruction and the CPU
state so that execution of the interrupted process may
continue (restore) after the interrupt has been serviced.
 Incoming interrupts are disabled while another interrupt is
being processed to prevent lost interrupts.
 An operating system is interrupt driven. Interrupts are an
important part of a computer architecture.

4
Interrupt
Handling

5
Hardware Protection

 Dual‐Mode Operation
 I/O Protection
 Memory Protection
 CPU Protection

6
Dual‐Mode Operation

 Sharing system resources requires operating system to ensure that


an incorrect program cannot cause other programs to execute
incorrectly.
 Provide hardware support to differentiate between at least two
modes of operations.
• User mode – execution done on behalf of a user.
• Kernel mode (also monitor mode, supervisor mode, system
mode, or privileged mode) – execution done on behalf of
operating system.
 When an interrupt or trap occurs, or a process executes a system
call, CPU switches to kernel mode.
7
Dual‐Mode Operation …
 Mode bit added to computer hardware to indicate the
current mode: kernel (0) or user (1).
 When an interrupt or trap or system call occurs
hardware switches to kernel mode.

Interrupt/trap

kernel user
set user mode

Privileged instructions can be issued only in kernel mode.


8
I/O Protection
 All I/O instructions are privileged instructions.
 Must ensure that a user program could never gain
control of the computer in kernel mode.
 To achieve this there are some defined entry points
into the kernel (this will allow the kernel to execute
these I/O instructions on behalf of the user program)
 The OS provides a system call interface to execute
such instructions.
 System call is a way through which an OS allows a user
process to perform an I/O operation (or other
privileged operations).
9
Use of A System Call to Perform I/O

10
Memory Protection
 Region in the main memory that a process can legally
access is known as its address space.
 Must provide memory protection outside the address
space of a process.
 In order to have memory protection, add two registers
that determine the range of legal addresses a program
may access:
 Base register – holds the smallest legal physical
memory address.
 Limit register – contains the size of the process

 Memory outside the defined range is protected.


11
Use of Base and Limit Register
Kernel

Process 1

Process 2

Process 3

Process 4

12
Hardware Support

13
Storage Structure
The CPU can load instructions only from memory, so any programs must first be loaded
into memory to run. General‐purpose computers run most of their programs from
rewritable memory, called main memory (also called random‐access memory, or RAM).

14
CPU Protection
 Timer and a fixed‐interval clock that interrupts the CPU
periodically.
 Timer – interrupts computer after specified period to ensure
operating system maintains control.
 Timer is loaded with a value and decremented with every
clock tick.
 When timer reaches the value 0, an interrupt occurs and
an ISR is executed to switch CPU to another process.
 Load‐timer is a privileged instruction.

15
Resource Management
An OS has many components that manages all the resources
(resource manager) in a computer system, ensuring proper
execution off programs.

1) Process Management
2) Memory Management
3) Mass‐Storage Management
4) Cache Management
5) I/O System management
6) File‐System Management

16
Security and Protection
 If a computer system has multiple users and allows the concurrent
execution of multiple processes, then access to data must be regulated.
For that purpose, mechanisms ensure that files, memory segments,
CPU, and other resources can be operated on by only those processes
that have gained proper authorization from the operating system.
 Protection is any mechanism for controlling the access of processes or
users to the resources defined by a computer system. This mechanism
must provide means to specify the controls to be imposed and to
enforce the controls.
 It is the job of security to defend a system from external and internal
attacks. Such attacks spread across a huge range and include viruses
and worms, denial‐of‐service attacks (which use all of a system’s
resources and so keep legitimate users out of the system), identity theft,
and theft of service (unauthorized use of a system).
17
Virtualization
 Virtualization is a technology that allows us to abstract the hardware of
a single computer (the CPU, memory, disk drives, network interface
cards, and so forth) into several different execution environments,
thereby creating the illusion that each separate environment is running
on its own private computer

 Virtualization allows operating systems to run as applications within


other operating systems.

 Emulation, which involves simulating computer hardware in software, is


typically used when the source CPU type is different from the target
CPU type.

18
Kernel Data Structures
It defines the way data are structured in the system
 An array is a simple data structure in which each element can be accessed directly.
After arrays, lists are perhaps the most fundamental data structures in computer
science. Whereas each item in an array can be accessed directly, the items in a list
must be accessed in a particular order. That is, a list represents a collection of data
values as a sequence. The most common method for implementing this structure is
a linked list, in which items are linked to one another.

 A stack is a sequentially ordered data structure that uses the last in, first out (LIFO)
principle for adding and removing items, meaning that the last item placed onto a
stack is the first item removed. The operations for inserting and removing items
from a stack are known as push and pop, respectively.

 A queue, in contrast, is a sequentially ordered data structure that uses the first in,
first out (FIFO) principle: items are removed from a queue in the order in which they
were inserted.
 Other data stuctures include trees, hash functions and maps, bitmaps etc. 19
User and Operating‐System Interface
 There are several ways for users to interface with the operating system.
Here, we discuss three fundamental approaches.
 One provides a command‐line interface, or command interpreter, that
allows users to directly enter commands to be performed by the operating
system.
 The other two allow users to interface with the operating system via a
graphical user interface, or GUI.

20
Command Interpreters
 Most operating systems, including Linux, UNIX, and Windows, treat the
command interpreter as a special program that is running when a process
is initiated or when a user first logs on (on interactive systems).
 On systems with multiple command interpreters to choose from, the
interpreters are known as shells. For example, on UNIX and Linux systems,
a user may choose among several different shells, including the Bourne
shell, C shell, Bourne‐Again shell, Korn shell, and others.
 Third‐party shells and free user‐written shells are also available. Most
shells provide similar functionality, and a user’s choice of which shell to
use is generally based on personal preference.
 The main function of the command interpreter is to get and execute the
next user‐specified command. Many of the commands given at this level
manipulate files: create, delete, list, print, copy, execute, and so on.

21
Graphical User Interface
 A second strategy for interfacing with the operating system is through a
user friendly graphical user interface, or GUI. Here, rather than entering
commands directly via a command‐line interface, users employ a mouse‐
based window‐and‐menu system characterized by a desktop metaphor.
The user moves the mouse to position its pointer on images, or icons, on
the screen (the desktop) that represent programs, files, directories, and
system functions. Depending on the mouse pointer’s location, clicking a
button on the mouse can invoke a program, select a file or directory—
known as a folder—or pull down a menu that contains commands.

 Touch‐Screen Interface

22
Operating System Services

23
Operating System Services

 Services for user and users of programs:


 Program execution
 I/O Operations
 File System Manipulation
 Communications between processes/users
 Error detection and handling

24
Operating System Services …
 Services for efficient system operation:
 Resource management
 Accounting
 Protection

25
OS Kernel

Users
Applications
Operating System API, AUI
Operating System Kernel
Computer Hardware
Real work is done in the kernel
26
Entry Points into Kernel

System Call Signal

Interrupt Trap

27
System Calls

 User processes must not be given open access to the


kernel code
 The system call interface layer contains entry point in
the kernel code
 Any user or application request that involves access to
any system resource must be handled by the kernel
code

28
Types Of System Calls

 Process Control
 File Management
 Device Management
 Information maintenance
 Communications

29
System Call Execution
 The user program makes a call to a library function.
 Library routine puts appropriate parameters at a well‐
known place (registers, stack, or a table in memory).
 The trap instruction is executed to change mode from
user to kernel.
 Control goes to operating system.
 Operating system determines which system call is to be
carried out.

30
Semantics of System Call Execution …

 Kernel indexes the dispatch table, which contains


pointers to service routines for system calls.
 Service routine is executed and return parameter or
error code placed at well‐known places (usually a CPU
register).
 Control given back to user program.
 Library function executes the instruction following
trap.

31
System Call …
Process

Library Call

System Call

trap

Dispatch Table
Service
Code
Kernel
Code

32
Reference & Reading Material
Operating Systems Concepts, by ABRAHAM SILBERSCHATZ
• Chapter 1: Introduction

Section 1.2 Computer‐System Organization


Section 1.4 Operating‐System Operations
Section 1.5 Resource Management
Section 1.6 Security and Protection
Section 1.7 Virtualization
Section 1.9 Kernel Data Structures
• Chapter 2: Operating System Structures

Section 2.1 Operating‐System Services


Section 2.2 User and Operating‐System Interface
Section 2.3 System Calls

33

You might also like