INTRODUCTION TO OPERATING SYSTEM
What is an Operating System?
An operating system is a system software that acts as an intermediary between a user of a computer
and the computer hardware.
It is a software that manages the computer hardware.
Os allows the user to execute programs in a convenient and 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)
Computer system mainly consists of four components-
• Hardware – provides basic computing resources
CPU, memory, I/O devices
• Operating system
Controls and coordinates use of hardware among various applications
and users
• Application programs – define the ways in which the system resources are used to solve
the computing problems of the users
Word processors, compilers, web browsers, database systems, video
games
• Users
People, machines, other computers
The basic hardware components comprises of CPU, memory, I/O devices. The application program
uses these components. The OS controls and co-ordinates the use of hardware, among various
application programs (like compiler, word processor etc.) for various users.
The OS allocates the resources among the programs such that the hardware is efficiently used.
The operating system is the program running at all the times on the computer. It is usually called as
the kernel.
Non Kernel OS (User
necessary functions)
Kernel
Core of OS
(Sys. necessary functions)
Kernel functions are used always in system, so always stored in memory. Non kernel functions are
stored in hard disk, and it is retrieved whenever required.
Views of OS
Operating System can be viewed from two viewpoints– User
views & System views
1. User Views:-
The user’s view of the operating system depends on the type of user.
i. If the user is using standalone system, then OS is designed for ease of use and
high performances. Here resource utilization is not given importance.
ii. If the users are at different terminals connected to a mainframe or
minicomputers, by sharing information and resources, then the OS is designed
to maximize resource utilization. OS is designed such that the CPU time,
memory and i/o are used efficiently and no single user takes more than the
resource allotted to them.
iii. If the users are in workstations, connected to networks and servers, then the
user have a system unit of their own and shares resources and files with other
systems. Here the OS is designed for both ease of use and resource availability
(files).
iv. Users of hand held systems, expects the OS to be designed for ease of use and
performance per amount of battery life.
v. Other systems like embedded systems used in home devies (like washing m/c)
& automobiles do not have any user interaction. There are some LEDs to show
the status of its work.
2. System Views:-
Operating system can be viewed as a resource allocator and control program.
i. Resource allocator - The OS acts as a manager of hardware and software resources.
CPU time, memory space, file-storage space, I/O devices, shared files etc. are the
different resources required during execution of a program. There can be conflicting
request for these resources by different programs running in same system. The OS
assigns the resources to the requesting program depending on the priority.
ii. Control Program – The OS is a control program and manage the execution of user
program to prevent errors and improper use of the computer.
Computer System Organization
Computer-system operation
One or more CPUs, device controllers connect through common bus providing access to shared
memory. Each device controller is in-charge of a specific type of device. To ensure orderly access to
the shared memory, a memory controller is provided whose function is to synchronize access to the
memory. The CPU and other devices execute concurrently competing for memory cycles. Concurrent
execution of CPUs and devices competing for memory cycles
When system is switched on, ‘Bootstrap’ program is executed. It is the initial program to run in the
system. This program is stored in read-only memory (ROM) or in electrically erasable programmable
read-only memory(EEPROM). It initializes the CPU registers, memory, device controllers and other
initial setups. The program also locates and loads, the OS kernel to the memory. Then the OS starts
with the first process to be executed (ie. ‘init’ process) and then wait for the interrupt from the user.
Switch on ‘Bootstrap’ program
Initializes the registers, memory and I/O devices
Locates & loads kernel into memory
Starts with ‘init’ process
Waits for interrupt from user.
Interrupt handling –
The occurrence of an event is usually signaled by an interrupt. The interrupt can either be from the
hardware or the software. Hardware may trigger an interrupt at any time by sending a signal to the
CPU. Software triggers an interrupt by executing a special operation called a system call (also called
a monitor call).
When the CPU is interrupted, it stops what it is doing and immediately transfers execution to
a fixed location. The fixed location (Interrupt Vector Table) contains the starting address where the
service routine for the interrupt is located. After the execution of interrupt service routine, the CPU
resumes the interrupted computation.
Interrupts are an important part of computer architecture. Each computer design has its own
interrupt mechanism, but several functions are common. The interrupt must transfer control to the
appropriate interrupt service routine
Processor
interrupt
IVT
Interrupt Service
Routine
Stored at a fixed
location
Storage Structure
Computer programs must be in main memory (RAM) to be executed. Main memory is the large
memory that the processor can access directly. It commonly is implemented in a semiconductor
technology called dynamic random-access memory (DRAM). Computers provide Read Only
Memory(ROM), whose data cannot be changed.
All forms of memory provide an array of memory words. Each word has its own address.
Interaction is achieved through a sequence of load or store instructions to specific memory addresses.
A typical instruction-execution cycle, as executed on a system with a Von Neumann
architecture, first fetches an instruction from memory and stores that instruction in the instruction
register. The instruction is then decoded and may cause operands to be fetched from memory and
stored in some internal register. After the instruction on the operands has been executed, the result may
be stored back in memory.
Ideally, we want the programs and data to reside in main memory permanently. This
arrangement usually is not possible for the following two reasons:
1. Main memory is usually too small to store all needed programs and data permanently.
2. Main memory is a volatile storage device that loses its contents when power is turned off.
Thus, most computer systems provide secondary storage as an extension of main memory.
The main requirement for secondary storage is that it will be able to hold large quantities of data
permanently.
The most common secondary-storage device is a magnetic disk, which provides storage for
both programs and data. Most programs are stored on a disk until they are loaded into memory. Many
programs then use the disk as both a source and a destination of the information for their processing.
The wide variety of storage systems in a computer system can be organized in a hierarchy as
shown in the figure, according to speed, cost and capacity. The higher levels are expensive, but they
are fast. As we move down the hierarchy, the cost per bit generally decreases, whereas the access time
and the capacity of storage generally increases.
In addition to differing in speed and cost, the various storage systems are either volatile or
nonvolatile. Volatile storage loses its contents when the power to the device is removed. In the absence
of expensive battery and generator backup systems, data must be written to nonvolatile storage for
safekeeping. In the hierarchy shown in figure, the storage systems above the electronic disk are volatile,
whereas those below are nonvolatile.
An electronic disk can be designed to be either volatile or nonvolatile. During normal
operation, the electronic disk stores data in a large DRAM array, which is volatile. But many
electronic-disk devices contain a hidden magnetic hard disk and a battery for backup power. If external
power is interrupted, the electronic-disk controller copies the data from RAM to the magnetic disk.
Another form of electronic disk is flash memory.
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 specialpurpose
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.
BUFFER
DEVICE
Registers
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.
• DMA is used for high-speed I/O devices, able to transmit information at close to
memory speeds
• Device controller transfers blocks of data from buffer storage directly to main memory
without CPU intervention
• Only one interrupt is generated per block, rather than the one interrupt per byte
Computer System Architecture
Categorized roughly according to the number of general-purpose processors used –
Single-Processor Systems –
Most systems use a single processor. The variety of single-processor systems range from PDAs
through mainframes. On a single-processor system, there is one main CPU capable of executing
instructions from user processes. It contains special-purpose processors, in the form of device-specific
processors, for devices such as disk, keyboard, and graphics controllers.
All special-purpose processors run limited instructions and do not run user processes. These
are managed by the operating system, the operating system sends them information about their next
task and monitors their status.
For example, a disk-controller processor, implements its own disk queue and scheduling
algorithm, thus reducing the task of main CPU. Special processors in the keyboard, converts the
keystrokes into codes to be sent to the CPU.
The use of special-purpose microprocessors is common and does not turn a singleprocessor
system into a multiprocessor. If there is only one general-purpose CPU, then the system is a single-
processor system.
Multiprocessor Systems (parallel systems or tightly coupled systems) –
Systems that have two or more processors in close communication, sharing the computer bus,
the clock, memory, and peripheral devices are the multiprocessor systems.
Multiprocessor systems have three main advantages:
1. Increased throughput - In multiprocessor system, as there are multiple processors
execution of different programs take place simultaneously. Even if the number of processors is
increased the performance cannot be simultaneously increased. This is due to the overhead
incurred in keeping all the parts working correctly and also due to the competation for the
shared resources. The speed-up ratio with N processors is not N, rather, it is less than N. Thus
the speed of the system is not has expected.
2. Economy of scale - Multiprocessor systems can cost less than equivalent number of
many single-processor systems. As the multiprocessor systems share peripherals, mass storage,
and power supplies, the cost of implementing this system is economical. If several processes
are working on the same data, the data can also be shared among them.
3. Increased reliability- In multiprocessor systems functions are shared among several
processors. If one processor fails, the system is not halted, it only slows down. The job of the
failed processor is taken up, by other processors.
Two techniques to maintain ‘Increased Reliability’ - graceful degradation & fault
tolerant
Graceful degradation – As there are multiple processors when one processor fails
other process will take up its work and the system goes down slowly.
Fault tolerant – When one processor fails, its operations are stopped, the system failure
is then detected, diagnosed, and corrected.
The HP NonStop system uses both hardware and software duplication to ensure continued
operation despite faults. The system consists of multiple pairs of CPUs. Both processors in the
pair execute same instruction and compare the results. If the results differ, then one CPU of the
pair is at fault, and both are halted. The process that was being executed is then moved to
another pair of CPUs, and the instruction that failed is restarted. This solution is expensive,
since it involves special hardware and considerable hardware duplication.
There are two types of multiprocessor systems – •
Asymmetric multiprocessing
• Symmetric multiprocessing
1) Asymmetric multiprocessing – (Master/Slave architecture) Here each processor is
assigned a specific task, by the master processor. A master processor controls the other
processors in the system. It schedules and allocates work to the slave processors.
2) Symmetric multiprocessing (SMP) – All the processors are considered as peers. There
is no master-slave relationship. All the processors have its own registers and CPU, only
memory is shared.
The benefit of this model is that many processes can run simultaneously. N processes can run
if there are N CPUs—without causing a significant deterioration of performance. Operating
systems like Windows, Windows XP, Mac OS X, and Linux—now provide support for SMP.
A recent trend in CPU design is to include multiple compute cores on a single chip. The
communication between processors within a chip is more faster than communication between two
single processors.
Clustered Systems
Clustered systems are two or more individual systems connected together via network and sharing
software resources. Clustering provides high-availability of resources and services. The service will
continue even if one or more systems in the cluster fail. High availability is generally obtained by
storing a copy of files (s/w resources) in the system.
There are two types of Clustered systems – asymmetric and symmetric
In asymmetric clustering – one system is in hot-stand by mode while the others are running
the applications. The hot-standby host machine does nothing but monitor the active server. If that
server fails, the hot-standby host becomes the active server.
In symmetric clustering – two or more systems are running applications, and are monitoring
each other. This mode is more efficient, as it uses all of the available hardware. If any system fails, its
job is taken up by the monitoring system.
Other forms of clusters include parallel clusters and clustering over a wide-area network (WAN).
Parallel clusters allow multiple hosts to access the same data on the shared storage. Cluster technology
is changing rapidly with the help of SAN(storage-area networks). Using SAN resources can be
shared with dozens of systems in a cluster, that are separated by miles.
Operating-System Structure
One of the most important aspects of operating systems is the ability to multiprogram. A single user
cannot keep either the CPU or the I/O devices busy at all times. Multiprogramming increases CPU
utilization by organizing jobs, so that the CPU always has one to execute.
The operating system keeps several jobs in memory simultaneously as shown
in figure. This set of jobs is a subset of the jobs kept in the job pool. Since the number
of jobs that can be kept simultaneously in memory is usually smaller than the number
of jobs that can be kept in the job pool(in secondary memory). The operating system
picks and begins to execute one of the jobs in memory. Eventually, the job may have
to wait for some task, such as an I/O operation, to complete. In a non-
multiprogrammed system, the CPU would sit idle. In a multiprogrammed system, the
operating system simply switches to,
and executes, another job. When that job needs to wait, the CPU is switched to another job,
and so on.
Eventually, the first job finishes waiting and gets the CPU back. Thus the CPU is never idle.
Primary memory
Secondary mem.
CPU
Job
Pool
Multiprogrammed systems provide an environment in which the various system resources (for
example, CPU, memory, and peripheral devices) are utilized effectively, but they do not
provide for user interaction with the computer system.
In Time sharing (or multitasking) systems, a single CPU executes multiple jobs by
switching among them, but the switches occur so frequently that the users can interact with
each program while it is running. The user feels that all the programs are being executed at the
same time. Time sharing requires an interactive (or hands-on) computer system, which
provides direct communication between the user and the system. The user gives instructions to
the operating system or to a program directly, using a input device such as a keyboard or a
mouse, and waits for immediate results on an output device. Accordingly, the response time
should be short—typically less than one second.
A time-shared operating system allows many users to share the computer
simultaneously. As the system switches rapidly from one user to the next, each user is given
the impression that the entire computer system is dedicated to his use only, even though it is
being shared among many users.
A multiprocessor system is a computer system having two or more CPUs within a single
computer system, each sharing main memory and peripherals. Multiple programs are executed
by multiple processors parallel.
Distributed Systems
Individual systems that are connected and share the resource available in network is called
Distributed system. Access to a shared resource increases computation speed, functionality,
data availability, and reliability.
A network is a communication path between two or more systems. Distributed systems
depend on networking for their functionality. Networks vary by the protocols used, the
distances between nodes, and the transport media. TCP/IP is the most common network
protocol. Most operating systems support TCP/IP.
Networks are characterized based on the distances between their nodes. A local-area
network (LAN) connects computers within a room, a floor, or a building. A wide-area
network (WAN) usually links buildings, cities, or countries. A global company may have a
WAN to connect its offices worldwide. A metropolitan-area network (MAN) links buildings
within a city. A small-area network connects systems within a several feet using wireless
technology. Eg. BlueTooth and 802.11.
The media to carry networks also vary - copper wires, fiber strands, and wireless
transmissions between satellites, microwave dishes, and radios.
A network operating system is an operating system that provides features such as file
sharing across the network and that allows different processes on different computers to
exchange messages.A computer running a network operating system acts autonomously from
all other computers on the network, although it is aware of the network and is able to
communicate with other networked computers.
Operating-System Operations
Modern operating systems are interrupt driven. If there are no processes to execute,
no I/O devices to service, and no users to whom to respond, an operating system will sit quietly,
waiting for something to happen. Events are signaled by the occurrence of an interrupt or a
trap. A trap (or an exception) is a software-generated interrupt. For each type of interrupt,
separate segments of code in the operating system determine what action should be taken. An
interrupt service routine is provided that is responsible for dealing with the interrupt.
a) Dual-Mode Operation
Since the operating system and the user programs share the hardware and software
resources of the computer system, it has to be made sure that an error in a user program cannot
cause problems to other programs and the Operating System running in the system.
The approach taken is to use a hardware support that allows us to differentiate among
various modes of execution.
The system can be assumed to work in two separate modes of operation:
• user mode and
• kernel mode (supervisor mode, system mode, or privileged mode).
A hardware bit of the computer, called the mode bit, is used to indicate the current mode:
kernel (0) or user (1). With the mode bit, we are able to distinguish between a task that is
executed by the operating system and one that is executed by the user.
When the computer system is executing a user application, the system is in user mode.
When a user application requests a service from the operating system (via a system call), the
transition from user to kernel mode takes place.
At system boot time, the hardware starts in kernel mode. The operating system 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 (that is, changes the mode bit from 1 to 0). Thus,
whenever the operating system gains control of the computer, it is in kernel mode.
The dual mode of operation provides us with the means for protecting the operating
system from errant users—and errant users from one another.
The hardware allows privileged instructions to be executed only in kernel mode. If an
attempt is made to execute a privileged instruction in user mode, the hardware does not execute
the instruction but rather treats it as illegal and traps it to the operating system. The instruction
to switch to user mode is an example of a privileged instruction.
Initial control is within the operating system, where instructions are executed in kernel
mode. When control is given to a user application, the mode is set to user mode. Eventually,
control is switched back to the operating system via an interrupt, a trap, or a system call.
b) Timer
Operating system uses timer to control the CPU. A user program cannot hold CPU for
a long time, this is prevented with the help of timer.
A timer can be set to interrupt the computer after a specified period. The period may
be fixed (for example, 1/60 second) or variable (for example, from 1 millisecond to 1 second).
Fixed timer – After a fixed time, the process under execution is interrupted.
Variable timer – Interrupt occurs after varying interval. This is implemented using a
fixed-rate clock and a counter. The operating system sets the counter. Every time the clock
ticks, the counter is decremented. When the counter reaches 0, an interrupt occurs.
Before changing to the user mode, the operating system ensures that the timer is set to interrupt.
If the timer interrupts, control transfers automatically to the operating system, which may treat
the interrupt as a fatal error or may give the program more time.