Module 1 Bcs 303 New
Module 1 Bcs 303 New
MODULE-I
CHAPTER 1
INTRODUCTION
What Operating Systems Do?
An Operating System (OS) is system software that manages the computer hardware.
o It provides a basis for application programs and acts as an intermediary between the
computer users and the computer hardware.
o The purpose of an OS is to provide an environment in which the user can execute the
program in a convenient & efficient manner.
Operating system goals:
Make the computer system convenient to use. It hides the difficulty in
managing the hardware.
Use the computer hardware in an efficient manner
Provide and environment in which user can easily interface with computer.
It is a resource allocator.
Computer System Structure (Components of Computer System)
A computer system can be divided into four components
Hardware: The Hardware consists of memory, CPU, ALU, I/O devices, peripherals
devices & storage devices.
OS: The OS controls & co-ordinates the use of hardware among various application
programs for various users.
Application Program: The application programs includes word processors, spread
sheets, compilers & web browsers which defines the ways in which the resources are
used to solve the problems of the users.
User: Who works/executes the required function.
The following figure shows the abstract view of the components of a computer system
The basic hardware components comprise of CPU, memory, I/O devices. The
application program uses these components. The OS controls and co-ordinates the use
Views of OS
To completely understand the role of operating system two views are considered as below:
1. User View:
The user view of the computer depends on the interface used. Some users may use PC’s.
Such system is designed for one user. Here the OS is designed for ease of use where
some attention is mainly on performances and not on the resource utilization.
Some users may use a terminal connected to a mainframe or minicomputers. Other users
may access the same computer through other terminals. These users may share resources
and exchange information. In this case the OS is designed to maximize resource
utilization- so that all available CPU time, memory & I/O are used efficiently.
Other users may sit at workstations, connected to the networks of other workstation and
servers, then the user have a system unit of their own and shares resources and files with
other systems. In this case OS is designed to compromise between individual usability &
resource utilization.
Users of handheld systems expects the OS to be designed for ease of use and
performance per amount of battery life.
Other systems like embedded systems used in home devices (like washing m/c) &
automobiles do not have any user interaction. There are some LEDs to show the status of
its work.
2. System View:
An operating system can be viewed as resource allocator and control program.
A computer system has many resources such as CPU Time, memory space, file storage
space, I/O devices and so on that may be used to solve a problem.
The OS acts as a manager of these resources and decides how to allocate these resources
to programs and the users so that it can operate the computer system efficiently and
fairly.
A different view of an OS is that it controls various I/O devices & user programs i.e. an
OS is a control program which manages the execution of user programs to prevent
errors and improper use of the computer.
Computer System Organization
I/O Structure
A large portion of operating system code is dedicated to managing I/O, both
because of its importance to the reliability and performance of a system and because of
the varying nature of the devices.
Every device have a device controller, maintains some local buffer and a set of
special- purpose registers. The device controller is responsible for moving the data
between the peripheral devices. The operating systems have a device driver for each
device controller.
To start an I/O operation, the device driver loads the registers within the device
controller. The device controller, examines the contents of these registers to determine
what action to take (such as "read a character from the keyboard"). The controller starts
the transfer of data from the device to its local buffer. Once the transfer of data is
complete, the device controller informs the device driver(OS) via an interrupt that it has
finished its operation. The device driver then returns control to the operating system,
and also returns the data. For other operations, the device driver returns status
information.
This form of interrupt driven I/O is fine for moving small amounts of data, but
very difficult for bulk data movement. To solve this problem, direct memory access
(DMA) is used.
A system that has one main CPU and is capable of executing a general-purpose
instruction set, including instructions from the user processes.
Some systems also have special purpose processor to perform specific task, or on
mainframes, they come in the form of general purpose processors such as I/O
processor. These special purpose processors have limited instruction set and do not
run user processes. They are managed by the OS by sending information about the
next task and monitor their status.
Ex1: A disk controller microprocessor receives a sequence of requests from the
main CPU and implements its own disk queue and scheduling algorithm. This
relieves the main CPU from disk scheduling.
Ex2: PCs contain a microprocessor in the keyboard to convert the keystrokes into
codes to be sent to the CPU.
These special purpose processors do not convert single processor system into
multiprocessor system.
Multiprocessor Systems
Multiprocessor systems have more than one processor in close communication. Also
known as Tightly Coupled System or Parallel Systems.
They share computer bus, the clock, memory & peripheral devices.
Two processes can run in parallel.
Multi Processor Systems have 3 advantages,
o Increased Throughput: By increasing the number of processors we can get more
work done in less time. Speed up ratio with N processors is not N, but it is less
than N.
o Economy of Scale: As Multiprocessor systems share peripherals, mass storage &
power supplies, they can save more money than multiple single processor
systems. If many programs operate on same data, they will be stored on one disk
and all processors can share them instead of maintaining data on several systems.
o Increased Reliability: If a program is distributed properly on several processors,
then the failure of one processor will not halt the system but it only slows down.
The ability to continue providing service proportional to the level of surviving
hardware is called graceful degradation. Such systems that provide graceful
The differences between symmetric & asymmetric multiprocessing may be result from
either hardware or software. Special hardware can differentiate the multiple processors,
or the software can be written to allow only one master & multiple slaves.
A recent trend in CPU design is to include multiple compute cores on a single chip.
Blade Servers are recent development in which multiple processor boards, I/O boards,
and networking boards are placed in same chassis. Here each processors can boot
independently and run their own OS.
Clustered Systems
The clustered systems have multiple CPUs but they are composed of two or more
individual systems coupled together.
Clustered systems share storage and are closely linked via LAN Network.
Clustering is usually used to provide high availability.
A layer of software cluster runs on the cluster nodes. Each node can monitor one or
more of the others. If the monitored machine fails, the monitoring machine takes
ownership of its storage and restarts the applications that were running on failed
machine.
Clustered systems can be categorized into two groups
1. Asymmetric Clustering.
2. Symmetric clustering.
In asymmetric clustering one machine is in hot standby mode while others are
running the application. The hot standby machine does nothing but it monitors the
active server. If the server fails the hot standby machine becomes the active server.
In symmetric mode two or more hosts are running the application & they monitor
each other. This mode is more efficient since it uses all the available hardware.
Multiprogramming system
Single user cannot keep CPU and I/O devices busy at all times.
Multiprogramming increases CPU utilization by organizing jobs so that CPU always
has one to execute.
The OS has to keep several jobs in memory simultaneously as shown in below figure
shown below
Timesharing (multitasking)
Dual-mode operation
At system boot time, the hardware starts in kernel mode. The OS is then loaded and
starts user applications in user mode. Whenever a trap or interrupt occurs, the
hardware switches from user mode to kernel mode. Thus whenever the OS gains
control of the computer, it is in kernel mode. The system always switches to user
mode before passing control to user program.
The hardware allows privileged instructions to be executed only in kernel mode. If
an attempt is made to execute privileged instructions in user mode, the hardware does
not execute it but rather treats it as an illegal and traps it to the OS. Examples:
Instruction to switch to user mode, I/O control instructions, timer management
instructions and interrupt management instructions.
Timer
Timer is used to prevent a program from getting stuck in an infinite loop or not
calling system services and never returning control to the OS.
Timer can be set to interrupt the computer after a specific period.
The period may be fixed or variable. The variable timer is implemented by fixed
rate clock and a counter. Whenever the clock ticks, operating system decrements the
counter. When counter reaches zero it generates an interrupt.
Timer has to be set before scheduling process to regain control or terminate program
that exceeds allotted time.
Process Management
A process is a program in execution. Ex1. A time-shared user program like a
compiler is a process. Ex2. A word processing program run by an individual user on a
PC is a process.
A process requires certain resources like CPU time, Memory, I/O devices to
complete its task.
When the process terminates, the OS reclaims all the reusable resources.
A program in a file is stored on disk and is a passive entity, where as a process is an
active entitylocated on main memory.
A single threaded process has one PC (program counter) specifying the address of
the next instruction to be executed. Such processes are sequential i.e. the CPU
executes one instruction after the other.
A multi-threaded process has multiple program counters each pointing to the next
instruction to execute for a given thread.
A system consists of a collection of processes, some of which are OS processes and
the rest are user processes. All these processes can execute concurrently by
multiplexing the CPU among them on a single CPU.
The OS is responsible for the following activities of the process management,
o Creating & deleting of the user & system processes.
o Suspending and resuming processes.
o Providing mechanisms for process synchronization.
o Providing mechanisms for process communication.
o Providing mechanisms for deadlock handling.
Storage Management
Computer system must provide secondary storage toback up main memory because,
o It is too small to accommodate all data and programs.
o Data held in this memory is lost when power goes off.
Caching
Once the increment to A takes place in the internal registers, the value of A differs in
various storage systems. The value of A becomes same only after the new value of A
is written from the internal register back to the disk.
In multitasking environments, extreme care must be taken to use most recent value,
not matter where it is stored in the storage hierarchy.
The situation becomes more complicated in multiprocessor environment, where
each CPU is associated with local cache. A care must be taken to make sure that an
update to the value of A in one cache is immediately reflected in all other caches.
This situation is called as cache coherency.
The situation becomes even more complex in a distributed environment. Several
copies of the same file can be kept on different computers. Since the various replicas
may be accessed and updated concurrently, some distributed systems ensure that,
I/O Systems
Distributed Systems
A distributed system is a collection of physically separate heterogeneous computer
systems that are networked to provide the users with access to various resources that
the system maintains.
A distributed system is one in which Hardware or Software components located at the
networked computers communicate & coordinate their actions only by passing
messages.
The special purpose computers are those whose functions are more limited and whose objectives
are to deal with limited computation domains. Eg: Real time Embedded Systems, Multimedia
Systems and Handheld Systems.
Embedded computers are found almost everywhere from car engines, robots, alarm
systems, medical imaging systems, industrial control systems, microwave ovens,
weapon systems etc.
This class of computers have very specific task and run an OS with very limited
features. Usually they have limited or no user interface.
Embedded systems runs on real time OS.
A real time system should have well defined, fixed time constraints. Processing must
be done within the defined constraints or the system will fail.Hence they are often
used as controlled device in a dedicated application. Real time OS uses priority
scheduling algorithm to meet the response requirement of a real time application.
Real time systems are of two types
o Hard Real Time Systems
o Soft Real Time Systems
A hard real time system guarantees that the critical tasks to be completed on time.
This goal requires that all delays in the system be bounded from the retrieval of stored
data to time that it takes the OS to finish the request.
In soft real time system is a less restrictive one where a critical real time task gets
priority over other tasks & retains the property until it completes. Soft real time
system is achievable goal that can be mixed with other type of systems. They have
limited utility than hard real time systems. Soft real time systems are used in area of
multimedia, virtual reality & advanced scientific projects. It cannot be used in
robotics or industrial controls due to lack of deadline support. Soft real time requires
two conditions to implement, CPU scheduling must be priority based & dispatch
latency should be small.
Handheld Systems
Computing Environments
Traditional Computing
Consider the “typical office environment”: Few year’s back it consisted of PCs
connected to the network with servers providing file and print service, Remote access
looked tough and portability was achieved through laptop.
Terminals attached to mainframes were common at many companies with even few
remote access and portability option.
The web technologies are stretching the boundaries of traditional computing.
Companies have portals, which provide web access to their internal servers. Network
computers are terminals that understand the web based computing. Hand held PDAs
can also connect to wireless networks to use company’s web portal.
Peer-to-Peer(P2P) Computing
It is another form of a distributed system. Here, clients and servers are not
distinguished from one another.
All nodes within the system are considered as peers. Each can act as a server or
aclient depending on who is requesting or providing a service.
The advantage is the removal of bottleneck as the services can be provided by
several nodes that are distributed throughout the network.
To participate in a P2P system a node must first join the network of peers. On joining,
the new node can provide and request for services.
Determining what services are available in the network can be accomplished in one
of two methods,
1. When a node joins a network, it registers its services with a centralized lookup
service on the network. Any node wants service, first contacts the centralized
lookup service to determine which nodes provides the service. Then the
communication takes place between the client and the service provider.
2. A peer which is a client broadcasts a request for service to all nodes in the
network. The nodes that provide the service responds to the requesting peer. A
discovery protocol is used by the peers to discover the services provided by
other peers.
It leads to more access by wider variety of devices other than PCs workstations,
PDAs, and cell phones.
Web computing has increased the emphasis on networking.
Devices that were not previously networked have been wired or wireless nowadays.
The network connectivity is faster through improved network technology and
optimized network implementation code.
Web based computing has given rise to a new category of devices called load
balancers which distribute network connections among a pool of similar servers.
CHAPTER 2
OPERATING SYSTEM STRUCTURES
An OS provides an environment for the execution of the programs. The common services
provided by the OS are
1. User interface: Almost all operating systems have a user interface (UI).This interface
can take several forms.
a. Command-line interface(CLI): uses text commands and a specific
method for entering them.
b. Batch Interface: commands and directives to control are entered into files
and those files are executed.
c. Graphical User Interface (GUI): most common. Interface is a window
system with a pointing device directing the I/O, choose from menus, make
selections along with keyboard to enter text.
There are two fundamental approaches for users to interface with OS,
1. Command-line Interface
2. Graphical User Interface
Command Interpreter(CI)
Some OS include CI in the kernel, and in others like windows-XP and UNIX, it is
treated as a special program that is running when a job is initiated or when a user
first logs on.
On systems with multiple command interpreters to choose from, the interpreters
are known as shells. For ex:On UNIX and Linux systems, there are different
shells a user may choose from including Bourne shell, C shell and Korn shell etc
SYSTEM CALLS
The system call interface intercepts function call in the API and invokes the necessary
system call within the OS.
Three general methods are used to pass the parameters to the OS.
1. The simplest approach is to pass the parameters in registers.
2. In some cases there can be more parameters than registers. In these cases the
parameters are stored in a block or table in memory and the address of the block
is passed as a parameter in register. It is shown in below figure This approach is
used by Linux and Solaris.
3. Parameters can also be placed or pushed onto stack by the program &popped
off the stack by the OS.
Some OS prefer the block or stack methods, because those approaches do not limit the
number or length of parameters being passed.
1. Process control
end, abort
A running program needs to be able to halt its execution either normally or
abnormally. In an abnormal termination a dump of memory is taken and an error
load, execute
A process executing one program may want to load and execute another
program. This feature allows the command interpreter to execute programs as
directed by the user.
The question of where to return the control when the loaded program terminates is
related to the problem of whether the existing program is lost, saved or allowed to
continue execution concurrently with the new program. There is a system call for
this purpose (create or submit process).
2. File management
create file, delete file
System calls can be used to create & delete files.System calls may require the
name of the files and attributes for creating & deleting of files.
open, close file
Opens the file for usage and finally we need to close the file.
read, write, reposition
3. Device management
request device, release device
read, write, reposition
get device attributes, set device attributes
logically attach or detach devices
4. Information maintenance
get time or date, set time or date
get system data, set system data
get and set process, file, or device attributes
Many system calls exist for the purpose of transferring information between the
user program and the operating system.
For example, most systems have a system call to return the current time and date.
Other system calls may return information about the system, such as the number
of current users, the version number of the operating system, the amount of free
memory or disk space, and so on.
The operating system also keeps information about all its processes, and system
calls are used to access this information.
Systemcalls are also used to reset the process information (get process attributes
and set process attributes).
5. Communications
create, delete communication connection
send, receive messages
transfer status information
attach and detach remote devices
System Programs
i. File management: These programs create, delete, copy, rename, print, dump,
list, and generally manipulate files and directories.
ii. Status information: Some programs asks the system for the date, time,
amount of available memory or disk space, number of users, or similar status
information. Others are more complex, providing detailed performance,
logging, and debugging information.
iii. File modification: Several text editors are available to create and modify the
content of files stored on disk or other storage devices. There may also be
In addition to system programs, most operating systems are supplied with application
programs that are useful in solving common problems or performing common
operations. Such application programs are word processors, text formatters, spreadsheets,
database systems, compilers, plotting and statistical-analysis packages and games.
OS Design & Implementation
Design goals
The first aspect in designing a system is defining goals and specifications. Next we
need to define the mechanisms and policies to be implemented. Finally the
implementation takes place.
At the highest level, the system design will be affected by the choice of hardware and
type of system like timesharing, batch, distributed, real time, single user, multiuser
OS or general purpose etc.
At the next level the requirements can be divided into two basic groups: user goals
and system goals.
The user goals basically comprises of convenient to use, easy to learn and to use,
reliable, safe and fast etc.
The system goals are from the designer’s perspective that the system must be easy to
design, create and maintain. It should also be flexible, reliable, error free and
efficient.
The requirements vary from system to system. Different requirements result in
different solutions and hence different Operating Systems.
Simple Structures
Simple structure OS are small, simple & limited systems.The structure is not well
defined.
MS-DOS is an example of simple structure OS.MS-DOS layer structure is shown in
below figure.
In MS-DOS, the interfaces and levels of functionality are not well separated.
For instance, application programs are able to access the basic I/O routines to write
directly to the display and disk drives.
Everything below the system-call interface and above the physical hardware is the
kernel.
Kernel provides the file system, CPU scheduling, memory management, and other
operating-system functions through system calls.
This monolithic structure was difficult to implement and maintain.
Layered Approach
A system can be made modular in many ways. One method is the layered approach
in which the OS is divided into number of layers, where one layer is built on the top
of another layer.
The bottom layer (layer 0) is hardware and higher layer (layer N) is the user
interface. This layering structure is depicted in below figure.
Micro Kernels
Modules
The best current methodology for operating-system design involves using object-
oriented programming techniques to create a modular kernel.
Here, the kernel has a set of core components and links in additional services either
during boot time or during run time. Such a strategy uses dynamically loadable
modules and is common in modern implementations of UNIX, such as Solaris, Linux,
and Mac OS X.
For example, the Solaris operating system structure, shown in the below figure 2, is
organized around a core kernel with seven types of loadable kernel modules:
1. Scheduling classes
2.File systems
3.Loadable system calls
4.Executable formats
5.STREAMS modules
6.Miscellaneous
7.Device and bus drivers
The top layers include application environments and a set of services providing a
graphical interface to applications.
Below these layers is the kernel environment, which consists primarily of the Mach
microkernel and the BSD kernel.
Mach provides memory management, support for remote procedure calls (RPCs) and
inter process communication facilities, including message passing and thread
scheduling.
The BSD component provides a BSD command line interface, support for networking
and file systems, and an implementation of POSIX APIs, including Pthreads.
Virtual Machines
The fundamental idea behind a virtual machine is to abstract the hardware of a single
computer (the CPU, memory, disk drives, network interface cards, and so on) into
several different execution environments, thereby creating the illusion that each
separate execution environment is running its own private computer.
By using CPU scheduling and virtual-memory techniques, an operating system can
create the illusion that a process has its own processor with its own (virtual) memory.
Each process is provided with a (virtual) copy of the underlying computer as shown
in the below figure.
A major difficulty with the virtual machine approach involves disk systems. Suppose
that the physical machine had three disk drives but wanted to support seven virtual
machines. Clearly, it could not allocate a disk drive to each virtual machine, because
the virtual machine software itself will need substantial disk space to provide virtual
memory and spooling. The solution is to provide virtual disks-termed minidisks in
IBM's VM operating system which are identical in all respects except size.
Implementation
Examples
1. VMware
VMware architecture
Here, Linux is running as the host operating system and FreeBSD, Windows NT, and
Windows XPare running as guest operating systems.
The virtualization layer is the heart of VMware, as it abstracts the physical hardware
into isolated virtual machines running as guest operating systems.
Each virtual machine has its own virtual CPU, memory, disk drives, network
interfaces, and so on.
The class loader loads the compiled .class files from both the Java program and the
Java API for execution by the Java interpreter.
After a class is loaded, the verifier checks that the .class file is valid Java bytecode
and does not overflow or underflow the stack. It also ensures that the bytecode does
not perform pointer arithmetic, which could provide illegal memory access.
If the class passes verification, it is run by the Java interpreter.
The JVM also automatically manages memory by performing garbage collection -the
practice of reclaiming memory from objects no longer in use and returning it to the
system.
The JVM may be implemented in software on top of a host operating system, such as
Windows, Linux, or Mac OS X, or as part of a Web browser.
2.11System Boot
The procedure of starting a computer by loading the kernel is known as booting the
system.
Bootstrap program or Bootstrap loader locates the kernel, loads it into main memory
and start its execution.
Bootstrap program is in the form of read only memory (ROM) because the RAM is in
unknown state at a system startup. All forms of ROM are knows as firmware.
For large OS like Windows, Mac OS, the Bootstrap loaders is stored in firmware and the
OS is on disk.
Bootstrap has a bit code to read a single block at a fixed location from disk into the
memory and execute the code from that boot block.
A disk that has a boot partition is called a boot disk or system disk.
Question Bank
1. What is an Operating system? Explain its functions and goals.
2. Define the essential properties of the following types of operating systems:
a) Batch
b) Multiprogramming
c) Multitasking
d) Distributed
e) Realtime
3. Give the examples of real time system application.
4. Explain the function of memory management.
5. Explain the various operating system services.
6. What are the different types of system calls?
7. Explain different types of system structures.
8. Explain file management and its activity.
9. What is microkernel? Discuss the layers of kernel.
10. Explain the different categories of system calls.
10. What are the three main purposes of an operating system?
11. What is the main advantage of multiprogramming?
12. What are the differences between a trap and an interrupt? What is the use of each function?
1. Explain fundamental difference between i) N/w OS and distributed OS ii) web based and
embedded computing.
2. What do you mean by cooperating process? Describe its four advantages. 3. What are different
categories of system programs? Explain
4. Define OS. Discuss its role from different perspectives.
5. List different services of OS. Explain.
6. Explain the concept of virtual machines. Bring out its advantages. 7. Difference between a trap
and an interrupt
8. Define an operating system. Discuss its role with user and system view points.
9. Give features of symmetric and asymmetric multiprocessing systems
10. Briefly explain common classes of services provided by various OS for helping use for
ensuring efficient operation of system.
11. Define OS. Explain its two view points
12. What are OS operations? Explain
13. Define Virtual machine. With diagram, explain its working. What are its benefits?
14. Distinguish among following terminologies: Multiprogramming systems, multitasking
Systems, multiprocessor systems
15. What are system calls? With examples explain different categories of system call?
16. List and explain the functions and services of an operating system and OS operations17.
What are virtual machines? Explain VM-WARE architecture with a neat diagram18.
Differentiate between multiprogramming, multiprocessing and multitasking systems.
19. Explain process states with state transition diagram. Also explain PCB with a neat
diagram20. What is IPC? Explain Direct and Indirect communication with respect to message
passing systems. 21. Distinguish between the following pairs of terms:
Symmetric and asymmetric multiprocessor systems
CPU burst and I/O burst jobs.
User’s view and systems view of OS.
Batch systems and time sharing systems.
User mode and kernel mode operations.