[go: up one dir, main page]

0% found this document useful (0 votes)
60 views112 pages

ICS 431 Ch1 2 OS Intensive Introduction

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 112

Welcome to the ICS 431 Course and let us

collaborate to understand and to be knowledgeable in the


“Operating Systems”

Dr. Tarek Helmy, KFUPM-ICS


Operating Systems 431
Weeks 1- 2
Intensive Introduction of Operating Systems
[Chapters 1, 2, and Parts of 3, 12]

Dr. Tarek Helmy El-Basuny

Dr. Tarek Helmy, KFUPM-ICS


Outline

• In the last class:

• We presented the course information and some coordination issues.

• We agreed on the grading polices including the lab component.

• We discussed the topics to be covered during this course.

• In today’s class,

• We will start the intensive introduction of the operating systems.

Dr. Tarek Helmy, KFUPM-ICS 3


During the Intensive OS Introduction

• We will introduce the computer System’s Component,


• We will introduce the basic computer system organization and operation,
• We will introduce different definitions and views of the OS,
• We will introduce the major Operating Systems (OS) types,
• We will introduce the services an OS provides to users, processes, and other systems.
• We will introduce the common OS components,
• We will introduce the storage hierarchy structure in the computer systems,
• We will introduce caching features & problems and how the OS deals with?
• We will introduce the computing models and the OS support,
• We will introduce multiprocessor and multiprocessing systems, Covered by ch. 1, ch. 2
& Parts of ch. 3 &ch.12
• We will introduce the OS support to multi-processing systems,
in the text book.
• We will introduce real time and embedded OSs,
• We will introduce the interrupts, exceptions and how does the OS handle?
• We will introduce different I/O structures and techniques,
• We will introduce the security and protection issue of system’s resources by the OS,
• We will introduce the system calls, the system programs how does the OS handle?
• We will introduce various ways of structuring an operating system,
• We will introduce how operating systems are installed, customized and how they boot?

Dr. Tarek Helmy, KFUPM-ICS 4


Computer System’s Component

• A computer system consists of


– Hardware modules: Provides basic computing
resources (CPU, memory, I/O devices, etc.).
HW SW
– Applications programs: Define the ways in which
the system resources are used to solve the
computing problems of the users (provide services)
(compilers, database systems, video games, Applications System
business programs).
– Users (people, other computers) run the programs.
– Operating system: Controls and coordinates the
use of the hardware resources among various
OS Non-OS
application programs for various users.

Operating System

Dr. Tarek Helmy, KFUPM-ICS 5


Computer System Organization

• A computer system consists of a CPU, a memory and multiple I/O device


controllers that are connected through a common bus.
• Device controllers interface with the I/O devices under the OS control.
– One controller may handle several devices of the same type
– Controllers have local buffers and a set of specific purpose registers.
– The size of the local buffers various from one device to another.
• Each device controller is responsible for moving the data between the
device it controls and its local buffer under the OS control.
• I/O is from the device to local buffer of controller.
• The CPU can access information directly only if it is kept in main memory.
• I/O devices and the CPU can execute concurrently, competing for the
memory access.
• To ensure orderly access to the memory, the OS with memory controller
should synchronize access to the shared memory.

Dr. Tarek Helmy, KFUPM-ICS 6


Computer-System Operation

• After turning on a computer system, its main memory is empty:


how can the execution of programs be started?
• A small part of the OS (BIOS) is built in the board (ROM/EPROM).
• First, the CPU executes the BIOS to validate the system
resources.
• Second, the essential parts of the OS are loaded from the hard
disk to the main memory and then executed.
• Third, the execution of a user’s programs (processes) begin.
• Instructions are executed one after the other as specified in the
running program.
• If an I/O operation is required, the program under execution is
temporarily suspended, and the CPU switches to execute another
service program.
• Interrupts are used to signal important events; they disrupt the
flow of execution temporarily.
• The purpose of an interrupt is to transfer control from the current
task to the OS.
Dr. Tarek Helmy, KFUPM-ICS 7
What is an Operating System?

• There is no a universally accepted definition of


the OS. You are here
• It’s a program that mediates between the Application Program
application programs and the hardware Operating System
resources. Computer Hardware
• It’s a program that manages all other programs
and resources in a computer system.
• Operating system is a program that:
– Controls input/output data from/to
input/output devices.
– Keeps track of files and directories on the
disk.
– Keeps track of how much each process will
get out of a resource and for how long.
• It allows application programs to co-exist
peacefully, i.e.:
– Enforcing Protection and security policies,
– Detecting and recovering of errors,
– Sharing resources fairly among concurrently
running processes.
Dr. Tarek Helmy, KFUPM-ICS 8
What is an Operating System?

User 1 User 2 User 3 User N

Compiler Spreadsheet Text Editor Pacman

System and Application Programs

Operating System
Controls the hardware and coordinates its use among the various application programs for the various user.

Computer Hardware

Dr. Tarek Helmy, KFUPM-ICS 9


What is an Operating System?

• It is a control program that controls the execution of user’s


programs and operations of I/O devices.
• It provides abstractions to simplify building applications:
– Files instead of “bytes on a disk”
– Contiguous memory regions (segments/pages) instead of “bits in
a RAM chip”.
• It is an extended machine that:
– Presents user with a virtual machine, easier to use.
– Hides the messy details which must be performed.

• An OS can be viewed as an event-driven system:

– That reacts to events as they occur by the user or the


processes.

• Write your own definition here,

– …..

Dr. Tarek Helmy, KFUPM-ICS 10


Benefits of the Operating Systems

• The benefits are for programmers, processes and users.


– Programming simplicity since the programmer will see high-level
abstractions (i.e. files) instead of low-level hardware details (device
registers).
– Programming simplicity due to code reusability across many APIs.
– Allow number of users to use the computer system simultaneously.
– Program “sees” own virtual machine, thinks its owns computer.
– OS protects programs/user from each other.
– OS fairly multiplexes resources across programs.
– Improving the cost , responsiveness and throughput (the amount of
work that a computer can do in a given time period) through:-
• Sharing of resources across many users/processes.
• Concurrent execution of multiple processes on the same
recourse.

Dr. Tarek Helmy, KFUPM-ICS 11


How do we Interact with the Operating Systems?

• Graphical User Interface (GUI)


Usually a window system with a pointing
device to direct I/O, choose from menus and
make selections and a keyboard to enter text.

• Command Line Interface (CLI)


A mechanism for interacting with a computer
operating system or software by typing
commands to perform specific tasks.

• Batch Interface (shell scripting)


Commands and directives to control those
commands are entered into files, and those
files are executed.

Dr. Tarek Helmy, KFUPM-ICS 12


Many OS now include both CLI and GUI Interfaces

• Apple Mac OS X has “Aqua” GUI interface with


UNIX kernel underneath and shells available.

• Microsoft Windows is GUI with CLI “command”


shell.

• Solaris is CLI with optional GUI interfaces

Dr. Tarek Helmy, KFUPM-ICS 13


The Operating System Types

• Single Processor operating systems: Designed to support concurrent


executing of processes on a single processor machine.

• Multiprocessor operating systems: Designed to support large collection of


concurrent executing of processes on multiprocessor machines (Multi-core).

• Single Processing Operating Systems: the OS allows a single process to


run at a time.

• Multi-Processing or Multi-Task Operating Systems: the OSs that allow


the execution of multiple processes at the same time/concurrently.
• Multi-processing can be of two types namely, pre-emptive or co-operative.
– In preemptive multiprocessing, the operating system slices the CPU time
and dedicates one slot to each of the processes. Unix-like operating
systems such as Solaris and Linux support preemptive multiprocessing.
– Cooperative multiprocessing is achieved by relying on each process to
give time to the other processes in a defined manner.

Dr. Tarek Helmy, KFUPM-ICS 14


The Operating System Types

• Server Operating System: it provides runtime support for specialized, high-


performance server applications, e-mail, HTTP, FTP, printer servers.

• Multi-User/Time-Sharing Operating Systems: The operating system allows


multiple users to access a computer system concurrently through the sharing
of time. Unix is an example of multi-user operating systems.

• Single-User Operating Systems: as opposed to a multi-user operating


system, are usable by a single user at a time. Being able to have multiple
accounts on a Windows operating system does not make it a multi-user
system. Rather, only the network administrator is the real user. But for a Unix-
like operating system, it is possible for more than one user to login at a time.

• Single-User, Single-Task: is designed to manage the computer so that one


user can effectively do one thing at a time. The Palm OS for Palm handheld
computers is a good example of a modern single-user, single-task operating
system.

Dr. Tarek Helmy, KFUPM-ICS 15


The Operating System Types

• Single-User, Multi-Tasking: Allows a single user to run several programs at


the same time. Windows and Mac platforms are both examples of that
operating systems.

• Multithreading Operating Systems: that allow different threads of a running


process to run concurrently.

• Smart card/Embedded Operating System: It comes pre-installed on a chip


of the device (i.e. clock, microwave, ..) to provide highly stable functionalities.
(i.e. Java Card OS, Aptura Smart Card OS). It is able to operate on:
– Slow processors
– Limited recourses due to the size

Dr. Tarek Helmy, KFUPM-ICS 16


The Operating System Types

• Real-Time Operating Systems: are those in which the correctness of the


system depends not only on the logical result of computation, but also on
the time at which the results are produced.
• Often used in dedicated applications such as controlling scientific
experiments, medical imaging systems, industrial control systems, and some
display systems. There are two types:
• Hard real-time system
– Guarantees that critical tasks be done on time,
– All delays in the system must be bounded,
– Secondary storage is usually limited or missing, why?
• Data stored in short term memory, or read-only memory (ROM),
• Useful for industrial applications.
• Soft real-time system
– Deadline is important but not critical,
– Limited utility in industrial control or robotics,
– Useful in real-time applications such as multimedia, networking,
advanced scientific projects, etc..

Dr. Tarek Helmy, KFUPM-ICS 17


The Operating System Types

• Cyber Shield Operating System: designed to deliver verifiable security for


conducting confidential online transactions, such as online banking, or
accessing medical records. https://www.youtube.com/watch?v=XuQdk1HQjNo
• It is used to boot the PC with Cyber Shield-OS from a USB or CD, then
conduct one's online banking or other sensitive Internet transactions, then
when finished shut down Cyber Shield-OS and return to one's normal PC
environment.
– Cyber Shield-OS is not intended as a substitute for a general purpose
operating system.
– Cyber Shield-OS is not designed to support the PC's internal Wi-Fi
network adapter. It only allows cable-based internet connection.
– Cyber Shield-OS runs in PC RAM only. It is not designed to install on the
PC's hard drive.
– Cyber Shield-OS does not allow any changes to the original code, any
attempts to install a plug-in will be discarded.
– Cyber Shield-OS includes a built-in firewall that blocks LAN access during
its operation.
– The objective is to isolate the PC running Cyber Shield-OS from other
PC's on the same LAN as the security status of the other PC's may be
unknown.

Dr. Tarek Helmy, KFUPM-ICS 18


The Major OS Design Issues

 As we are going to study the OS, we should think about the followings:
– Structure: How are the OS components organized?
– Sharing: How are resources shared across users/processes?
– Concurrency: How are concurrent processes (computation and I/O)
created and controlled?
– Naming: How are resources named (by users or processes)?
– Communication: How do processes exchange information, including
across network?
– Security: How is the integrity of the OS and its resources ensured?
– Accounting: How do we keep track of a resource usage, and perhaps
charge for it?
– Performance: How do we make it all go fast to improve the
responsiveness.
– Reliability: What happens if something goes wrong (either with hardware
or with a program)?
– Extensibility: Can we add new features into the OS?
– Scale: What happens as demands or resources increase?
– Distribution: How do multiple computers interact with each other?

Dr. Tarek Helmy, KFUPM-ICS 19


Operating System Services/Functions

• Program execution: the OS allows the system to load a program into memory
(where, when, and how long?) and to execute it.
• I/O operations: Since user programs cannot execute I/O operations directly,
the OS must provide some means to perform I/O.
• File-system manipulation: the OS allows programs to read and write files and
directories, to create and delete them, to search for them, to list file
Information, etc.
• Communications: the OS allows processes executing either on the same
computer or on different systems tied together by a network to exchange
information. Implemented via shared memory or through message passing.

Dr. Tarek Helmy, KFUPM-ICS 20


Operating System Services/Functions

 Error detection and recovery: OS needs to be continuously aware of


possible errors.
• Errors may occur in the CPU, memory, I/O devices, or in user’s program.
• For each type of error, OS should take the appropriate action to ensure
correct and consistent computing.
 Resource allocation:
• When there are multiple users or multiple processes running at the same
time, resources must be allocated fairly to concurrently running
processes/users.
 Accounting:
• Keep track of resources utilization and usage?
• What kind of resources and how much each process/user is using?
 Protection and Security:
• When several processes execute concurrently, it should not be possible
for one process to interfere with the others or with the OS itself.
• Security of the system from outsiders is also important and defense of the
system against internal and external attacks.

Dr. Tarek Helmy, KFUPM-ICS 21


There are 5 Views of the OS

Your view of an OS depends on who you are and your


interest:
• The hardware engineer view
• The operating system designer’s view
• The application programmer’s (Software Engineer) view
• The end-user’s view
• The system administrator’s view

Dr. Tarek Helmy, KFUPM-ICS 22


The Hardware Engineer View

• The HW engineer interest revolves around:


• How to make the booting process more faster by writing efficient
Bootstrap program.
• A bootstrap program is the first code that is executed when
the computer system is started .
• Typically stored in ROM or EPROM, generally known as
Firmware/BIOS.
• Initializes all aspects of system.
• Loads operating system kernel and starts execution of
processes.
• How does the OS verify the devices and efficiently use them.
• How to make the interactions between the HW and the OS more
efficient.

Dr. Tarek Helmy, KFUPM-ICS 23


The OS Designer’s View

• The OS designer’s interest revolves mainly about the OS itself, its


internal structure, efficiency, performance, etc..

• How can we make the OS more friendly?

• How can we add more functionality to upgrade the OS?

• How do we debug the Os to make it more reliable, scalable, etc..

Dr. Tarek Helmy, KFUPM-ICS 24


The Application Programmer’s View

Since the OS is like a library with a well defined set of API’s. The application
programmer’s interest revolves mainly around:
• What abstractions are available from the OS?

• How well is the API structured?

– Not too low-level, or high-level.

• How portable is the interface?

– Don’t want to keep rewriting the same program for each new OS
release.

Dr. Tarek Helmy, KFUPM-ICS 25


The End-User’s View

The end user’s interest revolves mainly around:

• End users care about their applications, not the OS.

• The OS should be transparent and friendly.

• The OS must not crash easily.

• The OS must protect their applications and privacy.

Dr. Tarek Helmy, KFUPM-ICS 26


The System Administrator View

• Since, the OS is a program that allows the efficient and fair usage of
resources. The system administrator’s interest revolves mainly
around:

• How easy is it to install a new software on that OS?

• How does OS track usage of resources for accounting?

• How does OS support the security aspects?

• How does OS support the fairness among running processes and


users?

Dr. Tarek Helmy, KFUPM-ICS 27


Main Performance Goals of the OS

1. Maximize Resources Utilization: CPU cycles, Memory, Disks, etc. must be


managed efficiently to maximize the overall system performance.
2. Resources Abstraction: OS transforms the devices into more abstract and
easily used devices. In this way, it is building an extended machine.
3. Fairness: the OS fairly multiplexes the resources across processes.
4. Maximize the throughput: The amount of work that a computer can do in a
given time period.
5. Virtualization: The operating system creates virtual copies of the processor
and the memory so that it can supports different OS to communicate and
exchange information. Gives each user the appearance of an unshared
resource.

Dr. Tarek Helmy, KFUPM-ICS 28


Advantages & Disadvantages of Virtualization

Advantage:
• The virtual-machine concept provides complete protection of system
resources since each virtual machine is isolated from all other virtual
machines.
• Allows you to install different platforms on the same machine.
Disadvantage:
• The isolation, however, permits no direct sharing of resources.
• That means the resources utilization will be low and the throughput will be
low as well.
• The virtual machine concept is difficult to implement due to the effort
required to provide an exact duplicate to the underlying machine.

Dr. Tarek Helmy, KFUPM-ICS 29


Supporting of Multi-processing by OS: Why?
• Multiprocessing means allowing more than one active process to be executed
simultaneously through the interleaving between I/O and CPU bound instructions:
– An I/O-bound process will have short CPU instructions and many I/O instructions.
– A CPU-bound process will have many long CPU instructions and less I/O ones.
• Why: to maximize the throughput and increase system’s resources utilization.
• Since I/O bound Instructions are very slow in execution compared to CPU bound instructions,
for example:
– If there is a CPU with a speed of 400 MHz (400 million cycles/second)
– If each CPU-bound instruction takes 10 cycles/instruction
– That means the CPU can execute about 40 million CPU-bound instructions/second
– Or the CPU can do (40 x 106) / 103= 40,000 CPU-bound instructions/millisecond.
– If one I/O-bound instruction like (Reading 1 disk block) takes 20 ms
– In a time to read one disk block, CPU can do 20 * 40,000 = 800,000 CPU-bound
instructions !!. The result:
• Poor CPU utilization when only one process is executing at a time
• Low throughput.
• Low utilization of the system resources in general

Dr. Tarek Helmy, KFUPM-ICS 30


Multiprocessing OS

• If several processes can execute concurrently, then the CPU can


switch to another one whenever one is waiting for the I/O to
complete and that maximizes the CPU utilization which will increase
the throughput and resources utilization as well.

Dr. Tarek Helmy, KFUPM-ICS 31


Requirements for Multi-processing OS

• In multiprocessing, the OS runs multiple processes at once by interleaving I/O-


bound and CPU-Bound instructions of the running processes.
– But that needs asynchronous I/O devices [once the I/O starts, the control
returns to the OS without waiting for I/O completion] and also needs to know
when the I/O devices are done:
– Interrupts, or Polling or DMA
• It needs HW support for memory management.
 Keeping track of memory usage,
 Process swapping,
 Dynamic memory allocation,
– Base and Limit registers to protect processes from each other.
• It needs SW support to manage resources conflict, i.e.
• CPU scheduling (which process is to be run next),
• Deadlock handling,
• Memory allocation,
• Management of I/O resources,
• The goal is to maximize the system’s throughput and to increase system’s
resources utilization.
– Perhaps at the cost of response time.

Dr. Tarek Helmy, KFUPM-ICS 32


Multiprocessing Modes by the OS

• CPU is shared among a number of processes based on a certain policy (i.e.


SJF, FCFS, ..) while one process is waiting for the I/O, another one can use
the CPU.
• CPU is shared among processes based on a pre-defined time interval.
• Instead of waiting until the process gives up voluntarily the CPU in multi-
processing environment, take it away at regular intervals (time-slices).
• Divide CPU’s time equally or non equally among the processes. If a
process is truly interactive (e.g. editor), then it can be given more time.
• Advantages of both strategies:
– CPU is kept busy and recourses utilization is maximized .
• Disadvantages of both strategies:
– Hardware and OS became significantly more complex for handling CPU
scheduling, handling deadlock, protection, memory management, virtual
memory, etc.

Dr. Tarek Helmy, KFUPM-ICS 33


Supporting of Multiprocessor Systems by the OS, Why?

• Three main advantages of supporting Multiprocessor system by the OS:


– Increased throughput (more CPUs = more work in less time),
– Economy of scale (saves money, CPUs share I/O resources),
– Increased reliability (provides redundancy and fault tolerance),
• Types of Multiprocessor systems:
• Tightly coupled system (Multi-core system, more than one CPU in close
communication).
– Processors connected at the bus level and share both memory and clock,
– Communication usually takes place through the shared memory (i.e. Processor-
Memory Interconnection Network (PMIN), or I/O processor interconnection
network (IOPIN) or Interrupt Signal Interconnection Network (ISIN).
• Loosely coupled system
– Processors do not share memory and clock (Networked machines)
– Processors interconnected via a high speed communication system,
– Communication usually takes place through communicating messages,

Dr. Tarek Helmy, KFUPM-ICS 34


Types of Multiprocessor Systems

• Symmetric Multi-Processing (SMP)


– Each processor runs the same copy of the operating system
• All processors are peers
– It dynamically partitions tasks across the processors, manages the ordering of
task completion, and controls the sharing of all resources among the cores.
– Many processes can run simultaneously without performance deterioration
• Data sharing should be carefully coordinated for efficiency
– Most modern OSs (Windows, Unix, Linux) support SMP.
• Asymmetric Multi-Processing (AMP)
– Master processor runs the OS, schedules and allocates work to slave
processors.
– Each slave is assigned a specific task by the master processor.
– More common in extremely large systems (Distributed or Clustered systems).

Symmetric Multiprocessing Architecture A Dual-Core Design


Dr. Tarek Helmy, KFUPM-ICS 35
Multiprocessor Systems: Distributed Systems

• A distributed system is a set of independent machines that are


geographically distributed and each has its CPU, Memory and I/O
resources but appears to its users as a single coherent system.
• Distributed OS:
– Runs over a set of networked machines not on a single node.
– Provides the user with transparent access to all resources in the
network (including the hot resources, i.e. CPU, Main Memory).
– Gives the impression that there is a single OS controlling the network.
– Distributed OS is a kind of Cooperating OSs (each OS has its goal,
but supports other OSs to achieve their goals by sharing its hot
resources)
node 2 node 1

disk disk
Processors Processors
disk disk

Network
node 3 node N
Processors disk … disk
Processors
disk disk

Dr. Tarek Helmy, KFUPM-ICS 36


Multiprocessor Systems: Distributed Systems

• Advantages of distributed systems:


– Maximize the resources utilization through resources sharing.
– Sharing and printing files at remote sites
– Processing information are remote sites.
– Computation speedup through distributing the load evenly across
machines (Load Balance).
– HW preference: a process may need a HW which is not available locally.
– Data access: a process may need some data that are not locally available
and will migrate to access it rather that transferring the data.
– More Reliability through detecting and recovering from site failure,
function transfer, reintegrate failed sites.
– Supports Inter-Process Communication (IPC) through:
• Message passing,
• Shared memory
• Distributed Systems requires:
– A single global IPC mechanism,
– A global protection mechanism,
– Identical process management and system calls at all nodes,
– Common file system at all nodes.
Dr. Tarek Helmy, KFUPM-ICS 37
Multiprocessor Systems: Distributed vs. Network Systems

 The user is not aware of the


 The user is aware of the existence
multiple CPUs.
of multiple CPUs.
 Each machine runs a part of the
 Each machine has its own private
DOS.
Operating System and runs
 Gives the impression there is a
independently from other
single OS controlling the network.
computers on the network.
 Network is mostly transparent –
 Applications need to know about
it’s a powerful virtual machine.
location of different services.
 Applications interact with single
 Provides mainly I/O sharing (i.e.
service layer.
Files, Printers, etc.)
Dr. Tarek Helmy, KFUPM-ICS 38
Multiprocessor Systems: Clustered Systems

• A computer’s cluster is a group of distributed


computers working together closely to achieve
one computational task.
• The clustered systems are a combination of
hardware and software components.
• The hardware component helps in sharing of
system resources.
• The software component makes all the systems
work together .
• Clustered OS is a kind of Collaborating OSs (all
OSs cooperate to achieve the same task by
sharing their resources including CPUs,
Memories, etc.)
• Clustered systems support high availability, each
node can monitor one or more nodes in the
cluster.
• Examples of Cluster Operating system includes
Solaris MC, UnixWare, MOSIX and GLUnix.
Dr. Tarek Helmy, KFUPM-ICS 39
Multiprocessor Systems: Clustered Systems

• Possible clustering schemes:


– Symmetric mode (two or more nodes running applications and monitoring
each other).
– Asymmetric clustering (one is in hot standby mode while another is
running applications; switches to backup if the active one fails).
• Cluster systems categories:
– High-Availability clusters are implemented primarily for the purpose of improving
the availability of services that the cluster provides. They operate by having
redundant nodes, which are then used to provide service when system
components fail.

– Load-Balancing clusters is when multiple computers are linked together to share


computational workload or function as a single virtual computer. Logically, from the
user side, they are multiple machines, but function as a single virtual machine.

– Computing/Grid clusters are used primarily for computational purposes, rather


than handling IO-oriented operations such as web service or databases.

Dr. Tarek Helmy, KFUPM-ICS 40


Computing Models Shift

• The main objective here is to discuss how the operating support of each
computing model will be different.
Dr. Tarek Helmy, KFUPM-ICS 41
Client-Server Computing Model

• In the Client-Server model: The client


sends a request to a server, and the server
responds with the information requested.
– Popular models, e.g. Telnet, FTP, etc.
• Client-Server Computing
– Client terminals are PCs client
– Servers, responding to requests sent server

by clients
• Server computer provides an
interface to the clients to request
services (i.e. database).
• File-server provides interface for
clients to store and retrieve files.

Client invocation invocation Server

result result
Server

Client
Key:
Proces s: Computer:

Dr. Tarek Helmy, KFUPM-ICS 42


Advantages & Disadvantages of Client-Server Model

• Advantages:
– Centralization: access, resources, and data security are
controlled through the server.
– Scalability: any element can be upgraded when needed.
– Flexibility: new technology can be easily integrated into the
system.
– Interoperability: all components (clients, network, servers) work
together.
– Accessibility: server can be accessed remotely and across
multiple platforms
– Lower costs
• Disadvantages
– If the number of simultaneous client requests to a given server
increases, the server becomes overloaded.
– Lacking of the robustness, if the server fails, clients’ requests
cannot be fulfilled.
Dr. Tarek Helmy, KFUPM-ICS 43
Peer-to-Peer Computing Model

• P2P is a model of distributed system:


– All nodes are considered peers (identical
and there is no distinguish between clients
and servers) peer

– May each act as client, server or both.


– Peers make a portion of their resources,
peer
such as CPU time, Memory space, Disk
storage etc., directly available to other
Peers without the need for central peer
coordination by servers. peer
– A node joins a P2P network must:
• Registers its service with central lookup
service on the network, or peer
peer
• Broadcasts a request for a needed
service and responds to requests for
service via discovery protocol.
peer
– Examples include Napster and Gnutella as peer
file sharing systems. peer

Dr. Tarek Helmy, KFUPM-ICS 44


Advantages & Disadvantages of P2P Computing Model

• Advantages
– No central point of failure
• All peers in P2P network are the same.
• Data and computation is decentralized/not centralized.
• Peers are autonomous, they have full control.
– Scalability
• Since every peer is alike, it is possible to add more peers to the
system and scale it to larger networks.
• Disadvantages
– Decentralized coordination
• How to keep the global state consistent?
• Require distributed coherency protocols.
– All node’s load may not be equal, Load unbalance.
• Computing power, bandwidth have an impact on overall
performance.

Dr. Tarek Helmy, KFUPM-ICS 45


Web/Cloud Computing Model

• Web has become everywhere and available all the time (Ubiquity)
• Computing-intensive applications need more computing and better performance.
• Cloud computing is an Internet-based computing, where shared resources, software
and information are provided to computers and other devices on-demand, like the
electricity grid.
• Cloud computing is a model for enabling convenient, on-demand network access to
a shared pool of configurable computing resources (e.g., networks, servers, storage,
applications, and services) that can be rapidly released with minimal management
effort.
• Cloud computing is a way of managing large numbers of highly virtualized
resources such that, from a management perspective, they resemble a single large
resource. This can then be used to deliver services with flexible scaling.
• Cloud Providers – Amazon, Google, e.g. Google owns more than 20,000 servers/data
center.

Dr. Tarek Helmy, KFUPM-ICS 46


Cloud Computing Frameworks

• So we will just buy everything from the cloud.

Dr. Tarek Helmy, KFUPM-ICS 47


Operating Systems Main Components

1. Process Management Component


(PMC)
2. Memory Management Component
(MMMC)
3. File Management Component (FMC)
4. Mass Storage Management
Component (MSMC)
5. I/O Management Component (IOMC)
6. Network Management Component
(NMC)
7. Protection and Security Component
(PSC)
8. User Interface or Command-
Interpreter-Component (CIC) (i.e. GUI’s
shell in Windows OS, and CLI’s shell in
Unix/Linux OSs).

Dr. Tarek Helmy, KFUPM-ICS 48


Process Management Component (PMC)

• A process is a program in its execution phase.


• A process needs certain resources (i.e. CPU time, Memory Space, Files
access, and I/O devices) to complete its task.
• The PMC in the OS is responsible for the following operations:
– Creating a process,
– Deleting/killing a process,
– Suspending a process,
– Resuming a suspended process,
– Cloning a process,
– Supporting Inter-process communication,
– Creating/killing, …etc. of a child process (sub-process)

• In most systems, processes form a tree, with the root (parent) being the
first process to be created.
• An example of a process tree:
– A created two children processes, B and C
• B created three children processes, D, E, and F
• We will get into the details of the process management in Ch. 3 soon.
Dr. Tarek Helmy, KFUPM-ICS 49
Main-Memory Management Component (MMMC)

• The MMMC in the operating system is responsible for the following activities
in connections with the main memory management:
– The MMMC keeps track of which parts of the main memory are currently
used and which parts are free.
– The MMMC decides which processes to load when memory space
becomes available.
• A policy is needed
– The MMMC decides how many block of memory to allocate to each
process.
• A policy is needed
– The MMMC maintains the mappings of processes from physical to virtual
memory and vise versa.
• Through page tables
– The MMMC decides when to remove/eject out a process from memory if
memory space it required by a VIP process.
• A policy is needed
• We will get into the details of the main memory management in Ch. 8 soon.

Dr. Tarek Helmy, KFUPM-ICS 50


File Management Component (FMC)

• File Management
– A file in windows OS is a collection of related information defined
by its creator. Files represent programs (both data, source, object
and executable forms).
– In Unix/Linux files are either ordinary files (doc., exe., pdf., media,
etc.), directory files (folders) or devise file (printers, CD, ..)
– The FMC is responsible for the following activities in connections
with the file management:
• File creation and deletion.
• Directory creation and deletion.
• Support of primitives for manipulating files and directories.
• Mapping files onto secondary storage.
• File backup on stable (nonvolatile) storage media.

• We will get into the details of the file management in CHs. 13 &14
soon.
Dr. Tarek Helmy, KFUPM-ICS 51
I/O Management Component (IOMC)

• The IOMC in the OS is responsible for the


following activities in connections with the
I/O management:
• Controls the processes access to I/O
resources via drivers.
• Allows sharing and synchronizing of the I/O
resource.
• Provides a standard interface between
process (user's one or system’s one) and
I/O devices.
– File system (disk), sockets (network).
• Provides buffers for caching services.

• Manages the device’s driver code for


specific I/O devices.

• We will present the details of I/O management in the intensive introduction & you need to
read Ch.12.

Dr. Tarek Helmy, KFUPM-ICS 52


Network Management Component (NMC)

• The NMC is responsible for the following activities in


connections with the network management:
• Managing and administering the computer network.
• Network management comprises fault analysis,
maintaining the quality of service, provisioning of
networks, and performance management.
• Network management provides the facility of network
connection, whether it is fully or partially connected
network.
• It helps to design routing and connection strategies,
which helps in overcoming the issues of security and
connection.

• The details of NMC will be introduced in the network and distributed systems
Chapter19. (not covered in the undergraduate course.

Dr. Tarek Helmy, KFUPM-ICS 53


Mass-Storage Management Component (MSMC)

• Since main memory (primary storage) is volatile and not enough to


accommodate all data of concurrently running processes.
• So, the operating system uses a mass-storage memory to extend
(create VM) and to back up the main memory content.
• The OS uses (VM) as the principle on-line storage medium, for both
processes and data.
• We will present the details of Virtual Memory Management in Ch.9.

• The MSMC in the OS is responsible for the following activities in


connection with the disk/mass-storage management:
– Manages the free space available on the secondary-storage device.
– Allocates of storage space when new files have to be written.
– Schedules the read and write requests for mass-storage access.
• We will present the details of Mass-Storage Management in Ch.11.

Dr. Tarek Helmy, KFUPM-ICS 54


Command-Interpreter Component (CIC)

• Many commands are given to the OS either from keyboard (command-line


interface, CLI), or script files (i.e. Unix/Linux), or from GUIs through the mouse
(i.e. in Windows or Mac).
• These commands may deal with:
– Process creation and management
– I/O & Networking handling
– Mass-storage management
– Main-Memory management
– Editing and File-system access
• The CIC in the OS acts as interface where it allows users to enter commands
directly to be performed by the operating system as following.
• It accepts the commands, interprets, and dispatches these commands to the
corresponding OS modules then displays the result. The CIC may be called :
– GUI or Shell (any program that users use to interact with the OS)
– Control-Card Interpreter
– Command-Line Interpreter
• You need to practice them on different OSs by yourself in the Lab part .

Dr. Tarek Helmy, KFUPM-ICS 55


Command-Interpreter Component (CIC)

• Two different approaches to construct a command


interpreter.
• Approach 1(used by Windows):

• The command interpreter itself contains the code


to execute the commands by making appropriate
system calls.
• The number of supported commands determines
the size of the command interpreter.

• Approach 2 (used by Unix):


• Implements most commands through system programs.
• The command interpreter does not understand the
command in any way; it merely uses the command to
identify a file to be loaded into memory and executed.

Dr. Tarek Helmy, KFUPM-ICS 57


Command-Interpreter Component (CIC)

• Let’s look at an example using the Unix approach.

• Example: Use the command line to delete the file file.txt


$> rm file.txt
• Read command line ”rm file.txt” from the user.
• Parse the command line (split into the
command ”rm” and the parameter “file.txt”
• Search for a program file called rm.
• Execute the rm program with the parameter file.txt.
• NOTE:
• The function associated with the rm command would be defined
completely by the code in the file rm.
• In this way, programmers can add new command to the system
easily by creating new files with the proper names.
• The command-interpreter program, which can be small, does not
have to be changed for new commands to be added.

Dr. Tarek Helmy, KFUPM-ICS 58


Protection & Security Component (PSC)

• Since the OS supports multi-users with concurrent execution of multi-


processes, then these processes or users must be protected from one
another‘s.
– Protection refers to mechanisms for controlling the access of processes,
or users to the resources defined by a computer system (internal).
– Security refers to defense of the system against external attacks.
• The PSC is responsible of:
– Protecting processes' assigned resources (files, memory, etc.) from being
accessed by other processes
– Detecting any trial for intrusion
– Graceful recovery from errors detected by the hardware
• e.g. illegal instructions, divide-by-zero…
– Preventing malicious destruction or resources.
– Protects all system resources, i.e.
• CPU, see in the next slide how does the OS protect the CPU.
• Memory, see in the next slide how does the OS protect the memory.
• We will present the details of Protection & Security aspects in CHs.16&17.

Dr. Tarek Helmy, KFUPM-ICS 58


Example: CPU Protection

• Since the CPU is one of the golden/valuable/hot resources in the


computer system, the OS needs to prevent processes from hogging
the CPU for a long time. i.e.
– Getting into Infinite loops
– Waiting for non-exist resources
• The OS uses a timer to control process execution, so that when the
timer expires, the control switches back to the OS.
– Context switch
• This is the idea of CPU time-slicing
– Each process runs for a few msec.

P1 …, jmp, loadc, add,…


P2 …, sub, cmp, breq, jmp,… CPU
P3 …, store, mov, add, cmp,…
P1 is running
Dr. Tarek Helmy, KFUPM-ICS 59
Example: Memory Protection

• Since the Main Memory is one of the


golden/valuable/hot resources in the computer
system The OS needs to ensure that no process can
interfere with any other processes memory spaces,
i.e.
– Could overwrite other processes in memory
– Needs to protect the OS memory in particular
• Must provide memory protection at least for the
interrupt vector and the interrupt service routines.

• The OS uses two registers to determine the range of


legal addresses of each process.
– Base register: Holds the smallest legal physical
memory address for the process.
– Limit register: Contains the size of the process.

Dr. Tarek Helmy, KFUPM-ICS 60


Base & Limit Registers to protect a process’s memory

Address (supervisor mode)

Base Base+Limit

Memory
CPU >= <
Address Yes Yes
(user mode) No No
Trap to OS
(Addressing error)

Dr. Tarek Helmy, KFUPM-ICS 61


Storage Hierarchy in the Computer System
• In any computer system, the storage systems
are organized in hierarchy based on:
– Speed Volatile

Fast Expensive
– Cost
– Volatility
– Size
Memory

Slow Cheap
• CPU registers (index registers, ACC, etc.)
provides a high speed cache for CPU.

• Cache memory: Copying temporary


information into faster storage devices with Non
access time close to the CPU time. Volatile

• Main memory: Only the storage media that


the CPU can access directly.
• Main memory can be viewed as a last cache
for secondary storage.

• Secondary storage: Extension of main


memory that provides large nonvolatile
storage capacity.

Dr. Tarek Helmy, KFUPM-ICS 62


Caching and Consistency

• Caching
– Use of high-speed memory to hold recently-accessed data.
– Requires a cache management policy (cache size, replacement policy).
– Data that resides on the disk are copied into the main memory, then into the
cache and then into the CPU registers for processing.
– This requires data that is simultaneously stored in more than one level to be
consistent.
– Consistency: due to replication of data, this may lead to one copy being
different from the others. The OS must insure that all copies of the data will be
the same.
– This is not a big problem, in computing environment where only one process
executes at a time. The modification done on the CPU registers can be copied
back to the disk for a consistency purpose.
– In multiprocessing environment, extreme care must be taken by the OS so
that if several processes want to access A, then each should get the latest
value of A.

Dr. Tarek Helmy, KFUPM-ICS 63


Caching and Coherency

• Coherency: The OS needs to synchronize the data access in


multiple caches such that reading the data from any memory
location will return the most recent data.
• To ensure that each cache has a copy of the newest version when it
needs it.
• OS must ensure that an update of A’s value will be immediately
reflected in all other caches where A resides.
• Consistency leads to coherency but not the other way.

Dr. Tarek Helmy, KFUPM-ICS 64


The Problem of Cache Consistency

CPU CPU CPU

Cache Cache Cache

A’ 100 A’ 550 A’ 100

B’ 200 B’ 200 B’ 200

Memory Memory Memory

A 100 A 100 A 100

B 200 B 200 B 440

I/O I/O: Output of A gives 100 I/O: Input 440 to B


consistent is there where Inconsistent where Inconsistent where
Cache and memory are Cache and memory are Cache and memory are
the same. A’ = A, B’ = B. not the same. A’ != A. not the same. B’ != B.

Dr. Tarek Helmy, KFUPM-ICS 65


Dual-Mode Operation

• Two modes of operation are there in any operating system.


– User mode: the control of execution will be done by a user’ s program.
– Monitor mode (supervisor, or kernel mode): the control of execution will be
done by the OS.
• A Mode bit (a hardware bit) is used to indicate the current mode.
• The mode bit is reset/set to=0 for the Monitor/Kernel/Supervisor mode
• The mode bit is set to =1 for the User mode
• When an interrupt or a trap occurs, the control switches to monitor mode.
• All I/O instructions (privileged instructions) can be executed only in monitor
mode.
• The OS must ensure that a user program could never gain control of the
system in monitor mode.
In case of Interrupt/ Exception

Monitor User
Mode Mode

After serving the


Interrupt or Exception

Dr. Tarek Helmy, KFUPM-ICS 66


Privileged Instructions

• Some instructions are restricted to be


executed under the OS control, in the
monitor/supervisor mode.
– They are known as privileged instructions
• Since user’s program may issue illegal I/O
instructions: i.e.
– Write to a non-existence device
– Read more data than a disk holds
• User programs can only perform I/O by
requesting it through the OS.
• OS retains control over user’s programs to:
– Directly access I/O devices (disks, network
cards, etc.)
– Manipulate memory state management
• Page table pointers
– Manipulate special ‘mode bits’
• Interrupt priority level
– Halt instruction
Dr. Tarek Helmy, KFUPM-ICS 67
Interrupts and Exceptions

• Modern OSs are events-driven programs where events are either Interrupts or
Exceptions.
• Interrupts are used to handle events external to the processor, raised by
hardware devices or from the process to OS (system call) to get OS
attention. Interrupts are not visible to the user’s programs, e.g.:
• A device finishes I/O operation (keyboards, mouse, etc. ).
• Timer fires
• Exceptions or traps are used to handle events internal to the processor
(detected by the processor while executing the process), means caused by
software and it is visible to the user’s programs, e.g.:
• An exception e.g., “div. by zero”
• A page fault, “write to a read-only page”
• Asking to make arithmetic operation on non-numbers.
• The Interrupts transfer the control to the interrupt service routine, through the
interrupt vectors which contain the addresses of all the service routines.

Processor
Processor Interrupt
Exception

Dr. Tarek Helmy, KFUPM-ICS 68


Reasons of Interrupts/Exception

• Reasons for interrupts (or exceptions/traps) are:


– Control of asynchronous I/O devices
– Context switch between processes based on a CPU scheduling policy
– Exceptional conditions (e.g., illegal instruction) occurred during execution.
– System call: a user’s process requests for OS services.
– etc..
• The OS must save the address of the interrupted instruction.
• In single processor systems: Incoming interrupts are disabled while
another interrupt is being processed to prevent a lost of interrupt.
• In multi-processor systems: Disabling of interrupts is not enough
and some sort of synchronization is required.

Dr. Tarek Helmy, KFUPM-ICS 69


Interrupt Handling

• Serving an interrupt is known as “Interrupt Handling”.


• Different types of interrupts are handled by different interrupt service
routines of the OS.
• The OS maintains a table, known as Interrupt Vector, that contains
the starting addresses of the interrupt service routines.
• An integer is associated with each type of interrupt.
• When an interrupt occurs, the corresponding integer is supplied to the
OS usually by the hardware (in a register).
• The OS determines which service routine to be executed by mapping
the associated integer number to the Interrupt Vector.
• The OS saves the state of the executing process by storing
– CPU Registers (PC, Process Status Word, SP, Data Registers)
– Additional information about the current process and its state
• Execute the interrupt service routine.
• Upload the status of the process and resume its execution.

Dr. Tarek Helmy, KFUPM-ICS 70


Interrupt Handling Steps

1. The hardware device calls the OS at a pre-


specified location/register, Address of Int. A
Int. A?
2. The OS saves the state of the current
process, (contents of, registers: PC, SP,
Service
general-purpose registers) Routine for A
3. The OS identifies the device and the cause
of interrupt, Address of Int. C
Int. C?
4. Responds to the interrupt by executing the
Service
identified interrupt service routine, Routine for C
5. OS restores the state of the interrupted
process, Address of Int. Z
Int. Z?
6. Execute a Return-from-Interrupt (RTI) to
return to the interrupted process. Service
Routine for Z
• Key Fact: None of these actions are visible
to the user program.

Dr. Tarek Helmy, KFUPM-ICS 71


Exceptions/Traps Handling Steps

1. The running processes calls the OS at a pre-specified location.

2. The OS identifies the cause of the exception (e.g. divide by 0).

3. If the user’s process has an exception handling routine, then the OS


adjusts the user’s process state so that it calls its exception handler
routine.

4. If the user’s process does not have a specified handler, then the OS
suspends it and runs the OS’s exception handler routine.

5. Execute a Return-from-Interrupt (RTI) instruction and then return to


the user’s process.

• Key Fact: Effects of exceptions are visible to user’s processes and


causes abnormal execution flow.

Dr. Tarek Helmy, KFUPM-ICS 72


I/O Handling Methods/Modes: Ch. 12

• Synchronous/blocking: blocking the progress of a process while the I/O operation


is in progress, leaving system resources idle. This means that the CPU can spend
almost all of its time idle waiting for I/O operations to complete. How this is
done?
– Request is made to the I/O device,
– The CPU waits for the I/O device,
• Wait instruction idles (Looping) the CPU until the request is completed.
– At most, one I/O request is running at a time, no simultaneous I/O processing,

• Asynchronous/non-blocking: after requesting for an I/O operation, the control


returns to user’s process without waiting for the I/O request to be completed,
– Request is made to the I/O device,
– CPU records the request,
• Device-status table: contains entry for each I/O device indicating its type,
address, and state,
– The CPU continues the process execution, it can be a different one
– After completing of the I/O operation, the device interrupts the OS,
– The processor records that the request is done,
– It can resume the process execution.
Dr. Tarek Helmy, KFUPM-ICS 73
I/O Handling Methods: Ch. 12

Synchronous Asynchronous

These structures are


necessary to keep
track of IO in
progress.

Device-Status Table

Dr. Tarek Helmy, KFUPM-ICS 74


I/O Data Transfer Techniques: Ch. 12
• There are three techniques of managing data transfer between I/O devices and
the Main Memory.
• Programmed I/O (Polling)
– The CPU executes the I/O instructions written in program. Usually the
program controls data transfer to and from CPU and I/O device.
– Transferring data under programmed I/O requires constant Monitoring/Polling
of the I/O devices by the CPU. CPU checks by polling, reads and writes into
device buffers.
• Interrupt Driven I/O
– CPU asks devices to let it know when they are ready to transfer data.
– Device notifies CPU when I/O operation complete.
• Direct Memory Access (DMA, a memory controller)
– DMA is programmed by the OS to exchange data at high rate between main
memory and the I/O device.
– CPU asks DMA to perform the I/O directly to or from memory.
– DMA controller performs “I/O”, not CPU.
– CPU notified with DMA complete.
• The OS is responsible for choosing & managing the right technique for each
specific I/O in order to deliver the best overall performance.
Dr. Tarek Helmy, KFUPM-ICS 75
Programmed I/O: Polling

Programmed I/O (Polling): CPU Polls I/O Device’s Status


CPU sends read
Registers
request to device
• CPU executes I/O instructions and checks/polls in
turn each I/O channel or port to determine if it has Not ready
information for input or is ready to accept data for
output. CPU waits
for device
• I/O modules share the bus with the CPU.
• CPU has direct control over the I/O
– Sensing the status through flag register Ready
– Read/write commands CPU reads data
– Transferring data from device
• Polling is time consuming:
• CPU must swap between executing processes and
polls of each port. CPU writes data
• Wastes CPU time: Programmed I/O asks for too much to main memory
attention of the CPU if the device is fast.
• If the device is slow the CPU might have to wait a long
time (most devices are slow compared to modern No
Done?
CPUs).
• The CPU is also involved as a middleman for the Yes
actual data transfer.

Dr. Tarek Helmy, KFUPM-ICS 76


Interrupt-Driven I/O

• In the programmed I/O method the CPU CPU sends read


stays in the program loop until the I/O unit request to device
indicates that it is ready for data transfer.
• This is time consuming process because it CPU does other stuff
keeps the processor busy needlessly. ...
• This problem can be overcome by CPU receives interrupt
using interrupt Driven I/O.
• The CPU sets up I/O operation and
CPU reads data
continues its work, from device
• The device performs the I/O (long time),
• If the device completes, it interrupts the CPU writes data
CPU, to main memory
• Then the CPU responds to the interrupt
and transfers the data, No
• Continue once I/O is complete, Done?

• Interrupts save overhead of polling the I/O Yes


resources by the CPU.

Dr. Tarek Helmy, KFUPM-ICS 77


Direct Memory Access

• Fast I/O devices (graphics cards, network cards and sound cards,
etc.) use Direct Memory Access (DMA), why?
CPU sends read
• DMA permits the I/O device to transfer data directly to or from request to DMA
main memory without having each byte handled by the CPU. unit

– DMA controller moves data between device and memory then


sends interrupt to CPU only when transfer is complete. CPU does other stuff
1. CPU only initiates operation ...
2. DMA controller transfers data directly to/from main memory
3. Interrupt when transfer completed CPU receives DMA
interrupt
• DMA enables more efficient use of interrupts, increases data
throughput, and potentially reduces hardware costs by eliminating
the need for specific FIFO buffers for every resource.

Dr. Tarek Helmy, KFUPM-ICS 78


DMA: The best Data Transfer Mode

• The DMA mode of data transfer reduces CPU's

overhead in handling I/O operations.

• It also allows parallelism in CPU and I/O operations.

• Such parallelism is necessary to avoid wastage of

valuable CPU time while handling I/O devices whose

speeds are much slower as compared to CPU.

Dr. Tarek Helmy, KFUPM-ICS 79


Three Techniques for I/O

Dr. Tarek Helmy, KFUPM-ICS 80


System Calls

• System calls provide an interface to the services made available by an


operating system.
• These system calls
System and Application Programs
are generally
available as System
Programs written in
GUI batch command line
C and C++.
user Interfaces
• Is C/C++ enough to
system calls implement system
calls?

program I/O resource
execution operations
communication
allocation
accounting
Certain low level
helpful for the user Operating ensuring the efficient operation
tasks (i.e., tasks
error
System
Pprotection
where hardware
File System Services
detection and security
must be accessed
directly), may need
to be written using
Computer Hardware
assembly-language
instructions.

Dr. Tarek Helmy, KFUPM-ICS 81


System Calls

• System calls allow user’s processes to request some services from the
operating system which the process itself is not allowed to do.
• A System call: Provides a "direct access" to OS services (e.g., file system,
I/O routines, memory allocate & free routines) by user’s processes.
• System calls in fact, are treated as a special case of interrupts.
• Programs that make system calls called "system programs“.
• System calls accessed by system programs via Application Program
Interface (API).
• Three most common APIs are Win32 API for Windows, POSIX API UNIX,
Linux, Mac OS X, and Java API for the Java Virtual Machine (JVM).

Dr. Tarek Helmy, KFUPM-ICS 82


Application Programming Interfaces

• The API specifies a set of functions that are available to an application


programmer, including the parameters that are passed to each function
and the return values the programmer can expect.

• Three of the most common APIs:

• Win32 API for Windows systems.

• The Portable Operating System Interface for Unix


(POSIX) API for Unix like systems.

• The Java API for designing programs that run on the


Java virtual machine.

Dr. Tarek Helmy, KFUPM-ICS 84


Example of System Calls

• System calls sequence to copy the contents of one file to another file.

OSs execute
Even simple thousands of
programs may system calls per
make heavy second.
use of the OS.

Dr. Tarek Helmy, KFUPM-ICS 84


Types of System Calls: Windows & Unix

Dr. Tarek Helmy, KFUPM-ICS 85


API – System Call – OS Relationship

User Process User Mode


open(); // invoking the open() system call
// Returns after system call mode bit = 1

System Call Interface

Kernel Mode

mode bit = 0
System Calls
Number Pointer
open()
• Implementation of The system call
interface
• A number is
the open() system
intercepts function
call.
• associated . calls in the API
i . and invokes the
with each necessary system
.
• system call. calls made
• return available within
the operating
• system.

Dr. Tarek Helmy, KFUPM-ICS 86


Handling a System Call

– User’s process makes a system call by executing a


system call privileged instruction. Address of SR 1
SC 1?
 Hardware resets the mode-bit to 0 and switches to
kernel mode.
Service
 OS saves the state of the user’s process. Routine 1
 OS identifies the system call (branch to case
Address of SR 2
statement in system code). SC 2?

 Switch to a service routine based on the Service


Routine 2
associated system call number.
 OS executes the service routine. Address of SR 3
 OS restores the state of the user’s process by SC 3?
loading its parameters from [PCB].
Service
 Switches to the user mode by setting the mode bit. Routine 3

 Resume executing the user’s process.

Dr. Tarek Helmy, KFUPM-ICS 87


System Programs

• The system programs are a set of utility programs help the process to issue a
system call requesting services.
• System programs were traditionally coded in assembly language but currently
written by C, C++, and Java Programming languages.
• Example of System Program:
• File management: Create, delete, copy, rename, print, dump, list, and
generally manipulate files and directories.
• Status information: Asks the system for info. i.e. date, time, amount of
available memory, disk space, number of users
• File Processing: Text editors to create, modify and search contents of files.
• Programming-language support: Compilers, assemblers, debuggers and
interpreters.
• Program loading and execution: Absolute loaders, linkage editors, and
overlay-loaders, debugging systems for higher-level and machine language
• Communications - Provide the mechanism for creating virtual connections
among processes, users, and computer systems (http, ftp, telnet, …)
– Allow users to send messages to one another’s, browse web pages, send
electronic-mail messages, log in remotely, files transfer.

Dr. Tarek Helmy, KFUPM-ICS 88


Passing System Call Parameters to the OS

• Three methods are used to pass system call parameters to the OS:-

1. System call parameters stored in registers

• In some cases, may be more parameters than registers

2. System call parameters stored in a block, or table, in memory,


and address of the block passed as a parameter in a register

• This approach taken by Linux and Solaris

3. System call parameters placed, or pushed, onto the stack by


the process and popped off by the OS.

Dr. Tarek Helmy, KFUPM-ICS 89


Parameter Passing via Table

The methods to pass parameters between a running program and the OS.

Dr. Tarek Helmy, KFUPM-ICS 83


Example of Standard API

• Consider the ReadFile() system call in the Win32 API for reading from a file

• A description of the parameters passed to ReadFile()


– HANDLE file—the file to be read
– LPVOID buffer—a buffer where the data will be read into and written from
– DWORD bytesToRead—the number of bytes to be read into the buffer
– LPDWORD bytesRead—the number of bytes read during the last read
– LPOVERLAPPED ovl—indicates if overlapped I/O is being used

• What is the reasonable way of passing these parameters to the OS?

Dr. Tarek Helmy, KFUPM-ICS 84


Processes Communication Methods

• Processes communicate with each other using direct message


passing by sending/receiving messages through the OS kernel, or
through shared memory .

Message Passing Shared Memory

Dr. Tarek Helmy, KFUPM-ICS 92


Message passing vs Shared Memory

Message-Passing Shared-Memory
• Messages can be exchanged • Processes can communicate
between processes either directly or by reading and writning to
indirectly using a common mailbox. shared memory.

Pros & Cons of the two approaches?

• Message-passing is useful for • Shared memory allows maximum


exchanging smaller amounts of speed and convenience of
data, because no conflicts need be communication, since it can be
avoided. done at memory transfer speeds.

• It is also easier to implement • Problems: protection and


compared to the shared memory synchronization between the
approach. processes sharing memory.

Dr. Tarek Helmy, KFUPM-ICS 93


Outline of OS Intensive Introduction Classes

• We have presented till now:


• Definitions of the OSs, Benefits of the OS to users and application programs,
• Computer-System Organization and Operation, Different types of OSs, the Major OS Issues,
Operating System Services, Different views of the OS,
• Main Goals of OS, Supporting of Multi-processing by OS: why?
• Requirements of Multi-processing (HW and SW support), Multiprocessor Systems (Tightly and
loosely coupled, symmetric and asymmetric mode of coupling),
• Distributed vs. Network OSs, Clustered systems, and why do we support clustering?
• Computing models: Client-server, P2P, Grid-computing, Cloud-Computing,
• Fundamental components of the OS; i.e. Process Management, Memory Management, File
Management, I/O Management, Mass-Storage Management, Command-Interpreter, Protection &
Security components. Protecting CPU and Memory as hot resources,
• Memory Storage Hierarchy, Consistency and Coherency Definitions and Support by the OS,
Dual-Mode Operation of the OS, Privileged Instructions, Interrupts and Exceptions Definitions.
Reasons of Interrupts/Exception, Interrupts and Exceptions Handling.
• I/O Handling Methods (Synchronous/blocking and Asynchronous/non-blocking)
• I/O Data Transfer Techniques (Polling, Interrupt, Direct Memory Access)
• System Calls, System Programs, and how to handle a system call?
• Passing System Call Parameters to the OS, and Processes Communication Methods.
• We are going to present:
• Operating System Design Issues, Operating System Design Goals.
• Different ways of structuring the operating systems.
• Operating System Implementation, and System Generation (SYSGEN).

Dr. Tarek Helmy, KFUPM-ICS 94


Operating System Design Issues

• As we have seen, the OS consists of many components/unites/modules,


so the OS’s designers need to think about:
– How do we organize all of the components/units/modules?
– Where do they exist?
– How do they cooperate together?
• Answering these questions is a massive software engineering and
design issues.
• What are the important software characteristics of an OS the designer
should care?
– Correctness, simplicity, and completeness,
– Efficient performance,
– Scalability and portability,
– Suitability for distributed and parallel systems,
– Compatibility with existing systems,
– Security and fault tolerance,
– .. etc.

Dr. Tarek Helmy, KFUPM-ICS 95


More Design Issues

• Flexibility
– It should be easy to add and remove functional modules from the operating
system. This is the idea of microkernel operating system. In a microkernel
operating system, it provides minimal services:
• Inter-Process communications (IPC)
• Some memory management
• A limited amount of low-level process management and scheduling.
• Low-level input/output.
– These basic services are provided in kernel just because it is too expensive
to provide them anywhere else.
• Reliability
– With distributed system, it is possible to provide higher reliability because
some nodes can perform functions for the failed nodes.

• Performance
– With distributed systems, one expects better performance.

• Scalability
– The system design should be able to expand to large number of
processors, not just a few.

Dr. Tarek Helmy, KFUPM-ICS 96


OS Design Goals

 The OS is a kind of SW package and has to pass the Software


Development Life Cycle, i.e. Requirements, Design, Implementation,
Integration, Deployment and Maintenance phases.
• The OS design will be affected by the choice of the HW and the type of the
system (Batch OS, Time shared OS, Single user OS, Multi-user OS, Real
time OS, Distributed OS, or what?).
• The first problem in designing the system is to define the goals and
specification of the system.

• User’s goals: OS should be convenient to use, easy to learn, reliable, safe,


multi-purpose, and fast.

• System’s goals: OS should be easy to design, implement, and maintain, as


well as flexible, reliable, error-free, and efficient.
• Next, we will present different ways of structuring the operating systems.

Dr. Tarek Helmy, KFUPM-ICS 97


Monolithic-Based of OS Structure: i.e. Unix

• All OS functions are combined into the kernel.


• Kernel: Everything below the system-call interface and above the physical
hardware.
– Provides file system, CPU scheduling, memory management, and other
OS functions through system calls.
• The monolithic approach defines a high-level virtual interface over the
hardware, with a set of primitives or system calls to implement OS services.
• Traditional UNIX OS versions were built as a monolithic kernel.
• This monolithic structure was difficult to implement and maintain.

Dr. Tarek Helmy, KFUPM-ICS 98


Monolithic-Based OS Kernels

• Major advantage:
– Cost of module interactions is low (procedure/function/method call)

• Disadvantages:
– Hard to understand,

– Hard to modify or to maintain,

– Unreliable (no isolation between system modules)

• What is the alternative?


– Can we moves some components from the kernel into “user” space to
simplify its design and implementation?

Dr. Tarek Helmy, KFUPM-ICS 99


Microkernel-Based OS Structure

• Moves as much as possible from the kernel into “user” space


• Communication takes place between user’s modules using message passing
– Provides only small number of services
• Attempt to keep kernel small and scalable
– High degree of modularity
• Extensible, portable and scalable
– Increased level of inter-module communication
• Can degrade system performance
• Mac and BSD (Berkeley Standard Distribution) OSs are examples.

Dr. Tarek Helmy, KFUPM-ICS 10


Microkernel-Based OS Structure

• Benefits:
– Easier to extend a microkernel,
– Easier to port the operating system to new architectures,
– More reliable (less code is running in kernel mode),
• Disadvantages:
– Performance overhead of user space to kernel space communication.

Mac OS X Structure

• Can we organize the OS into layers in order to simplify its design and implementation?

Dr. Tarek Helmy, KFUPM-ICS 10


Layering-Based OS Structure

• The layering approach means:


– Implement the OS components as a set of layers,
– All the layers can be defined separately and interact with each other as required,
– A typical layer M consists of a set of data structures and routines that can be
invoked by higher-level layers.
– Layer M can invoke operations on lower-level layers.
– Each layer acts as a ‘virtual machine’ to the layer above.
• Layered Systems
– Layer 1: Responsible for the multiprocessing aspect of the operating system. It
decides which process to be allocated to the CPU (Scheduling). It deals with
interrupts and performs the context switches when a process change is required.

Dr. Tarek Helmy, KFUPM-ICS 10


Layering-Based OS Structure

– Layer 2: Concerns with allocating memory to processes.

– Layer 3: Deals with inter-process communication and


communication between the OS and the console.

– Layer 4: Manages all I/O between the devices attached to


the computer. This includes buffering information from the
various devices.

– Layer 5: Where the user programs store.

– Layer 6: Where the overall control of the system (called


the system operator).

Dr. Tarek Helmy, KFUPM-ICS 10


Layering Advantages and Disadvantages

• Advantages:
– Each layer can be tested and verified independently,
– Layering eases maintenance, developing, and updating of
system,
– Explicit structure allows identification, relationship of complex
system’s pieces.
• Disadvantages:
• Disjunction between modularity and reality
– Systems modeled as layers, but not really built that way.
• Strict layering isn’t flexible enough
– A layer can communicate only with the lower layer.
• Poor performance
– Each layer crossing has overhead associated with it.

Dr. Tarek Helmy, KFUPM-ICS 10


Modules-Based OS Structure

• A modular operating system is built with its various functions broken up into
distinct processes, each with its own interface.
• Most modern operating systems implement the kernel as modules
– Uses object-oriented approach,
– kernel does not have to implement message passing since
modules/Functions are free to contact each other directly.
– Each core component is separate,
– Each talks to the others over known interfaces,
– Each is loadable as needed within the kernel,
• Overall, similar to layers but with more flexibility

Solaris Modular Approach


Dr. Tarek Helmy, KFUPM-ICS 10
OS Design to support Virtual Machines

• Creating software copies of the processor (the capability to execute


instructions) and the memory (the capability to store information), each
constitutes a Virtual Computer (VC).
• The resources of the physical machine are shared. Virtual devices are sliced
out of the physical ones. Virtual disks are subsets of physical ones.
• Useful for running different OS on the same machine.
• To provide an interface or resource that differs from that of the lower levels.
• Primarily used for cross OS compatibility (portability of code), i.e. Java VM.
• Protection is excellent, but no sharing possible.

Dr. Tarek Helmy, KFUPM-ICS 10


Java Virtual Machine: Example

Java Virtual Machine:


• Mediates between the application and the underlying platform:
• Converts the application’s byte code into machine-level code.
• Handles tasks such as managing the system memory, providing security
against malicious code, and managing multiple threads of program
execution.
• Thus: Compiled Java programs are platform-independent, byte-codes
executed by a Java Virtual Machine (JVM).

• The Java Virtual


Machine allows
Java code to be
portable between
various hardware
and OS
platforms.

Dr. Tarek Helmy, KFUPM-ICS 99


Advantages/Disadvantages of Virtual Machines

Advantages:
• The virtual-machine concept provides complete protection of
system resources since each virtual machine is isolated from all
other virtual machines.

Disadvantage:
• The isolation, however, permits no direct sharing of resources
which is against sharing of the resources to maximize their
utilization.
• The virtual machine concept is difficult to implement due to the
effort required to provide an exact duplicate to the underlying
machine.

Dr. Tarek Helmy, KFUPM-ICS 108


System Implementation

• Traditionally OSs have been written in assembly language and that


means it is available only for that processor’s family.
• Modern OS are often written in Higher-Level Languages such as C, C++,
Java.
• i.e. Unix is written in C and it is available on a different CPUs.
• The advantages of using HLL in writing the OSs are:
– Can be written faster.
– Is more compact.
– Is easier to understand and debug.
– An OS is far easier to port (move to some other hardware) if it is
written in a portable high-level language.
• The major disadvantages are:
– Reduced speed and increased storage requirements.

• In many OSs the critical modules (CPU scheduling, memory


management) can be written in assembly to improve the performance of
the OS.
Dr. Tarek Helmy, KFUPM-ICS 109
System Generation (SYSGEN) Module

• Since the OS is designed to run on any machine; the OS must be configured for each
computer, this process is known as system generation.
• Sysgen is the process of creating a particular unique instance of an OS by combining
user-specified options and parameters with manufacturer-supplied general-purpose
program code to produce an OS tailored for a particular hardware and software
environment.
• SYSGEN Module obtains information concerning the specific configuration of the
hardware system, it may ask the system operator to define the HW or probes the HW
directly. SYSGEN must determine:
– What type of the CPU? Type of instruction set, floating point arithmetic, ..
– How much memory is available? Some OS will detect the amount of memory by
referencing the memory locations sequentially until getting into illegal address.
– What devices are available? The OS needs to know how to address each device,
the characteristic of the device, etc.
– Any newly connected HWs can be used through Plug and play feature.
• After the OS is generated, it must be available for the use by the HW through:
• Bootstrap program/BIOS: Code stored in ROM that is able to locate the kernel, to load
it into memory, and to start its execution.
• Booting: The procedure of starting a computer by loading the fundamental parts
(kernel) of the OS.

Dr. Tarek Helmy, KFUPM-ICS 110


At the End

• We’ve completed our intensive introduction of the OS.


• This was a satellite picture about the concepts and principles of the OS.
• From now, we’ll be at the ground level, looking at each component of the
OS in more details.
• We will conduct a quiz next week about the introductory classes of the
OS. Please prepare your self for that.
• Your references for the introductory sessions are:
– Lectures’ slides
– Text book chapters 1, 2 and parts of chapters 3 and I/O (Ch. 12).

Dr. Tarek Helmy, KFUPM-ICS 111


The End!!

Thank you

Any Questions?

Dr. Tarek Helmy, KFUPM-ICS 112

You might also like