CS211 Lec 3
CS211 Lec 3
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
Interrupt/trap
kernel user
set user mode
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
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
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
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
Interrupt Trap
27
System Calls
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 …
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
33