Download as pdf or txt
Download as pdf or txt
You are on page 1of 77

Operating System

Chapter 1

Presented By:- Dr. Sanjeev Sharma


What is Operating system
• It is a control program that provides an interface between the
computer hardware and the user.
• Part of this interface includes tools and services for the user.
• From Silberschatz (page 3): “An operating system is a
program that acts as an intermediary between a user of
computer and computer hardware. The purpose of the OS is
provide an environment in which the user can execute
programs.
• The primary goal of an OS is thus to make the computer
convenient to use.
• A secondary goal is to use the computer hardware in an
efficient manner.”
Abstract view of the computer System
• Computer Hardware – CPU, memory, I/O devices provide
basic computing resources.
• System and Application Programs – Compilers, database
systems, games, business programs, etc. define the ways the
computing resources are used to solve the user’s problems.
• Operating System – Controls and coordinates the computing
resources among the system and application programs for the
users.
• End User – Views the computer system as a set of
applications. The End User is generally not concerned with
various details of the hardware.
• Programmer – Uses languages, utilities (frequently used
functions) and OS services (linkers, assemblers, etc.) to
develop applications instead. This method is used to reduce
complexity by abstracting the detail of machine dependant
calls into APIs and various utilities and OS services.

• OS – Masks the hardware details from the programmer and


provides an interface to the system. Manages the computers
resources. The OS designer has to be familiar with user
requirements and hardware details.
Functions of Operating System

• Memory Management
• Processor Management
• Device Management
• File Management
• Security
• Control over system performance
• Job accounting
• Error detecting aids
• Coordination between other software and users
• Memory management refers to management of Primary
Memory or Main Memory.
• Main memory is a large array of words or bytes where each
word or byte has its own address.
• Main memory provides a fast storage that can be accessed
directly by the CPU.
• For a program to be executed, it must in the main memory.
• An Operating System does the following activities for memory
management:
– Keeps tracks of primary memory, i.e., what part of it are in use
by whom, what parts are not in use?
– In multiprogramming, the OS decides which process will get
memory when and how much.
– Allocates the memory when a process requests it to do so.
– De-allocates the memory when a process no longer needs it or
has been terminated.
Processor Management

• In multiprogramming environment, the OS decides which


process gets the processor when and for how much time. This
function is called process scheduling. An Operating System
does the following activities for processor management:
– Keeps tracks of processor and status of process. The program
responsible for this task is known as traffic controller.
– Allocates the processor (CPU) to a process.
– De-allocates processor when a process is no longer required
Device Management
• An Operating System manages device communication via their
respective drivers. It does the following activities for device
management:
– Keeps tracks of all devices. The program responsible for this
task is known as the I/O controller.
– Decides which process gets the device when and for how much
time.
– Allocates the device in the most efficient way.
– De-allocates devices.
File Management
• A file system is normally organized into directories for easy
navigation and usage. These directories may contain files and
other directions.
• An Operating System does the following activities for file
management:
– Keeps track of information, location, uses, status etc. The
collective facilities are often known as file system.
– Decides who gets the resources.
– Allocates the resources.
– De-allocates the resources.
Other Important Activities
• Security - By means of password and similar other techniques,
it prevents unauthorized access to programs and data.
• Control over system performance - Recording delays
between request for a service and response from the system.
• Job accounting -- Keeping track of time and resources used
by various jobs and users.
• Error detecting aids - Production of dumps, traces, error
messages, and other debugging and error detecting aids.
• Coordination between other software and users -
Coordination and assignment of compilers, interpreters,
assemblers and other software to the various users of the
computer systems.
Operating system Evolution
• Let’s see how operating systems evolve over time.
• This will help us to identify some common features of
operating systems and how and why these systems have been
developed as they are.
• Early Systems (1950)
• Simple Batch Systems (1960)
• Multiprogrammed Batch Systems (1970)
• Time-Sharing and Real-Time Systems (1970)
• Personal/Desktop Systems (1980)
• Multiprocessor Systems (1980)
• Networked/Distributed Systems (1980)
Early System
• Structure
– Single user system.
– Large machines run from console.
– Programmer/User as operator.
– Paper Tape or Punched cards.
– No tapes/disks in computer.

• Significant amount of setup time.


• Low CPU utilization.
• But very secure
Batch Operating System
• The users of a batch operating system do not interact with the
computer directly. Each user prepares his job on an off-line
device like punch cards and submits it to the computer
operator. To speed up processing, jobs with similar needs are
batched together and run as a group. The programmers leave
their programs with the operator and the operator then sorts the
programs with similar requirements into batches.
• The problems with Batch Systems are as follows:
– Lack of interaction between the user and the job.
– CPU is often idle, because the speed of the mechanical I/O
devices is slower than the CPU.
– Difficult to provide the desired priority.
• Here First the pooled jobs are read and executed by the batch
monitor, and then these jobs are grouped; placing the identical
jobs (jobs with the similar needs) in the same batch, So, in the
batch processing system, the batched jobs were executed
automatically one after another saving its time by performing
the activities (like loading of compiler) only for once. It
resulted in improved system utilization due to reduced turn
around time.
• The operating systems (called resident monitor) manages the
execution of each program in the batch.
– Monitor utilities are loaded when needed.
– Resident monitor is always in main memory and available for
execution.
– The resident monitor usually has the following part.
• Control card interpreter – responsible for reading and
carrying out instructions on the cards.
• Loader – loads systems programs and applications
programs into memory.
• Device drivers – know special characteristics and
properties for each of the system’s I/O devices.
• One big problem associate with these OS is CPU was often
idle.
• To over come this spooling can be used.
• Uniprogramming Until Now
– I/O operations are exceedingly slow (compared to instruction
execution).
– A program containing even a very small number of I/O
operations will spend most of its time waiting for them.
– Hence: poor CPU usage when only one program is present in
memory.
Memory model for uniprogramming
Multiprogrammed Batch Systems

• Several jobs are kept in main memory at the same time, and
the CPU is multiplexed among them.
• If memory can hold several programs, then CPU can switch to
another one whenever a program is waiting for an I/O to
complete – This is multiprogramming.
Time-sharing Operating Systems

• Time-sharing is a technique which enables many people,


located at various terminals, to use a particular computer
system at the same time.
• Time-sharing or multitasking is a logical extension of
multiprogramming.
• Processor's time which is shared among multiple users
simultaneously is termed as time-sharing.
• The main difference between Multiprogrammed Batch
Systems and Time-Sharing Systems is that in case of
Multiprogrammed batch systems, the objective is to maximize
processor use, whereas in Time-Sharing Systems, the objective
is to minimize response time.
• Multiple jobs are executed by the CPU by switching between
them, but the switches occur so frequently. Thus, the user can
receive an immediate response. For example, in a transaction
processing, the processor executes each user program in a
short burst or quantum of computation. That is, if n users are
present, then each user can get a time quantum. When the user
submits the command, the response time is in few seconds at
most.
• Advantages of Timesharing operating systems are as follows:
– Provides the advantage of quick response
– Avoids duplication of software
– Reduces CPU idle time

• Disadvantages of Time-sharing operating systems are as


follows:
– Problem of reliability
– Question of security and integrity of user programs and data
– Problem of data communication
Distributed Operating System

• Distribute the computation among several physically separated


processors.
• Loosely coupled system – each processor has its own local
memory; processors communicate with one another through
various communications lines, such as high-speed buses or
telephone lines.
• These processors are referred as sites, nodes, computers, and
so on.
• The advantages of distributed systems are as follows:
– With resource sharing facility, a user at one site may be able to
use the resources available at another.
– Speedup the exchange of data with one another via electronic
mail.
– If one site fails in a distributed system, the remaining sites can
potentially continue operating.
– Better service to the customers.
– Reduction of the load on the host computer.
– Reduction of delays in data processing.
Network Operating System

• A Network Operating System runs on a server and provides


the server the capability to manage data, users, groups,
security, applications, and other networking functions. The
primary purpose of the network operating system is to allow
shared file and printer access among multiple computers in a
network, typically a local area network (LAN), a private
network or to other networks.

• Examples of network operating systems include Microsoft
Windows Server 2003, Microsoft Windows Server 2008,
UNIX, Linux, Mac OS X, Novell NetWare
• The advantages of network operating systems are as follows:
– Centralized servers are highly stable.
– Security is server managed.
– Upgrades to new technologies and hardware can be easily
integrated into the system.
– Remote access to servers is possible from different locations and
types of systems.

• The disadvantages of network operating systems are as follows:


– High cost of buying and running a server.
– Dependency on a central location for most operations.
– Regular maintenance and updates are required.
Real-Time Operating System

• A real-time system is defined as a data processing system in which the time


interval required to process and respond to inputs is so small that it controls
the environment. The time taken by the system to respond to an input and
display of required updated information is termed as the response time. So
in this method, the response time is very less as compared to online
processing.

• Real-time systems are used when there are rigid time requirements on the
operation of a processor or the flow of data and real-time systems can be
used as a control device in a dedicated application. A real-time operating
system must have well-defined, fixed time constraints, otherwise the
system will fail. For example, Scientific experiments, medical imaging
systems, industrial control systems, weapon systems, robots, air traffic
control systems, etc.
• There are two types of real-time operating systems.
• Hard real-time systems
Hard real-time systems guarantee that critical tasks complete on time. In
hard real-time systems, secondary storage is limited or missing and the data
is stored in ROM. In these systems, virtual memory is almost never found.

• Soft real-time systems


• Soft real-time systems are less restrictive. A critical real-time task gets
priority over other tasks and retains the priority until it completes. Soft real-
time systems have limited utility than hard real-time systems. For example,
multimedia, virtual reality, Advanced Scientific Projects like undersea
exploration and planetary rovers, etc.
Operating system services
• An Operating System supplies different kinds of services to both the
users and to the programs as well.
• Here is a list of common services offered by an almost all operating
systems:
– User Interface
– Program Execution
– File system manipulation
– Input / output Operations
– Communication
– Resource Allocation
– Error Detection
– Accounting
– Security and protection
• User Interface of Operating System
• Usually Operating system comes in three forms or types.
Depending on the interface their types have been further sub
divided. These are:
– Command line interface:- which uses text commands and a
method for entering them.
– Batch based interface:- In which the command and directive to
control those command are entered into files.
– Graphical User Interface:- pointing device to direct I/O.
• Program Execution in Operating System
The operating system must have the capability to load a program
into memory and execute that program. Furthermore, the program
must be able to end its execution, either normally or abnormally /
forcefully.

• File System Manipulation in Operating System


Programs need has to be read and then write them as files and
directories. File handling portion of operating system also allows
users to create and delete files by specific name along with
extension, search for a given file and / or list file information. Some
programs comprise of permissions management for allowing or
denying access to files or directories based on file ownership.
• I/O operations in Operating System
• A program which is currently executing may require I/O, which may
involve file or other I/O device. For efficiency and protection, users cannot
directly govern the I/O devices. So, the OS provide a means to do I/O Input
/ Output operation which means read or write operation with any file.

• Communication System of Operating System


• Process needs to swap over information with other process. Processes
executing on same computer system or on different computer systems can
communicate using operating system support. Communication between
two processes can be done using shared memory or via message passing.
• Resource Allocation of Operating System
• When multiple jobs running concurrently, resources must need to be
allocated to each of them. Resources can be CPU cycles, main memory
storage, file storage and I/O devices. CPU scheduling routines are used
here to establish how best the CPU can be used.

• Error Detection
• Errors may occur within CPU, memory hardware, I/O devices and in the
user program. For each type of error, the OS takes adequate action for
ensuring correct and consistent computing.
• Accounting
• This service of operating system keeps track of which users are using how
much and what kinds of computer resources has been used for accounting
or simply to accumulate usage statistics.

• Protection and Security


• Protection includes in ensuring all access to system resources in a
controlled manner. For making a system secure, the user needs to
authenticate him or her to the system before using (usually via login ID and
password).
• Mach was the first and most widely known microkernel, and now forms a
major component of Mac OSX.

• Windows NT was originally microkernel, but suffered from performance


problems relative to Windows 95. NT 4.0 improved performance by
moving more services into the kernel, and now XP is back to being more
monolithic.

• Another microkernel example is QNX, a real-time OS for embedded


systems.
Interrupt Processing

• An interrupt is a signal that causes the computer to alter its


normal flow of instruction execution.
• eg. divide by zero, time out, I/O operation

• The interrupt automatically transfers control to an interrupt


processing routine which takes some action in response to the
condition that caused the interrupt, and then control is returned
to the program at which its execution was interrupted.
Some interrupt types:

• - I/O interrupt: Generated by an I/O channel or device.



• - Program interrupt: Generated by some condition that occurs
during program execution (eg. divide by zero, illegal machine
instruction, etc.)

• - Timer interrupt: Generated by an internal timer within the
CPU

• - Supervisor call interrupt (SVC): A SVC instruction generates
an interrupt that transfers control to an OS service routine. The
CPU switches from user mode to supervisor mode.
• When an interrupt occurs, the status of the CPU is saved (registers,
program counter etc.) and the interrupt service routine is executed.
After the interrupt is processed, they are restored by the interrupt
routine and control is transferred to the program. Saving and
restoring the processor status is called context switching.

• Interrupt priority: During the processing of an interrupt, all


interrupts of equal or lower priority are inhibited, higher priority
interrupts are allowed. At the end of an interrupt, if there are more
than one interrupt pending, one with the highest priority is executed.

• Interrupt masking, is used to prevent certain interrupts from


occurring while the first one is being processed.
Operating System Operation
• Modern operating systems are interrupt driven.

• Events are almost always signaled by the occurrence of


interrupt or a trap.

• A trap (or an exception ) is a s/w generated interrupt. (divide


by zero)
• For each type of interrupt, separate segment of code in the OS
determine what action should be taken.
• An interrupt service routine is provided for that.
• A basic example of an ISR is a routine that handles keyboard events,
such as pressing or releasing a key. Each time a key is pressed, the
the ISR processes the input.

• For example, if you press and hold the right arrow key in a text file,
the ISR will signal to the CPU that the right arrow key is depressed.
The CPU sends this information to the active word processor or text
editing program, which will move the cursor to the right.

• When you let go of the key, the ISR handles the "key up" event. This
interrupts the previous "key down" state, which signals to the
program to stop moving the cursor.
Dual mode operation

• Dual-mode operation allows OS to protect itself and other system


components
– User mode (1) and kernel mode (0)
– 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 call resets it to user
• Timer to prevent infinite loop / process hogging resources
– Set interrupt after specific period
– Operating system decrements counter
– When counter zero generate an interrupt
– Set up before scheduling process to regain control or terminate
program that exceeds allotted time
Distributing Computing
• A distributed system is a network of autonomous computers
that communicate with each other in order to achieve a goal.

• The computers in a distributed system are independent and do


not physically share memory or processors. They
communicate with each other using messages, pieces of
information transferred from one computer to another over a
network.

• Messages can communicate many things: computers can tell


other computers to execute a procedures with particular
arguments, they can send and receive packets of data, or send
signals that tell other computers to behave a certain way.
• Computers in a distributed system can have different roles.
• A computer's role depends on the goal of the system and the
computer's own hardware and software properties.
• There are two predominant ways of organizing computers in a
distributed system.
• The first is the client-server architecture, and the second is the
peer-to-peer architecture.
Client/Server Systems
• The client-server architecture is a way to dispense a service
from a central source.
• There is a single server that provides a service, and multiple
clients that communicate with the server to consume its
products.
• In this architecture, clients and servers have different jobs. The
server's job is to respond to service requests from clients,
while a client's job is to use the data provided in response in
order to perform some task.
• The concepts of client and server are powerful functional
abstractions.
• A server is simply a unit that provides a service, possibly to
multiple clients simultaneously, and a client is a unit that
consumes the service.
• The clients do not need to know the details of how the service
is provided, or how the data they are receiving is stored or
calculated, and the server does not need to know how the data
is going to be used.
• On the web, we think of clients and servers as being on
different machines, but even systems on a single machine can
have client/server architectures.
• For example, signals from input devices on a computer need to
be generally available to programs running on the computer.
The programs are clients, consuming mouse and keyboard
input data. The operating system's device drivers are the
servers, taking in physical signals and serving them up as
usable input.
• A drawback of client-server systems is that the server is a single point of
failure. It is the only component with the ability to dispense the service.
There can be any number of clients, which are interchangeable and can
come and go as necessary. If the server goes down, however, the system
stops working. Thus, the functional abstraction created by the client-server
architecture also makes it vulnerable to failure.

• Another drawback of client-server systems is that resources become scarce


if there are too many clients. Clients increase the demand on the system
without contributing any computing resources. Client-server systems
cannot shrink and grow with changing demand.
Peer-to-peer Systems
• The client-server model is appropriate for service-oriented
situations.
• However, there are other computational goals for which a more
equal division of labor is a better choice.
• The term peer-to-peer is used to describe distributed systems in
which labor is divided among all the components of the system.
• All the computers send and receive data, and they all contribute
some processing power and memory.
• As a distributed system increases in size, its capacity of
computational resources increases. In a peer-to-peer system, all
components of the system contribute some processing power and
memory to a distributed computation.
• Division of labor among all participants is the identifying
characteristic of a peer-to-peer system.
• This means that peers need to be able to communicate with
each other reliably.
• In order to make sure that messages reach their intended
destinations, peer-to-peer systems need to have an organized
network structure.
• The components in these systems cooperate to maintain
enough information about the locations of other components to
send messages to intended destinations.
• In some peer-to-peer systems, the job of maintaining the health
of the network is taken on by a set of specialized components.
• Such systems are not pure peer-to-peer systems, because they
have different types of components that serve different
functions.
• The components that support a peer-to-peer network act like
scaffolding: they help the network stay connected, they
maintain information about the locations of different
computers, and they help newcomers take their place within
their neighborhood.
• The most common applications of peer-to-peer systems are
data transfer and data storage.
• For data transfer, each computer in the system contributes to
send data over the network.
• If the destination computer is in a particular computer's
neighborhood, that computer helps send data along. For data
storage, the data set may be too large to fit on any single
computer, or too valuable to store on just a single computer.
Each computer stores a small portion of the data, and there
may be multiple copies of the same data spread over different
computers. When a computer fails, the data that was on it can
be restored from other copies and put back when a
replacement arrives.
Parallel Computing
• Computers get faster and faster every year.
• Despite this explosion in speed, computers aren't able to keep
up with the scale of data becoming available.
• In other words, for genetic data, computers are become less
and less able to cope with the scale of processing problems
each year, even though the computers themselves are getting
faster.
• To circumvent physical and mechanical constraints on
individual processor speed, manufacturers are turning to
another solution: multiple processors.
• If two, or three, or more processors are available, then many
programs can be executed more quickly. While one processor
is doing one aspect of some computation, others can work on
another. All of them can share the same data, but the work will
proceed in parallel.
• In order to be able to work together, multiple processors need
to be able to share information with each other. This is
accomplished using a shared-memory environment.
• The variables, objects, and data structures in that environment
are accessible to all the processes. The role of a processor in
computation is to carry out the evaluation and execution rules
of a programming language. In a shared memory model,
different processes may execute different statements, but any
statement can affect the shared environment.
The problem with share state
• Sharing state between multiple processes creates problems that
a single-process environments do not have. To understand
why, let us look the following simple calculation:
• x=5
• x = square(x)
• x=x+1
• These example shows that parallelizing code is not as easy as
dividing up the lines between multiple processors and having
them be executed. The order in which variables are read and
written matters.
• A tempting way to enforce correctness is to stipulate that no
two programs that modify shared data can run at the same
time.
Correctness in Parallel Computation
• Problems arise in parallel computation when one process
influences another during critical sections of a program.
These are sections of code that need to be executed as if they
were a single instruction, but are actually made up of smaller
statements.
• A program's execution is conducted as a series of atomic
hardware instructions, which are instructions that cannot be
broken in to smaller units or interrupted because of the design
of the processor. In order to behave correctly in concurrent
situations, the critical sections in a programs code need to be
have atomicity -- a guarantee that they will not be interrupted
by any other code.
• To enforce the atomicity of critical sections in a program's code
under concurrency , there need to be ways to force processes to
either serialize or synchronize with each other at important times.
Serialization means that only one process runs at a time -- that they
temporarily act as if they were being executed in serial.
Synchronization takes two forms.
• The first is mutual exclusion, processes taking turns to access a
variable, and the second is conditional synchronization, processes
waiting until a condition is satisfied (such as other processes having
finished their task) before continuing. This way, when one program
is about to enter a critical section, the other processes can wait until
it finishes, and then proceed safely.
Protecting Shared State: Locks and Semaphores

• Locks. Locks, also known as mutexes (short for mutual


exclusions), are shared objects that are commonly used to
signal that shared state is being read or modified. Different
programming languages implement locks in different ways,
but in Python, a process can try to acquire "ownership" of a
lock using the acquire() method, and then release() it some
time later when it is done using the shared variables. While a
lock is acquired by a process, any other process that tries to
perform the acquire() action will automatically be made to
wait until the lock becomes free. This way, only one process
can acquire a lock at a time.
• For a lock to protect a particular set of variables, all the
processes need to be programmed to follow a rule: no process
will access any of the shared variables unless it owns that
particular lock. In effect, all the processes need to "wrap" their
manipulation of the shared variables in acquire() and release()
statements for that lock.
• Semaphores. Semaphores are signals used to protect access to
limited resources. They are similar to locks, except that they
can be acquired multiple times up to a limit. They are like
elevators that can only carry a certain number of people. Once
the limit has been reached, a process must wait to use the
resource until another process releases the semaphore and it
can acquire it.
• For example, suppose there are many processes that need to
read data from a central database server. The server may crash
if too many processes access it at once, so it is a good idea to
limit the number of connections. If the database can only
support N=2 connections at once, we can set up a semaphore
with value N=2.

You might also like