Os Unit I R 22
Os Unit I R 22
A computer system can be divided roughly into for components – the hardware, the operating
system, the application programs and the users. The hardware consisting of CPU, memory and I/O
devices provides the basic computing resources for the system. The application programs define the
ways in which these resources are used to solve users computing problems.
1
The operating system controls and co-ordinates the use of hardware among the various application
programs for the various users.
Different views of Operating System
User view of an Operating System: The user’s view of the computer varies according to the
interface being used. While designing a PC for one user, the goal is to maximize the work that
the user is performing. Here OS is designed mostly for ease of use. In another case the user sits
at a terminal connected to a main frame or minicomputer. Other users can access the same
computer through other terminals. OS here is designed to maximize resource utilization to
assure that all available CPU time, memory and I/O are used efficiently. In other cases, users sit
at workstations connected to networks of other workstations and servers. These users have
dedicated resources but they also share resources such as networking and servers. Here OS is
designed to compromise between individual usability and resource utilization.
System view of an Operating System: From the computer’s point of view, OS can be viewed
as resource allocator where in resources are – CPU time, memory space, file storage space, I/O
devices etc. OS must decide how to allocate these resources to specific programs and users so
that it can operate the computer system efficiently. OS is also a control program. A control
program manages the execution of user programs to prevent errors and improper use of
computer. It is concerned with the operation and control of I/O devices.
Another service provided by the OS is of Resource manager. Resource management includes
multiplexing resources in two ways - "in time" and "in space". When a resource is time
multiplexed different programs or different users gets their turn to use that resource. Ex: Printer.
(ii)When a resource is space multiplexed instead of taking turns, the resource is shared among
them, i.e. each one gets a part of the resource. Ex: Sharing main memory, hard disk etc.
OBJECTIVES OF AN OPERATING SYSTEM
Convenience - An operating system makes a computer more convenient to use.
Efficiency - An operating system allows the computer system resources to be used in an
efficient manner.
Ability to Evolve - Should permit effective development, testing, and introduction of new
system features and functions without interfering with service.
DIFFERENT OPERATING SYSTEMS: Over the years, several different operating systems have been
developed for different purposes. The most typical operating systems in ordinary computers are
Windows, Linux and Mac OS.
WINDOWS: The name of the Windows OS comes from the fact that programs are run in “windows”:
each program has its own window, and you can have several programs open at the same time.
2
Windows is the most popular OS for home computers, and there are several versions of it. The newest
version is Windows 10.
LINUX AND UNIX: Linux is an open-source OS, which means that its program code is freely
available to software developers. This is why thousands of programmers around the world have
developed Linux, and it is considered the most tested OS in the world. Linux has been very much
influenced by the commercial Unix OS.
MAC OS X: Apple’s Mac computers have their own operating system, OS X. Apple’s lighter portable
devices (iPads, iPhones) use a light version of the same operating system, called iOS.Mac computers
are popular because OS X is considered fast, easy to learn and very stable and Apple’s devices are
considered well-designed—though rather expensive.
ANDROID: Android is an operating system designed for phones and other mobile devices. Android is
not available for desktop computers, but in mobile devices it is extremely popular: more than a half of
all mobile devices in the world run on Android.
Dual-Mode Operation
Since the operating system and the users share the hardware and software resources of the computer
system. We need to make sure that an error in a user program should not cause any problem to
operating system code or other programs. A properly designed operating system must ensure that an
incorrect (or malicious) program cannot cause other programs to execute incorrectly. In order to ensure
the proper execution of the operating system, we must be able to distinguish between the execution of
operating-system code and user defined code. The approach taken by most computer systems is to
provide hardware support that allows us to differentiate among various modes of execution.
Program can execute in two modes which are called User Mode and System mode or Kernel mode. A
bit, called the mode bit is added to the hardware of the computer 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 on behalf
of the operating system and one that is executed on behalf of the user. When the computer system is
executing on behalf of a user application, the system is in user mode. However, when a user application
requests a service from the operating system (via a system call), it must transition from user to kernel
mode to fulfill the request.
3
The dual mode of operation provides us with the means for protecting the operating system from errant
user. 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.
Timer:
We must ensure that the operating system maintains control over the CPU. We must prevent a user
program from getting stuck in an infinite loop or not calling system services and never returning
control to the operating system.
To accomplish this goal, we can use a 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). A variable timer is generally implemented by 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 turning over control to the user, 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.
Clearly, instructions that modify the content of the timer are privileged. Thus, we can use the timer to
prevent a user program from running too long. A simple technique is to initialize a counter with the
amount of time that a program is allowed to run. A program with a 7-minute time limit, for example,
would have its counter initialized to 420. Every second, the timer interrupts and the counter is
decremented by 1. As long as the counter is positive, control is returned to the user program. When the
counter becomes negative, the operating system terminates the program for exceeding the assigned
time limit.
Process Management
A process is a program in execution. A process needs certain resources, including CPU time, memory,
files, and I/O devices, to accomplish its task. These resources are either given to the process when it is
created, or allocated to it when it is running. Here program is a passive entity, such as the contents of a
file stored on disk, whereas process is an active entity, with a program counter specifying the next
4
instruction to execute. The execution of a process must be sequential. The operating system is
responsible for the following activities in connection with process management:
Creating and deleting both user and system processes.
Suspending and resuming processes.
Providing mechanisms for process synchronization.
Providing mechanisms for process communication.
Providing mechanisms for deadlock handling.
Main Memory Management
Main memory is a large array of words or bytes each with its own address. Main memory is a
repository of quickly accessible data shared by the CPU and I/O devices. Many different memory
management schemes are available and the effectiveness of the different algorithms depends on the
particular situation. The operating system is responsible for the following activities in connection with
memory management:
Keeping track of which parts of memory are currently being used and by whom.
Deciding which processes are to be loaded into memory when memory space becomes
available.
Allocating and de allocating memory space as needed.
File Management
File management is one of the most visible components of operating systems. Computers can store
information on several different types of physical media each having its own characteristics and
physical organization. A file is a collection of related information defined by its creator. It represents
programs and data. The OS implements the abstract concept of a file by managing mass storage media,
such as disks and tapes, and the devices that control them.
The operating system is responsible for the following activities in connection with file management:
Creating and deleting files
Creating and deleting directories
Supporting primitives for manipulating files and directories
Mapping files onto secondary storage
Backing up files on stable (nonvolatile) storage media.
I/O –System Management
One of the purposes of an operating system is to hide the peculiarities of specific hardware devices
form the user. The I/O subsystem consists of
A memory management component that includes buffering, caching and spooling.
A general device – driver interface.
5
Drivers for specific hardware devices
Without this cache, the CPU would have to wait several cycles while an instruction was fetched from
main memory. For similar reasons, most systems have one or more high-speed data caches in the
memory hierarchy. Because caches have limited size, cache management is an important design
problem. Careful selection of the cache size and of a replacement policy can result in greatly increased
performance. Main memory can be viewed as a fast cache for secondary storage, since data in
secondary storage must be copied into main memory for use, and data must be in main memory before
being moved to secondary storage for safekeeping.
Networking
Distributed system is a collection of processors that do not share memory, peripheral devices, or a
clock. Each processor has its own local memory and clock, and the processors communicate with one
another through various communication lines, such as high – speed buses or networks. The processors
in the system are connected through a communication network, which can be configured in a number
of different ways. A distributed system collects physically separate, possibly heterogeneous systems
into a single coherent system, providing the user with access to the various resources that the system
6
maintains. Access to a shared resource allows computation speedup, increased functionality, increased
data availability, and enhanced reliability. Operating systems usually generalize network access as a
form of file access, with the details of networking being contained in the network interface's device
driver.
Protection System
If a computer system has multiple users and allows the concurrent execution of multiple processes, then
the various processes must be protected from one another’s activities. Protection is any mechanism for
controlling the access of programs, processes, or users to the resources defined by a computer system.
Protection can improve reliability by detecting latent errors at the interfaces between component
subsystems. Early detection of interface errors can often prevent contamination of a healthy subsystem
by another subsystem that is malfunctioning.
Command-Interpreter System
One of the most important systems programs for an operating system is the command interpreter,
which is the interface between the user and the operating system. Some of the operating systems
include the command interpreter in the kernel. When a new job is started in a batch system, or when a
user logs on to a time – shared system, a program that reads and interprets control statements is
executed automatically. This program is sometimes called the control – card interpreter or the
command- line interpreter, and is often known as the shell. Its function is simple: To get the next
command statement and execute it. The command statements themselves deal with process creation
and management, I/O handling, secondary-storage management, main-memory management, file-
system access, protection, and networking.
Traditional Computing, as name suggests, is a possess of using physical data centers for storing
digital assets and running complete networking system for daily operations. In this, access to data, or
software, or storage by users is limited to device or official network they are connected with.
Batch systems
These are the early computers that are physically enormous machines running from a console. The
common input devices are card readers, tape drivers and some of the common output devices are Line
printers, Tape drives, Card Punches. The user did not interact directly with the computer systems.
7
Bring cards to 1401, Read cards onto input tape, Put input tape on 7094, perform the
computation, writing results to output tape, Put output tape on 1401, which prints output.
The operating system in these early computers was fairly simple. Its major task was to transfer control
automatically from one job to the next. The operating system was always resident in memory. To speed
up processing, operators batched together jobs with similar needs and ran them through the computer as
a group. Thus, the programmers would leave their programs with the operator. The operator would sort
programs into batches with similar requirements and, as the computer became available, would run
each batch. The output from each job would be sent back to the appropriate programmer. The
introduction of disk technology allowed the operating system to keep all jobs on a disk, rather than in a
serial card reader. With direct access to several jobs, the operating system could perform job scheduling, to
use resources and perform tasks efficiently.
Desktop systems
Once the personal computers PCs appeared in 1970’s, during the first decade, the CPUs in these PCs
lacked the features of protection of OS from user programs. PC operating systems were neither
multiuser nor multitasking. However as time passed, the goals of these operating systems shifted more
towards maximizing user convenience and responsiveness. The PCs started running Microsoft
Windows and Apple Macintosh. Linux, a UNIX-like operating system available for PCs, has also
become popular recently.
File protection was not a priority for these systems at first, but as these computers are now often tied
into other computers over local-area networks or other Internet connections enabling other computers
and users access the files on a PC, file protection again becomes a necessary feature of the operating
system. The lack of such protection has made it easy for malicious programs to destroy data on systems
such as MS-DOS and the Macintosh operating system. These programs may be self-replicating, and
may spread rapidly via worm or virus mechanisms and disrupt entire companies or even worldwide
networks. Security mechanisms capable of countering these attacks are to be implemented.
8
Multiprogrammed systems
One of the most important aspects of OS is its ability to multi program. Multi programming increases
CPU utilization by organizing jobs (code and data) so that the CPU always has one to execute. OS
keeps several jobs in memory.
This set of jobs can be a subset of jobs kept in the job pool which contains all jobs that enter the
system. OS picks and begins to execute one of the jobs in memory.
The job may have to wait for some task, such as I/O operation to complete. In a non multi
programmed system, the CPU would sit idle. But here, the OS simply switches to and executes
another job. When that job needs to wait, CPU is switched to another job and so on.
As long as at least on job needs to execute, CPU is never idle. Multiprogramming is the first
instance where the operating system must make decisions for the users. Multiprogrammed
operating systems are therefore fairly sophisticated. All the jobs that enter the system are kept in
the job pool.
This Job pool consists of all processes residing on disk awaiting allocation of main memory. If
several jobs are ready to be brought into memory, and if there is not enough room for all of
them, then the system must choose among them. Making this decision is job scheduling.
If several jobs are ready to run at the same time, the system must choose among them. Making
this decision is CPU scheduling.
Multi programmed systems provide an environment in which the various system resources are
utilized effectively but they do not provide for user interaction with the computer system.
9
Time- Sharing systems
Time-sharing or multi-tasking is a logical extension of multi programming. In time sharing
systems, 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.
Time-sharing requires an interactive computer system which provides direct communication
between the user and the system.
A time shared operating system allows many users to share the computer simultaneously. It
uses CPU scheduling and multi programming to provide each user with a small portion of a
time shared computer.
A program loaded into memory and executing is called a process. Time sharing and multi
programming require several jobs to be kept simultaneously in memory. Since main memory is
too small to accommodate all jobs, the jobs are kept initially on the disk in the job pool.
Time-sharing operating systems are even more complex than multi-programmed operating
systems. In Time sharing systems, to obtain a reasonable response time, jobs may have to be
swapped in and out of main memory to the disk that now serves as a backing store for main
memory.
A common method for achieving this goal is virtual memory, which is a technique that allows
the execution of a job that may not be completely in memory. The main advantage of the
virtual-memory scheme is that programs can be larger than physical memory.
Distributed systems
Distributed systems depend on networking for their functionality. By being able to communicate,
distributed systems are able to share computational tasks, and provide a rich set of features to users.
Also called as 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
10
telephone lines. These systems have many advantages such as resource sharing, computation speedup
(load sharing), reliability and communications. Distributed systems require networking infrastructure
such as Local Area Networks (LAN) or Wide Area Networks (WAN). They may be client-server or
peer-to-peer systems.
As PCs have become very powerful, faster and cheaper, the design interest has shifted from a
centralized system to that of a client-server system. Centralized systems today act as server systems to
satisfy requests generated by client systems. The general structure of a client-server system is depicted
below:
Server systems can be broadly categorized as compute servers and file servers.
Compute-server systems provide an interface to which clients can send requests to perform an
action, in response to which they execute the action and send back results to the client.
File-server systems provide a file-system interface where clients can create, update, read, and
delete files.
Peer-to-Peer Systems
Peer-to-peer network operating systems allow users to share resources and files located on their
computers and to access shared resources found on other computers. ... In a peer-to-peer network, all
computers are considered equal; they all have the same abilities to use the resources available on
the network.
11
Web-Based Computing
In brief, Web-based computing is an environment that consists of ultra-thin clients networked over
the Internet or intranet. The implementation of web-based computing has given rise to new categories
of devices, such as load balancers, which distribute network connections among a pool of similar
servers. Operating systems like Windows 95, which acted as web clients, have evolved into Linux and
Windows XP, which can act as web servers as well as clients. Generally, the Web has increased the
complexity of devices, because their users require them to be web-enabled.
Special-Purpose Systems
Unlike general purpose computers, there are different classes of computer systems whose functions are
more limited and whose objective is to deal with limited computation domains. Such special purpose
systems are
Real-Time Embedded Systems
Multimedia Systems
Hand held systems
Real-time systems
A real-time system is used when rigid time requirements have been placed on the operation of a
processor or the flow of data; thus, it is often used as a control device in a dedicated application. A real-
time system has well-defined, fixed time constraints. Processing must be done within the defined
constraints, or the system will fail. Real-Time systems are of two types. A hard real-time system
guarantees that critical tasks be completed on time. Due to the stringent time constraints, hard real-time
systems conflict with the operation of time-sharing systems, and the two cannot be mixed. A less
restrictive type of real-time system is a soft real-time system, where a critical real-time task gets
priority over other tasks, and retains that priority until it completes. Though soft real-time system is an
achievable goal, they have more limited utility than hard real-time systems and therefore risky to be
used in industrial control and robotics. They are useful in several areas, including multimedia, virtual
reality, and advanced scientific projects-such as undersea exploration and planetary rovers.
Multimedia Systems
Multimedia data consist of audio and video files as well as conventional files. These data differ from
conventional data in that multimedia data-such as frames of video-must be delivered (streamed)
according to
certain time restrictions (for example, 30 frames per second). Multimedia describes a wide range of
applications that are in popular use today. These include audio files such as MP3 DVD movies, video
conferencing, and short video clips of movie previews or news stories downloaded over the Internet.
Multimedia applications may also include live webcasts (broadcasting over the World Wide Web) of
speeches or sporting events. Most operating systems are designed to handle multimedia along with
conventional data such as text files, programs, word-processing documents, and spreadsheets.
12
Hand held systems:
Handheld systems includes personal Digital Assistants (PDAs) such as palm, pocket – pcs/ cellular
telephones. The main challenge of this type system is limited size of the system. So, it holds small
amount of storage space. One approach for displaying the content in webpage is web clipping, where
only a small subset of a web page is delivered and displayed on the handheld device.
Storage Structure
Computer programs must be in main memory (also called random-access memory or RAM) to be
executed. Main memory is implemented in a semiconductor technology called dynamic random-
access memory (DRAM), which forms an array of memory words. A typical instruction -execution
cycle, as executed on a system with a von Neumann architecture, will first fetch an instruction from
memory and will store 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. Since main
memory is too small and it’s volatile, most computer systems provide secondary storage as an
extension. The main idea is to store large quantities of data permanently. The most common secondary-
storage device is a magnetic disk, which provides storage of both programs and data. Most programs
(web browsers, compilers, word processors, spreadsheets, and so on) 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. Hence, the proper management of disk storage is of central
importance to a computer system. Main memory and the registers built into the processor itself are the
only storage that the CPU can access directly.
Storage Hierarchy:
The wide variety of storage systems in a computer system can be organized in a hierarchy according to
speed and cost. 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 storage capacity increases. The top three
levels of memory in above figure may be constructed using semiconductor memory. In the hierarchy
shown above, 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. Volatile storage
loses its contents when the power to the device is removed.
13
SERVICES PROVIDED BY AN OPERATING SYSTEM
An Operating System provides services to both the users and to the programs. It provides programs, an
environment to execute. It provides users, services to execute the programs in a convenient manner.
Following are few common services provided by operating systems.
User Interface:
Program execution
I/O operations
File System manipulation
Communication
Error Detection
Resource Allocation
Protection and Security
Accounting:
UI: A user interface refers to the part of an operating system, program, or device that allows a user to
enter and receive information. A text-based user interface (CUI) displays text, and its commands are
usually typed on a command line using a keyboard. With a graphical user interface (CUI) the
functions are carried out by clicking or moving buttons, icons and menus by means of a pointing
device.
14
Program execution: Operating system handles many kinds of activities from user programs to system
programs like printer spooler, name servers, file server etc. Each of these activities is encapsulated as a
process. A process includes the complete execution context. Following are the major activities of an
operating system with respect to program management.
Loads a program into memory.
Executes the program.
Handles program's execution.
Provides a mechanism for process synchronization.
Provides a mechanism for process communication.
Provides a mechanism for deadlock handling.
I/O Operation: I/O subsystem comprised of I/O devices and their corresponding driver software.
Drivers hides the peculiarities of specific hardware devices from the user as the device driver knows
the peculiarities of the specific device. Operating System manages the communication between user
and device drivers. Following are the major activities of an operating system with respect to I/O
Operation.
I/O operation means read or write operation with any file or any specific I/O device.
Program may require any I/O device while running.
Operating system provides the access to the required I/O device when required.
File system manipulation:A file represents a collection of related information. Computer can store
files on the disk (secondary storage), for long term storage purpose. Few examples of storage media are
magnetic tape, magnetic disk and optical disk drives like CD, DVDect. Each of these media has its
own properties like speed, capacity, and data transfer rate and data access methods. A file system is
normally organized into directories for easy navigation and usage. These directories may contain files
and other directions. Following are the major activities of an operating system with respect to file
management.
Program needs to read a file or write a file.
The operating system gives the permission to the program for operation on file.
Permission varies from read-only, read-write, denied and so on.
Operating System provides an interface to the user to create/delete files.
Operating System provides an interface to the user to create/delete directories.
Operating System provides an interface to create the backup of file system.
Communication:In case of distributed systems which are a collection of processors that do not share
memory, peripheral devices, or a clock, operating system manages communications between processes.
Multiple processes communicate with one another through communication lines in the network. OS
15
handles routing and connection strategies, and the problems of contention and security. Following are
the major activities of an operating system with respect to communication.
Two processes often require data to be transferred between them.
The both processes can be on the one computer or on different computer but are connected
through computer network.
Communication may be implemented by two methods either by Shared Memory or by Message
Passing.
Error handling:Error can occur anytime and anywhere. Error may occur in CPU, in I/O devices or in
the memory hardware. Following are the major activities of an operating system with respect to error
handling.
OS constantly remains aware of possible errors.
OS takes the appropriate action to ensure correct and consistent computing.
Resource Management: In case of multi-user or multi-tasking environment, resources such as main
memory, CPU cycles and files storage are to be allocated to each user or job. Following are the major
activities of an operating system with respect to resource management.
OS manages all kind of resources using schedulers.
CPU scheduling algorithms are used for better utilization of CPU.
Protection:Considering a computer systems having multiple users the concurrent execution of multiple
processes, then the various processes must be protected from each another's activities. Protection refers
to mechanism or a way to control the access of programs, processes, or users to the resources defined
by a computer systems. Security refers to providing a protection to the system.Following are the major
activities of an operating system with respect to protection.
OS ensures that all access to system resources is controlled.
OS ensures that external I/O devices are protected from invalid access attempts.
OS provides authentication feature for each user by means of a password.
Accounting: This service of the operating system keeps track of which users are using how much and
what kinds of computer resources have been used for accounting or simply to accumulate usage
statistics.
16
System Calls
System calls provide an interface to the services made available by an operating system. These calls are
generally available as routines written in C and C++, although certain low-level tasks, may need to be
written using assembly-language instructions.
Most programming languages provide a system-call interface that serves as the link to system calls
made available by the operating system. The system-call interface intercepts function calls in the API
and invokes the necessary system call within the operating system. Typically, a number is associated
with each system call, and the system-call interface maintains a table indexed according to these
numbers. The system call interface then invokes the intended system call in the operating system kernel
and returns the status of the system call and any return values.
Fig: The handling of a user application invoking the open() system call.
Three general methods are used to pass parameters between a running program and the operating
system:
Pass parameters in registers
Block or Table of Parameters
The Stack Approach
The simplest approach is to pass the parameters in registers. In some cases, however, there may be
more parameters than registers. In these cases, the parameters are generally stored in a block, or
table, in memory, and the address of the block is passed as a parameter in a register. This is the
approach taken by Linux and Solaris.
17
Parameters also can be placed, or pushed, onto the stack by the program and popped off the stack
by the operating system. Some operating systems prefer the block or stack method, because those
approaches do not limit the number or length of parameters being passed.
18
Device management : Device management does the job of device manipulation like reading from
device buffers, writing into device buffers, etc.
request device, release device
read, write, reposition
get device attributes, set device attributes
logically attach or detach devices
Information maintenance: It handles information and its transfer between the OS and the user
program.
get time or date, set time or date
get system data, set system data
get process, file, or device attributes
set process, file, or device attributes
Communications: These types of system calls are specially used for inter-process communications.
create, delete communication connection
send, receive messages
transfer status information
attach or detach remote devices
An operating system is a construct that allows the user application programs to interact with the system
hardware. There are many problems that can occur while designing and implementing an operating
system. It is quite complicated to define all the goals and specifications of the operating system while
designing it. System design is dominated by the choice of hardware and system type, it may change
from system to system.
There are basically two types of goals while designing an operating system. These are −
1. User Goals: The operating system should be convenient, easy to use, reliable, safe and fast
according to the users. However, these specifications are not very useful as there is no set
method to achieve these goals.
2. System Goals: The operating system should be easy to design, implement and maintain. These
are specifications required by those who create, maintain and operate the operating system. But
there is not specific method to achieve these goals as well.
A subtle difference between mechanism and policy is that mechanism shows how to do something and
policy shows what to do. Policies may change over time and this would lead to changes in mechanism.
So, it is better to have a general mechanism that would require few changes even when a policy change
occurs.
Operating-System Structure
A modern operating system is large in size and complex in structure, must be engineered carefully if it
is to function properly and be modified easily. A common approach is to partition the task into small
components rather than have one monolithic system. Each of these modules should be a well-defined
portion of the system, with carefully defined inputs, outputs, and functions.
Simple Structure:
Many commercial systems do not have well-defined structures. Frequently, such operating systems
started as small, simple, and limited systems and then grew beyond their original scope. MS-DOS is an
example of such a system. It was originally designed and implemented by a few people who had no
idea that it would become so popular. It was written to provide the most functionality in the least space,
so it was not divided into modules carefully. The following Figure shows its structure.
20
Layered Approach
Layered Structure is a type of system structure in which the different services of the operating
system are split into various layers, where each layer has a specific well-defined task to perform. It
was created to improve the pre-existing structures like the Monolithic structure ( UNIX ) and the
Simple structure ( MS-DOS ).
Example – The Windows NT operating system uses this layered approach as a part of it.
Design Analysis : The whole Operating System is separated into several layers ( from 0 to n ) as the
diagram shows. Each of the layers must have its own specific function to perform. There are some
rules in the implementation of the layers as follows.
1. The outermost layer must be the User Interface layer.
2. The innermost layer must be the Hardware layer.
3. A particular layer can access all the layers present below it, but it cannot access the layers present
above it. That is layer n-1 can access all the layers from n-2 to 0 but it cannot access the nth layer.
Thus if the user layer wants to interact with the hardware layer, the response will be travelled through
all the layers from n-1 to 1. Each layer must be designed and implemented such that it will need only
the services provided by the layers below it.
21
Advantages :
There are several advantages to this design :
1. Modularity: This design promotes modularity as each layer performs only the tasks it is
scheduled to perform.
2. Easy debugging: As the layers are discrete so it is very easy to debug. Suppose an error occurs in
the CPU scheduling layer, so the developer can only search that particular layer to debug, unlike
the Monolithic system in which all the services are present together.
3. Easy update: A modification made in a particular layer will not affect the other layers.
4. No direct access to hardware: The hardware layer is the innermost layer present in the design.
So a user can use the services of hardware but cannot directly modify or access it, unlike the
Simple system in which the user had direct access to the hardware.
5. Abstraction: Every layer is concerned with its own functions. So the functions and
implementations of the other layers are abstract to it.
Disadvantages :
Though this system has several advantages over the Monolithic and Simple design, there are also
some disadvantages as follows.
1. Complex and careful implementation: As a layer can access the services of the layers below it,
so the arrangement of the layers must be done carefully
2. Slower in execution: If a layer wants to interact with another layer, it sends a request that has to
travel through all the layers present in between the two interacting layers. Thus it increases
response time, unlike the Monolithic system which is faster than this. Thus an increase in the
number of layers may lead to a very inefficient design.
Virtual Machines
The fundamental idea behind a virtual machine is to abstract the hardware of a single computer into
several different execution environments, thereby creating the illusion that each separate execution
environment is running its own private computer. We can create a virtual machine for several reasons,
all of which are fundamentally related to the ability to share the same basic hardware yet can also
support different execution environments, i.e., different operating systems simultaneously.
VMs can run multiple operating system environments on a single physical computer, saving
physical space, time and management costs.
Virtual machines support legacy applications, reducing the cost of migrating to a new operating
system.
22
Disadvantages of virtual machines:
While virtual machines have several advantages over physical machines, there are also
some potential disadvantages:
Running multiple virtual machines on one physical machine can result in unstable
performance if infrastructure requirements are not met.
Virtual machines are less efficient and run slower than a full physical computer.
Most enterprises use a combination of physical and virtual infrastructure to balance the corresponding
advantages and disadvantages.
What is Microkernel?
Kernel is the core part of an operating system which manages system resources. It also acts like a
bridge between application and hardware of the computer. It is one of the first programs loaded on
start-up (after the Bootloader). Microkernel is one of the classification of the kernel. Being a kernel it
manages all system resources. But in a microkernel, the user services and kernel services are
implemented in different address space. The user services are kept in user address space, and kernel
services are kept under kernel address space, thus also reduces the size of kernel and size of
operating system as well. It provides minimal services of process and memory management. The
communication between client program/application and services running in user address space is
established through message passing, reducing the speed of execution microkernel.
23
What is Process?
• A process can be thought of as a program in execution, a process will need certain resources—
such as CPU time, memory, files, and I/O devices —to accomplish its task.
• These resources are allocated to the process either when it is created or while it is executing.
• A process is the unit of work in most systems. Systems consist of a collection of processes:
Operating-system processes execute system code, and user processes execute user code. All
these processes may execute concurrently
• Process memory is divided into four sections
o The text section comprises the compiled program code, read in from non-volatile
storage when the program is launched.
o The data section stores global and static variables, allocated and initialized prior to
executing main.
o The heap is used for dynamic memory allocation, and is managed via calls to new,
delete, malloc, free, etc.
o The stack is used for local variables. Space on the stack is reserved for local variables
when they are declared, and the space is freed up when the variables go out of scope.
The stack is also used for function return values.
24
Process States
The state of a process is defined in part by the current activity of that process. As a process executes, it
changes state.Each process may be in one of the following states:
25
PCB contains many pieces of information associated with a specific process, including these:
1. Process state
2. Program counter
3. CPU registers
4. CPU-scheduling information
5. Memory-management information
6. Accounting information
7. I/O status information
o Process state. The state may be new, ready, running, waiting, halted, and so on.
o Program counter. The counter indicates the address of the next instruction to be executed for
this process.
o CPU registers. The registers vary in number and type, depending on the computer architecture.
They include accumulators, index registers, stack pointers, and general-purpose registers, plus
any condition-code information.
o CPU-scheduling information. This information includes a process priority, pointers to
scheduling queues, and any other scheduling parameters.
o Memory-management information. This information may include such information as the
value of the base and limit registers, the page tables, or the segment tables etc.,
o Accounting information. This information includes the amount of CPU and real time used, time
limits, account numbers, job or process numbers, and so on.
o I/O status information. This information includes the list of I/O devices allocated to the process,
a list of open files, and so on.
26
Scheduling Queues
• As processes enter the system, they are put into a “job queue”, which consists of all processes
in the system.
• The processes that are residing in main memory and are ready and waiting to execute are kept
on a list called the “ready queue”. This queue is generally stored as a linked list.
• The list of processes waiting for a particular I/O device is called a “device queue”.
• A ready-queue header contains pointers to the first and final PCBs in the list.
• Each PCB includes a pointer field that points to the next PCB in the ready queue.
• The system also includes other queues. When a process is allocated the CPU, it executes for a
while and eventually quits, is interrupted, or waits for the occurrence of a particular event, such
as the completion of an I/O request.
Queueing Diagram
• A common representation of process scheduling is a queueing diagram where, each rectangular
box represents a queue. Two types of queues are present: the ready queue and a set of device
queues.
• The circles represent the resources that serve the queues, and the arrows indicate the flow of
processes in the system.
• A new process is initially put in the ready queue. It waits there until it is selected for execution,
or is dispatched.
• Once the process is allocated the CPU and is executing, one of several events could occur:
The process could issue an I/O request and then be placed in an I/O queue.
The process could create a new sub-process and wait for the sub-process's termination.
The process could be removed forcibly from the CPU, as a result of an interrupt, and be
put back in the ready queue.
• In the first two cases, the process eventually switches from the waiting state to the ready state
and is then put back in the ready queue.
27
• A process continues this cycle until it terminates, at which time it is removed from all queues
and has its PCB and resources deallocated
Process Schedulers
A process migrates among the various scheduling queues throughout its lifetime. The operating system
must select processes from these queues in some fashion. The selection process is carried out by the
appropriate scheduler.
The Short-term scheduler:The short-term scheduler, or CPU scheduler, selects from among the
processes that are ready to execute and allocates the CPU to one of them.
The short-term scheduler must select a new process for the CPU frequently.
A process may execute for only a few milliseconds before waiting for an I/O request. Often, the
short-term scheduler executes at least once every 100 milliseconds. Because of the short time
between executions, the short-term scheduler must be fast. All CPU scheduling algorithms are
type of short-term scheduler.
The long-term scheduler: The long-term scheduler, or job scheduler, selects processes from this pool
and loads them into memory for execution.The long-term scheduler executes much less frequently;
minutes may separate the creation of one new process and the next.The long-term scheduler controls
the degree of multi-programming. If the degree of multiprogramming is stable, then the average rate of
process creation must be equal to the average departure rate of processes leaving the system.
• Thus, the long-term scheduler may need to be invoked only when a process leaves the system.
Because of the longer interval between executions, the long-term scheduler can afford to take
more time to decide which process should be selected for execution.
• It is important that the long-term scheduler make a careful selection.
• In general, most processes can be described as either L/O bound or CPU bound. An I/O-bound
process is one that spends more of its time doing I/O than it spends doing computations. A
28
CPU-bound process, in contrast, generates I/O requests infrequently, using more of its time
doing computations.
• It is important that the long-term scheduler select a good process mix of I/O-bound and CPU-
bound processes. The system with the best performance will thus have a combination of CPU-
bound and I/O-bound processes.
This medium-term scheduler: The key idea behind a medium-term scheduler is that sometimes it can
be advantageous to remove processes from memory and thus reduce the degree of multiprogramming.
Later, the process can be reintroduced into memory, and its execution can be continued where it left
off. This scheme is called swapping.
• The process is swapped out, and is later swapped in, by the medium-term scheduler.
• Swapping may be necessary to improve the process mix or because a change in memory
requirements has overcommitted available memory, requiring memory to be freed up.
Context Switch
Interrupts cause the operating system to change a CPU from one process to another process. When an
interrupt occurs, the system needs to save the current context of the process on the CPU so that it can
restore that context when it resumingit.
• Switching the CPU to another process requires performing a state save of the current process
and a state restore of a different process. This task is known as a context switch.
29
Fig: Context Switch
• When a context switch occurs, the kernel saves the context of the old process in its PCB and
loads the saved context of the new process scheduled to run.
• Context-switch time is pure overhead, because the system does no useful work while switching.
• Context time speed varies from machine to machine, depending on the hardware support they
are
Operations on Processes
The processes in most systems can execute concurrently, and they may be created and deleted
dynamically, and the mechanism provided for this dynamic creation and deletion are:
• A process may create several new processes, via a create-process system call, during the course
of execution.
• The creating process is called a parent process, and the new processes are called the children of
that process.
• Each of these new processes may in turn create other processes, forming a tree of processes.
• Most operating systems identify processes according to a unique process identifier (or pid),
which is typically an integer number.
• In general, a process will need certain resources to accomplish its task. When a process creates
a sub-process, that sub-process may be able to obtain its resources directly from the operating
system, or it may be constrained to a subset of the resources of the parent process.
• The parent may have to partition its resources among its children, or it may be able to share
some resources among several of its children.
• Restricting a child process to a subset of the parent's resources prevents any process from
overloading the system by creating too many sub-processes.
30
Fig: Process Creation-A tree of processes on a typical Solaris system
When a process creates a new process, two possibilities exist in terms of execution:
1. The child process is a duplicate of the parent process (it has the same program and data as the
parent).
Process Termination:
• A process terminates when it finishes executing its final statement and asks the operating
system to delete it by using the exit () system call.
• At that point, the process may return a status value (typically an integer) to its parent process
(via the wait() system call).
• All the resources of the process—including physical and virtual memory, open files, and I/O
buffers—are deallocated by the operating system.
• Termination can occur in other circumstances as well. A process can cause the termination of
another process via an appropriate system call .
• Usually, such a system call can be invoked only by the parent of the process that is to be
terminated. Otherwise, users could arbitrarily kill each other's jobs.
• A parent may terminate the execution of one of its children for a variety of reasons, such as
these:
31
The child has exceeded its usage of some of the resources that it has been allocated.
The task assigned to the child is no longer required.
The parent is exiting, and the operating system does not allow a child to continue
• If its parent terminates. Some systems, including VMS, do not allow a child to exist if its parent
has terminated.
• In such systems, if a process terminates (either normally or abnormally), then all its children
must also be terminated. This phenomenon, referred to as “cascading termination”, is
normally initiated by the operating system.
Independent Process: A process is independent if it cannot affect or be affected by the other processes
executing in the system. Any process that does not share data with any other process is independent.
Threads
• A thread is a lightweight sub-process. It is a separate path of execution because each thread runs in a
different stack frame.
• A process may contain multiple threads. Threads share the process resources, but still, they execute
independently.
Why Multithreading?
32
• MS Word uses multiple threads: one thread to format the text, another thread to process inputs,
etc.
Process ‘VS’ Thread
The benefits of multithreaded programming can be broken down into four major categories:
3. Economy. Allocating memory and resources for process creation is costly. Because threads share
resources of the process to which they belong, it is more economical to create and context-switch
threads
Types of Threads
There are two types of threads, which are:
33
1. User Level Thread: As the name suggests, the user-level threads are only managed by users, and the
kernel does not have its information. These are faster, easy to create and manage. The kernel takes
all these threads as a single process and handles them as one process only. The user-level threads are
implemented by user-level libraries, not by the system calls.
2. Kernel-Level Thread: The kernel-level threads are handled by the Operating system and managed
by its kernel. These threads are slower than user-level threads because context information is
managed by the kernel. To create and implement a kernel-level thread, we need to make a system
call.
Multithreading Models
Based on the relationship between user threads and kernel threads, we have Three
Multithreadingmodels:
Many-to-One Model
• The many-to-one model maps many user-level threads to one kernel thread.
• Thread management is done by the thread library in user space, so it is efficient; but the entire
process will block if a thread makes a blocking system call.
• Also, because only one thread can access the kernel at a time, multiple threads are unable to run
in parallel on multiprocessors.
• Green threads—a thread library available for Solaris—uses this model, as does GNU Portable
Threads.
34
One-to-One Model
• The one-to-one model maps each user thread to a kernel thread.
• It provides more concurrency than the many-to-one model by allowing another thread to run
when a thread makes a blocking system call; it also allows multiple threads to run in parallel on
multiprocessors.
• The only drawback to this model is that creating a user thread requires creating the
corresponding kernel thread.
• Because the overhead of creating kernel threads can burden the performance of an application,
most implementations of this model restrict the number of threads supported by the system.
• Linux, along with the family of Windows operating systems—including Windows 95, 98, NT,
2000, and XP— implement the one-to-one model.
Many-to-Many Model
• The many-to-many model multiplexes many user-level threads to a smaller or equal number of
kernel threads.
• The number of kernel threads may be specific to either a particular application or a particular
machine.
• Whereas the many-to-one model allows the developer to create as many user threads as she
wishes, true concurrency is not gained because the kernel can schedule only one thread at a
time.
• The one-to-one model allows for greater concurrency, but the developer has to be careful not to
create too many threads within an application.
35
• The many-to-many model suffers from neither of these shortcomings: Developers can create as
many user threads as necessary, and the corresponding kernel threads can run in parallel on a
multiprocessor. Also, when a thread performs a blocking system call, the kernel can schedule
another thread for execution.
• One popular variation on the many-to-many model still multiplexes many user-level threads to
a smaller or equal number of kernel threads but also allows a user-level thread to be bound to a
kernel thread.
• This variation, sometimes referred to as the two-level model , is supported by operating systems
such as IRIX, HP-UX, and Tru64 UNIX.
• The Solaris operating system supported the two-level model in versions older than Solaris 9.
However, beginning with Solaris 9, this system uses the one-to-one model.
THE END
37