# Operating System (CH 1)
# Operating System (CH 1)
Operating Systems
Introduction
Computer software can be divided roughly into two kinds:
1. System software:- which manages the operation of the computer itself.
Operating system
and users
games
Users
1-5 People, machines, other computers
Four Components of a Computer
System
1-6
Contd.
A computer system can be viewed as a system consisting of
a. User view
The user view of a computer system depends on the types
ways:
o Sequential sharing:- a resource is allocated for exclusive
resource use
OS control programs
Controls execution of programs to prevent errors and
1-12
Operating System Functions
Can be summarized into two broad functions:
1. Resource Management
Time management - CPU and disk transfer scheduling
Space management - main and secondary storage
allocation
Synchronization and deadlock handling - IPC, critical
section, coordination
Accounting and status information - resource usage
tracking
2. User Environment monitoring:- OS layer transforms
bare hardware machine into higher level abstractions
Execution environment - process management, file
manipulation, interrupt handling, I/O operations, language.
Error detection and handling
Protection and security
1-13
Fault tolerance and failure recovery
Examples of where you will find
OSs
1. Servers (Mainframe Computers):- specialized for
processing large volumes of requests for a given
service.
Generally has a large number of necessary resources.
firmware
Initializes all aspects of system
1-20
Caching
Important principle, performed at many levels in a
storage temporarily
Faster storage (cache) checked first to determine if
information is there
If it is, information used directly from the cache (fast)
1-22
Computer system structure
A computer system can be categorized into a number
cheaper to store those data on one disk and to have all the
processors share them than to have many computers with
local disks and many copies of the data.
iii. Increased Reliability.
Functions being distributed properly among several
processors, failure of one processor will not halt the system,
only slow it down.
If 10 processors are there and if one fails, then each of the
A.Asymmetric multiprocessors
Each processor is assigned a specific task. A master
clustered Systems
is a type of multi-CPU system
Have multiple CPUs to accomplish computational
work(like multiprocessor systems)
They are composed of two or more individual systems
coupled together(difference with multiprocessors)
They share storages and are closely liked via a LAN or
faster interconnect such as InfiniBand.
Provide high availability service(service will continue
1-27 even if one or more systems in the cluster fail)
structure(cont)
Clustering can be
a. asymmetric mode
─ One machine is in hot-stand-by mode, while
the other is running the application.
─ The HSM host machine does nothing but
actively monitors the server. If server fails,
the HSM become the active server.
b. Symmetric mode
─ Two or more hosts are running applications,
and are monitoring each other.
─ More efficient as it uses all of the available
hardware.
1-28
Operating System Structure
Multiprogramming needed for efficiency
Single user cannot keep CPU and I/O devices busy
at all times
Multiprogramming organizes jobs (code and data)
so CPU always has one to execute
A subset of total jobs in system is kept in memory
One job selected and run via job scheduling
When it has to wait (for I/O for example), OS
switches to another job.
Timesharing (multitasking) is logical
extension in which CPU switches jobs so
frequently that users can interact with each job
while it is running, creating interactive
computing
Response time should be < 1 second
1-29
OPERATING SYSTEM STRUCTURE(CONT)
1-30
Memory Layout for Multiprogrammed System
Processor
switches
from one
process
to an
other
when
ever an
I/O event
Figure :-4 processes
or Timer are loaded to memory
interrupt in Multiprogramming
occurs systems
1-31
Operating System Components
All OSs have similar core components
Shell(User level)
Kernel (core)
The shell exposes functions to users and
applications
Piece of software that provides an interface for users
using either command-line or graphical interface
Acts as an interface between the user and the kernel.
Normally reside on disks and are loaded into memory
when needed.
The kernel (nucleus) interacts with hardware devices
Allocates time & memory to programs and handles the
file store & communication in response to system calls
Reside in memory all the time and is the hub of the OS
1-32
Operating-System Operations
Modern OS are interrupt driven.
Software error or request creates exception
or trap
Division by zero or invalid memory access.
Other process problems include infinite loop,
processes modifying each other or the
operating system
Dual-mode operation allows OS to protect
itself and other system components
User mode and kernel mode
Mode bit provided by hardware
Provides ability to distinguish when system is
running user code or kernel code
Some instructions designated as privileged, only
executable in kernel mode
System call changes mode to kernel, return from
1-33 call resets it to user
During a transition from User to Kernel Mode an infinite
loop may occur.
To prevent infinite loop / process hogging resources a
Timer is used.how?
o Set interrupt after specific period
o Operating system decrements counter
o When counter zero generate an interrupt
o Set up before scheduling process to regain control or
terminate program that exceeds allotted time
A computer system executing tasks on behalf of a user
applications, the system is in user mode.
When a user application requests service from an OS(via
system call) it is in kernel mode.
At system boot time, the hardware starts in kernel mode. Then
the OS is loaded and starts execution of user applications in a
user mode.
System call provide the means for a user program to ask the
OS to perform tasks reserved for the OS on the user’s
1-34 programs behalf.
Operating system services
1-35
Operating System Services
Below are some of the main services of the operating system that
provides helpful functions to the user.
User interface - Almost all operating systems have a
user interface (UI)
Varies between Command-Line (CLI), Graphics User Interface (GUI),
Batch
Program execution - The system must be able to
load a program into memory and to run that program,
end execution, either normally or abnormally
(indicating error)
I/O operations - A running program may require I/O,
which may involve a file or an I/O device.
1-39
User Operating System Interface - GUI
1-41
Example of System Calls
System call sequence to copy the contents of one file to another file.
1-42
Example of Standard API
Consider the ReadFile() function in the
Win32 API—a function for reading from a file
1-46
Standard C Library Example
C program invoking printf() library call,
which calls write() system call
1-47
Example:-to make clear how a systems call works, consider
a read system call with signature as follows.
- read(fd,&buffer,nbytes);
A call from a C program might look like this;
- count=read(fd,&buffer,nbytes);
System calls are performed in a number of steps: - to see
the steps consider the read system call discussed above.
1-48
System Call Parameter Passing
Often, more information is required than simply
identity of desired system call
Exact type and amount of information vary
according to OS and call
Three general methods are used to pass parameters
between a running program and the operating system.
Simplest: pass the parameters in registers
In some cases, may be more parameters than
registers
Parameters stored in a block, or table, in memory,
and address of block passed as a parameter in a
register
This approach taken by Linux and Solaris
Parameters placed on stack:- parameters are
pushed onto the stack by the program and popped
off the stack by the operating system
Block and stack methods do not limit the number or
1-49 length of parameters being passed
Parameter Passing via Table
1-50
Types of System Calls
1-51
System Programs(cont)
debugging information
Typically, these programs format and print the output to
1-57
Operating System Structure
Modern operating systems are complex and
consists of different components.
These components of modern systems are
interconnected and melded to the kernel.
five different OS structures have been tried so
far.
The five designs are:
a. monolithic systems
b.layered systems
c. virtual machines
d.Microkernel’s and
e. modules
1-58
I. Monolithic Systems
written to provide the most functionality in the least space
Not divided into modules
It is a simple structure.
each of which can call any of the other ones whenever it needs
to.
When this technique is used, each procedure in the system
mode.
The basic discipline in layered OS design is that the routines of
one layer use only the facilities of the layer directly below it,
that is, no layer in the structure can be bypassed.
1-62
LAYERED APPROACH(CONT
LAYERED OPERATING
the Netherlands by E. W. Dijkstra and his students.
SYSTEM
1-63
LAYERED APPROACH(CONT)
The layered approach suffers from two problems:
1-67
Strengths/weakness of Virtual Machines
1-71
Practice Exercises
What are the three main purposes of an operating
system?
State the main advantage of multiprogramming?
What are the main differences between operating
systems for mainframe computers and personal
computers?
In a multiprogramming and time-sharing environment,
several users share the system simultaneously. This
situation can result in various security problems.
a. What are two such problems?
b. Can we ensure the same degree of security in a time-
shared machine as we have in a dedicated machine?
Explain your answer.
What are the differences between a trap and an
interrupt? What is the use of each function?
Give two reasons why caches are useful. What problems
do they solve? What problems do they cause? If a cache
can be made as large as the device for which it is
caching (for
instance, a cache as large as a disk), why not make it
1-72
that large and eliminate the device?
PRACTICE EXERCISES(CONT)
OPERATING SYSTEM
AND ITS STRUCTURES
1-74