0% found this document useful (0 votes)
5 views77 pages

OS Material

An operating system (OS) serves as an interface between users and computer hardware, managing essential functions such as memory, processor, device, and file management. It enables efficient execution of programs and can be categorized into types like batch, time-sharing, distributed, network, and real-time operating systems. The document also discusses various OS structures, including simple, layered, and micro-kernel approaches, along with the services provided by operating systems to users and programs.

Uploaded by

tisap41181
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views77 pages

OS Material

An operating system (OS) serves as an interface between users and computer hardware, managing essential functions such as memory, processor, device, and file management. It enables efficient execution of programs and can be categorized into types like batch, time-sharing, distributed, network, and real-time operating systems. The document also discusses various OS structures, including simple, layered, and micro-kernel approaches, along with the services provided by operating systems to users and programs.

Uploaded by

tisap41181
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 77

CHAPTER-1

INTRODUCTION TO OPERATING SYSTEM


1.1 OVER VIEW OF OPERATING SYSTEMS:

 An Operating System (OS) is an interface between computer user and computer hardware.
 The operating system (OS) is the most important program that runs on a computer. Every
general-purpose computer must have an operating system to run other programs and
applications. Computer operating systems perform basic tasks, such as recognizing input
from the keyboard, sending output to the display screen, keeping track of files and
directories on the disk.
 The purpose of operating system is to provide an environment in which a user can execute
programs in convenient and efficient manner.
 An operating system is software which performs all the basic tasks like file management,
memory management, process management, handling input and output, and controlling
peripheral devices such as disk drives and printers.
 Operating system (OS) manages all of the software and hardware on the computer. Most
of the time, there are several different computer programs running at the same time, and they
all need to access your computer's central processing unit (CPU), memory, and storage.
The operating system coordinates all of this to make sure each program gets what it needs.
 Some popular Operating Systems include Linux, UNIX, Windows (XP, Vista, 7), Apple
MacOS, IOS etc.
DEFINITION: An operating system is a program that acts as an interface between the user and
the computer hardware and controls the execution of all kinds of programs.
OS is the interaction point or communication point between users and hardware.
Physical parts of the computer are called hardware. A set of programs given to the computer is
called software.

OPERATING SYSTEM MODEL

SYSTEM SOFTWARE: System software is a collection of programs designed to operate,


control and extend the processing capabilities of the computer itself. Compiler and Interpreter
etc are the examples of system software.

APPLICATION SOFTWARE: Application software is a set of programs designed for a


particular application. Examples of Application software are: Microsoft word, Microsoft Excel.
FUNCTIONS OF OPERATING SYSTEMS:

Following are some of important functions of an operating System.

1) Memory Management:
 Memory management refers to management of Primary Memory or Main Memory.
 Main memory is a large array of words or bytes where each word or byte has its own
address.
 Main memory provides a fast storage that can be accessed directly by the CPU. For a
program to be executed, it must in the main memory.
 A process is basically a program under execution

An Operating System does the following activities for memory management −


 Keeps tracks of primary memory, i.e., what part of it are in use by whom, what part is not
in use?
 The OS decides which process will get memory when and how much.
 Allocates the memory when a process requests it to do so.
 De-allocates the memory when a process no longer needs it or has been terminated.
2) Processor Management:
The OS decides which process gets the processor (CPU) when and for how much time. This
function is called process scheduling.

An Operating System does the following activities for processor management −

 Keeps tracks of processor and status of process. The program responsible for this task is
known as traffic controller.
 Allocates the processor (CPU) to a process.
 De-allocates processor when a process is no longer required.

3) Device Management:
An Operating System does the following activities for device management −

 Keeps tracks of all devices. Program responsible for this task is known as the I/O
controller.
 Decides which process gets the device when and for how much time.
 Allocates the device in the efficient way.
 De-allocates devices.

4) File Management:
A file system is normally organized into directories for easy navigation and usage. An
Operating System does the following activities for file management −

 Keeps track of information and location of files etc. The collective facilities are often
known as file system.
 Creating & deleting files.
 Creating & deleting directories.
5) Other Important Activities:
Following are some of the important activities that an Operating System performs −

 Security – OS prevents unauthorized access to programs and data by means of password


and similar other techniques,
 Control over system performance – OS maintains control over system performance by
recording delays between request for a service and response from the system.
 Job accounting −OS Keeps track of time and resources used by various jobs and users.
CPU time, memory, secondary storage like hard disks, network throughput, battery
power, external devices are all resources of a computer which an operating system
manages.
 Error detecting aids − Operating System is responsible for the productions of dumps
(unwanted data), error messages, error debugging and error detection aids.
 Coordination between other softwares and users − Coordination and assignment of
compilers, interpreters, assemblers and other software to the various users of the computer
systems is done by OS.

1.2 TYPES OF OPERATING SYSTEMS:

1) BATCH OPERATING SYSTEM:


Early computers were physically large machines. In these systems the user did not interact
directly with the computer system. Instead the user prepared a job which consists of
programming data and some control information and then submitted it to the computer
operator and after some time the output would appear.
Batch processing is a technique in which an Operating System collects the programs and
data together in a batch before processing starts. An Operating System does the following
activities related to batch processing −
 The OS defines a job which has predefined sequence of commands, programs and data as
a single unit.
 The OS keeps number of jobs in memory and executes them without any manual
information.
 Jobs are processed in the order of submission, i.e., first come first served fashion.
 When a job completes its execution, its memory is released and the output for the job
gets copied into an output spool for later printing or processing.
 To speed up processing, jobs with similar needs are batched together and run as a group.

BATCH OPERATING SYSTEM MODEL


Advantage
 Increased performance as a new job gets started as soon as the previous job is finished,
without any manual intervention.
Disadvantages
 Due to lack of protection scheme, one batch job can affect pending jobs.
 Lack of interaction between the user and the computer system.
2) TIME-SHARING OPERATING SYSTEM:
 Time-sharing is a technique which enables many people, located at various terminals,
to use a particular computer system at the same time.
 Processor's time which is shared among multiple users simultaneously is termed as time-
sharing.
 The time sharing system is also known as Multi User System or Multitasking Operating
System
 Multitasking is when multiple jobs are executed by the CPU simultaneously by switching
between them. Switches occur so frequently that the users may interact with each program
while it is running.
An Operating System does the following activities related to multitasking −
 The user gives instructions to the operating system or to a program directly, and receives
an immediate response. The operating system allows the users to share the computer
simultaneously.
 The OS handles multitasking in the way that it can handle multiple operations/executes
multiple programs at a time.
 These Operating Systems were developed to provide interactive use of a computer system
at a reasonable cost.
 A time-shared operating system uses the concept of CPU scheduling to provide each user
with a small portion of a time-shared CPU.
 CPU scheduling is a process which allows one process to use the CPU while the execution
of another process is on hold (in waiting state) due to unavailability of any resource like
I/O etc, thereby making full use of CPU. The aim of CPU scheduling is to make the system
efficient, fast and fair.
 The time sharing system provides the direct access to a large number of users where CPU
time is divided among all the users on scheduled basis.
 The OS allocates a set of time to each user.
 When this time is expired, it passes control to the next user on the system.
 This short period of time during that a user gets attention of the CPU is known as a time
slice or a quantum.
 The concept of time sharing system is shown in figure.
 In above figure the user 5 is active but user 1, user 2, user 3, and user 4 are in waiting state
whereas user 6 is in ready status.
 As soon as the time slice of user 5 is completed, the control moves on to the next ready
user i.e. user 6. In this state user 2, user 3, user 4, and user 5 are in waiting state and user 1
is in ready state.
 The process continues in the same way and so on.
 As the system switches CPU rapidly from one user/program to the next, each user is given
the impression that he/she has his/her own CPU, whereas actually one CPU is being shared
among many users.
Advantages of Timesharing operating systems are as follows −

 Provides the advantage of quick response.


 Reduces CPU idle time.
Disadvantages of Time-sharing operating systems are as follows –

 The system must have memory management & protection, since several jobs are kept in
memory at the same time.
 It provides mechanism for concurrent execution which requires complex CPU scheduling
schemes.
3) DISTRIBUTED OPERATING SYSTEM:
 The motivation behind developing distributed operating systems is the availability of
powerful and inexpensive microprocessors and advances in communication technology.
 These advancements in technology have made it possible to design and develop distributed
systems comprising of many computers that are inter connected by communication
networks. The main benefit of distributed systems is its low price.
 Distributed systems use multiple central processors to serve multiple real-time applications
and multiple users.
 Data processing jobs are distributed among the processors accordingly.
 The processors communicate with one another through various communication lines (such
as high-speed buses or telephone lines).
 These are referred as loosely coupled systems or distributed systems. Processors in a
distributed system may vary in size and function.
 Distributed OS is one where all of computers that are connected can share in tasks. For
instance, if you and your friend are connected with each other using distributed OS then
you can use a program which is actually on someone else's computer. LOCUS and
MICROS are the best examples of distributed operating systems.
The advantages of distributed systems are as follows −

 With resource sharing facility, a user at one site may be able to use the resources available
at another.
 If one site fails in a distributed system, the remaining sites can potentially continue
operating.
 Better service to the customers.
 Reduction of the load on the host computer.
The disadvantages of distributed systems are as follows –

 Security problem due to sharing


4) NETWORK OPERATING SYSTEM:
 A Network Operating System runs on a server and provides the server the capability to
manage data, users, groups, security, applications, and other networking functions.
 A typical configuration for a network operating system is a collection of personal
computers along with a common printer, server and file server for archival storage, all tied
together by a local network.
 Network OS is used to manage networked computers, means there would be a server and
one or more computers will be managed by that server like in your college, you might have
got one dedicated server and it will manage your individual computers or laptop.
 Some examples of network operating systems include Novell NetWare, Microsoft
Windows NT, Microsoft Windows 2000, Microsoft Windows XP, Sun Solaris, Linux, etc
The advantages of network operating systems are as follows −
 Security is server managed.
 Upgrades to new technologies and hardware can be easily integrated into the system.
 Remote access to servers is possible from different locations and types of systems.
The disadvantages of network operating systems are as follows −

 High cost of buying and running a server.


 Regular maintenance and updates are required.
5) REAL TIME OPERATING SYSTEM:
 Real time Operating Systems are very fast and quick respondent systems. These systems
are used in an environment where a large number of events must be accepted and
processed in a short time.
 Real time processing requires quick transaction and characterized by supplying immediate
response.
 The primary function of the real time operating system is to manage certain system
resources, such as the CPU, memory, and time. Each resource must be shared among the
competing processes to accomplish the overall function of the system.
 A real-time operating system must have well-defined, fixed time constraints, otherwise the
system will fail.
 Real-time operating system is designed for real-time applications, such as embedded
systems, industrial robots, scientific research equipments and others.

1.3 OPERATING SYSTEM STRUCTURES:

1) Simple Structure:

 There are several commercial systems that don‘t have a well- defined structure such
operating systems begin as small, simple & limited systems and then grow beyond their
original scope.
 MS-DOS (Microsoft Disk Operating System) is an example of such system. It was not
divided into modules carefully. In MS-DOS, the interfaces and levels of functionality are
not well separated.
 So MS-DOS was vulnerable to malicious programs, causing the entire system to crash
when user programs fail.
 Another example of limited structuring is the UNIX operating system.
2) Layered Approach:
 In the layered approach, the OS is broken into a number of layers (levels) each built on top
of lower layers. The bottom layer (layer 0) is the hardware & top most layer (layer N) is
the user interface.
 The main advantage of the layered approach is modularity.
 The layers are selected such that each uses functions (or operations) & services of only
lower layer.
 This approach simplifies debugging & system verification, i.e. the first layer can be
debugged without concerning the rest of the system. Once the first layer is debugged, its
correct functioning is assumed while the 2nd layer is debugged & so on.
 If an error is found during the debugging of a particular layer, the error must be on that
layer because the layers below it are already debugged. Thus the design & implementation
of the system are simplified when the system is broken down into layers.
 Each layer is implemented using only operations provided by lower layers. A layer doesn‘t
need to know how these operations are implemented; it only needs to know what these
operations do.
 The layer approach was first used in the operating system. It was defined in six layers.
 The major difficulty with the layered approach involves appropriately defining the various
layers. Because a layer can use only lower-level layers, careful planning is necessary.
 It is less efficient than a non layered system.

Layers Functions
5 User Program
4 I/O Management
3 Operator Process Communication
2 Memory Management
1 CPU Scheduling
0 Hardware
3) Micro-kernel Approach:
 A kernel is the central module of an operating system. It is the part of the operating system
that loads first, and it remains in main memory. It manages the tasks of the computer and
the hardware - most notably memory and CPU time.
 When the kernel became large and difficult to manage, in the mid-1980s, researchers at
Carnegie Mellon University developed an operating system called Mach that modularized
the kernel using the microkernel approach.
 This method structures the operating system by removing all nonessential components from
the kernel and implementing them as system and user-level programs. The result is a smaller
kernel. There is little confusion regarding which services should remain in the kernel and
which should be implemented in user space.
 The main function of the microkernel is to provide a communication facility between the
client program and the various services that are also running in user space.
 Communication is provided by message passing. For example if the client program wishes
to access a file, it must interact with the file server. The client program and service never
interact directly. Rather, they communicate indirectly by exchanging messages with the
microkernel.
 One benefit of the microkernel approach is ease of extending the operating system.
 All new services are added to user space and consequently do not require modification of the
kernel.
 When the kernel has to be modified, then the changes tend to be fewer, because the
microkernel is a smaller kernel. The resulting operating system is easier to port from one
hardware design to another.
 The microkernel also provided more security and reliability, since most services are running
as user – rather than kernel – processes. If a service fails the rest of the operating system
remains untouched.

1.4 OPERATING SYSTEM SERVICES:

An Operating System provides services to both the users and to the programs.

 It provides programs an environment to execute.


 It provides users the services to execute the programs in a convenient manner.
Following are a few common services provided by an operating system −

 Program execution
 I/O operations
 File System manipulation
 Communication
 Error Detection
 Resource Allocation
 Protection
1) Program execution: Operating systems handle many kinds of activities from user programs
to system programs. Each of these activities is encapsulated as a process. A process includes
the complete execution context (code to execute, data to manipulate). A process is program
under execution. Following are the major activities of an Operating System with respect to
program management –
 Loads a program into memory.
 Executes the program.
 Provides a mechanism for process communication.
2) I/O Operation: An I/O subsystem comprises of I/O devices and their corresponding driver
software. An Operating System manages the communication between user and device
drivers.
 I/O operation means read or write operation with any file or any specific I/O device.
 Operating system provides the access to the required I/O device when required.

3) File system manipulation: A file represents a collection of related information. Computers can
store files on the disk (secondary storage), for long-term storage purpose. Examples of
storage media include magnetic tape, magnetic disk and optical disk drives like CD, DVD.
Each of these media has its own properties like speed, capacity, data transfer rate and data
access methods. A file system is normally organized into directories for easy navigation and
usage. Following are the major activities of an Operating System with respect to file
management –
 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.

4) Communication: Multiple processes communicate with one another through communication


lines in the network. Following are the major activities of an Operating System with
respect to communication −
 Two processes often require data to be transferred between them
 Both the processes can be on one computer or on different computers, but are connected
through a computer network.
 Communication may be implemented by two methods, either by Shared Memory or by
Message Passing.

5) Error handling: Errors can occur anytime and anywhere. An 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 −
 The OS constantly checks for possible errors.
 The OS takes an appropriate action to ensure correct and consistent computing.

6) Resource Management: In 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 −
 The OS manages all kinds of resources using schedulers.
 CPU scheduling algorithms are used for better utilization of CPU.
7) Protection: Considering a computer system having multiple users and concurrent execution
of multiple processes, the various processes must be protected from each other's activities.
Protection refers to a mechanism or a way to control the access of programs, processes, or
users to the resources defined by a computer system. Following are the major activities of
an Operating System with respect to protection −
 The OS ensures that all access to system resources is controlled.
 The OS ensures that external I/O devices are protected from invalid access attempts.
 The OS provides authentication features for each user by means of passwords.

1.5 SYSTEM CALLS:


 As we know that for performing any Operation a user must have to specify the Operation
which he wants to operate on the Computer. We can say that For Performing any Operation
a user must have to Request for a Service from the System.
 For Making any Request a user will prepare a Special call which is also known as
the System Call.
 The System Call is the Request for running any Program and for performing any Operation
on the System.
 When a user first time, starts the system then the system is in the user mode and when he
request for a service then the user mode will be converted into the kernel mode which just
listen the request of the user and process the request and display the results those are
produced after the processing.
 When a user request for opening any folder or when he moves his mouse on the screen, then
this is called as the system call which he is using for performing any operation.
 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++.
 System Call is Programming interface to the services provided by the OS.
 Typically written in a high-level language (C or C++)
 Mostly accessed by programs via a high-level Application Program Interface (API) rather
than direct system call use.
 Three most common APIs are Win32 API for Windows, POSIX API for POSIX-based
systems (including virtually all versions of UNIX, Linux, and Mac OS X), and Java API for
the Java virtual machine (JVM)
 System calls provide the interface between a process & the OS. These are usually available
in the form of assembly language instruction.
 Some systems allow system calls to be made directly from a high level language program
like C, BCPL and PERL etc.
 Systems calls occur in different ways depending on the computer in use. System calls can be
roughly grouped into 5 major categories:
1) Process Control
2) File Manipulation
3) Device Management
4) Information maintenance
5) Communication
1. Process Control:
 End, abort: A running program needs to be able to has its execution either normally (end)
or abnormally (abort).
 Load, execute: A process or job executing one program may want to load and executes
another program.
 Create Process, terminate process: There is a system call specifying for the purpose of
creating a new process or job (create process or submit job). We may want to terminate a job
or process that we created (terminates process, if we find that it is incorrect or no longer
needed).
 Get process attributes, set process attributes: If we create a new job or process we should
able to control its execution. This control requires the ability to determine & reset the
attributes of a job or processes (get process attributes, set process attributes).
 Wait time: After creating new jobs or processes, we may need to wait for them to finish
their execution (wait time).
 Wait event, signal event: We may wait for a specific event to occur (wait event). The jobs
or processes then signal when that event has occurred (signal event).

2. File Manipulation:
 Create file, delete file: We first need to be able to create & delete files. Both the system
calls require the name of the file & some of its attributes.
 Open file, close file: Once the file is created, we need to open it & use it. We close the file
when we are no longer using it.
 Read, write, reposition file: After opening, we may also read, write or reposition the file
(rewind or skip to the end of the file).
 Get file attributes, set file attributes: For either files or directories, we need to be able to
determine the values of various attributes & reset them if necessary. Two system calls get
file attribute & set file attributes are required for their purpose.

3. Device Management:
 Request device, release device: If there are multiple users of the system, we first request
the device. After we finished with the device, we must release it.
 Read, write, reposition: Once the device has been requested & allocated to us, we can
read, write & reposition the device.

4. Information maintenance:
 Get time or date, set time or date: Most systems have a system call to return the current
date & time or set the current date & time.
 Get system data, set system data: Other system calls may return information about the
system like number of current users, version number of OS, amount of free memory etc.
 Get process attributes, set process attributes: The OS keeps information about all its
processes & there are system calls to access this information.

5. Communication:
 Create, Delete Communication Connection: Communication connection is created or
deleted.
 Send, Receive Messages: Messages are sent or received between users.
 Transfer Status Information: Status information is transferred between users.
SYSTEM PROGRAMS:
System programs provide a convenient environment for program development & execution.
They are divided into the following categories.
 File manipulation: These programs create, delete, copy, rename, print & manipulate files
and directories.
 Status information: Some programs ask the system for date, time & amount of available
memory or disk space, no. of users or similar status information.
 File modification: Several text editors are available to create and modify the contents of file
stored on disk.
 Programming language support: compliers, assemblers & interpreters are provided to the
user with the OS.
 Programming loading and execution: Once a program is assembled or compiled, it must
be loaded into memory to be executed.
 Application programs: Most OS are supplied with programs that are useful to solve
common problems or perform common operations. Ex: web browsers, word processors &
text formatters etc.

1.6 VIRTUAL MACHINES:


 A virtual machine is a program that acts as a virtual computer.
 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 forth) into several
different execution environments, thereby creating the illusion that each separate execution
environment is running its own private computer.
 A virtual machine (VM) is a software program or operating system that not only exhibits the
behaviour of a separate computer, but is also capable of performing tasks such as running
applications and programs like a separate computer.
 A virtual machine, usually known as a guest is created within another computing
environment referred as a "host." Multiple virtual machines can exist within a single host at
one time.
 A virtual machine is also known as a guest.
 It runs on your current operating system – the “host” operating system – and provides virtual
hardware to “guest” operating systems.
 The guest operating systems run in windows on your host operating system, just like any
other program on your computer.
 The guest operating system runs normally, as if it were running on a physical computer.
From the guest operating system’s perspective, the virtual machine appears to be a real,
physical computer.
 Virtual machines provide their own virtual hardware, including a virtual CPU, memory, hard
drive, network interface, and other devices.
 The virtual hardware devices provided by the virtual machines are mapped to real hardware
on your physical machine.
 For example, a virtual machine’s virtual hard disk is stored in a file located on your hard
drive.
 There are several reasons for creating a virtual machine, all of which are fundamentally
related to being able to share the same hardware yet run several different execution
environments (that is, different operating systems) concurrently.
Implementation: Although the virtual machine concept is useful, it is difficult to implement
since much effort is required to provide an exact duplicate of the underlying machine. The
CPU is being multiprogrammed among several virtual machines, which slows down the
virtual machines in various ways.

Advantages of virtual machines:


 Multiple OS environments can exist simultaneously on the same machine, isolated from
each other;
 Virtual machines are widely available and are easy to manage and maintain.

Disadvantages of virtual machines:


 When multiple virtual machines are simultaneously running on a host computer, each virtual
machine may introduce an unstable performance, which depends on the workload on the
system by other running virtual machines;
 Virtual machine is not that efficient as a real one when accessing the hardware.

1.7 OPERATING SYSTEM DESIGN AND IMPLEMENTATION:


VIEWS OF OPERATING SYSTEM:
Operating System is designed both by taking user view and system view into consideration.

Below is what the users and system thinks about Operating System.

1) User View:
 The goal of the Operating System is to maximize the work and minimize the effort of the
user.
 Most of the systems are designed to be operated by single user; however in some systems
multiple users can share resources, memory. In these cases Operating System is designed
to handle available resources among multiple users and CPU efficiently.
 Operating System must be designed by taking both usability and efficient resource
utilization into view.
 Operating System gives an effect to the user as if the processor is dealing only with the
current task, but in background processor is dealing with several processes.
 The user view of the computer varies by the interface being used. The examples are -
windows XP, vista, windows 7 etc.
 Most computer user sit in the in front of personal computer (pc), in this case the operating
system is designed mostly for easy use with some attention paid to resource utilization.
 Some user sit at a terminal connected to a mainframe/minicomputer. In this case other
users are accessing the same computer through the other terminals.
 There users share resources and may exchange the information. The operating system in
this case is designed to maximize resources utilization to assume that all available CPU
time, memory and I/O are used efficiently and no individual user takes more than his/her
fair and share.
 The other users sit at workstations connected to network of other workstations and servers.
These users have dedicated resources but they share resources such as networking and
servers like file, compute and print server. Here the operating system is designed to
compromise between individual usability and resource utilization.
2) System View:
 From the system point of view, Operating System is a program involved with the hardware.
 Operating System is allocator, which allocate memory, resources among various processes.
It controls the sharing of resources among programs.
 It prevents improper usage of resources and handles errors.
 It is a program that runs all the time in the system in the form of Kernel.
 It controls application programs that are not part of Kernel. The kernel is the
central module of an operating system (OS). It is the part of the operating system that loads
first, and it remains in main memory.
 From the computer point of view the operating system is the program which is most
intermediate with the hardware.
 An operating system has resources as hardware and software which may be required to
solve a problem like CPU time, memory space, file storage space and I/O devices and so
on. That‘s why the operating system acts as manager of these resources.
 Another view of the operating system is it is a control program. A control program
manages the execution of user programs to present the errors in proper use of the computer.
It is especially concerned of the user the operation and controls the I/O devices

DESIGN GOALS: The first problem in designing a system is to define goals and
specifications. At the highest level, the design of the system will be affected by the choice of
Hardware and the type of system: batch; time shared, network, distributed, real time, or general
purpose. Beyond this highest design level, the requirements may be much harder to specify.
The purpose of an operating system is to be provided an environment in which a user can
execute programs. Its primary goal is to make the computer system convenient for the user. Its
secondary goal is to use the computer hardware in efficient manner.

IMPLEMENTATION:
Once an operating system is designed, it must be implemented. Traditionally, operating systems
have been written in assembly language. Now, however, they are most commonly written in
higher-level languages such as C or C++.
CHAPTER-2
PROCESS MANAGEMENT
2.1 PROCESS CONCEPTS:
PROCESS:
 A process is basically a program under execution. The execution of a process must progress
in a sequential fashion.
 A process is defined as an entity which represents the basic unit of work to be implemented
in the system.
 To put it in simple terms, we write our computer programs in a text file and when we
execute this program, it becomes a process which performs all the tasks mentioned in the
program.
 A 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 instruction to execute.
 A process is an instance of a computer program that is being executed. It contains the
program code and its current activity.

PROGRAM:
A program is a piece of code which may be a single line or millions of lines. A computer
program is usually written by a computer programmer in a programming language. For
example, here is a simple program written in C programming language:

#include <stdio.h>
int main() {
printf("Hello, World! \n");
return 0; }
A computer program is a collection of instructions that performs a specific task when executed
by a computer. When we compare a program with a process, we can conclude that a process is
a dynamic instance of a computer program.

PROCESS LIFE CYCLE:


When a process executes, it passes through different states. The state of a process is defined in
part by the current activity of that process.
In general, a process can have one of the following five states at a time.

1) New: The process is being created.


2) Running: Instructions are being executed.
3) Waiting: The process is waiting for some event to occur (such as an I/O completion or
reception of a signal).
4) Ready: The process is waiting to be assigned to a processor.
5) Terminated: The process has finished execution.
 I/O operation means read or write operation with any file or any specific I/O device.
 Scheduler dispatch- Allocates CPU to a process.
PROCESS LIFE CYCLE
1. A process switches from the ready state to the running state at scheduler dispatch
2. A process switches from the running state to the ready state when an interrupt occurs
3. A process switches from the running state to the waiting state as the result of an I/O request
or event wait
4. A process switches from the waiting state to the ready state at completion of I/O or event
5. Finally a process terminates when it finishes its execution.

PROCESS CONTROL BLOCK (PCB):


A Process Control Block is a data structure maintained by the Operating System for every
process. The PCB is identified by an integer process ID (PID). A PCB keeps all the
information needed to keep track of a process as listed below−

 Process State: The current state of the process i.e., whether it is ready, running, waiting, or
whatever.
 Process privileges: This is required to allow/disallow access to system resources.
 Process ID: Unique identification for each of the process in the operating system.
 Pointer: A pointer to parent process.
 Program Counter: Program Counter is a pointer to the address of the next instruction to be
executed for this process.
 CPU registers: Various CPU registers where process need to be stored for execution for
running state.
 CPU Scheduling Information: Process priority and other scheduling information which is
required to schedule the process.
 Memory management information: This includes the information of page table, memory
limits, Segment table depending on memory used by the operating system.
 Accounting information: This includes the amount of CPU used for process execution,
time limits, execution ID etc.
 I/O status information: This includes a list of I/O devices allocated to the process.

 The architecture of a PCB is completely dependent on Operating System and may contain
different information in different operating systems.
 The PCB is maintained for a process throughout its lifetime, and is deleted once the
process terminates.
Here is a simplified diagram of a PCB:

2.2 OPERATIONS ON PROCESSES:

The processes in the system can execute concurrently, and they must be created and deleted
dynamically. Thus, the operating system must provide a mechanism (or facility) for process
creation and termination.

1) PROCESS CREATION:

 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, whereas the new processes are called the
children of that process.
 Each of these new processes may in turn create other processes.
 A new process is created by the forkO system call.
 In general, a process will need certain resources (such as CPU time, memory, files, I/O
devices) 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 (such as memory or files) among several of its children.
 When a process is created it obtains in addition to the various physical and logical resources,
initialization data (or input) that may be passed along from the parent process to the child
process.
When a process creates a new process, two possibilities exist in terms of execution:

1) The parent continues to execute concurrently with its children.


2) The parent waits until some or all of its children have terminated.

There are also two possibilities in terms of the address space of the new process:
1) The child process is a duplicate of the parent process (it has the same program and data as
the parent).
2) The child process has a new program loaded into it.
2) 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 data (output) 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 de-allocated by the operating system.
 A process can cause the termination of another process via an appropriate system call (for
example, abort).
 Usually, only the parent of the process that is to be terminated can invoke such a system call.
 Otherwise, users could arbitrarily kill each other's jobs. A parent therefore needs to know the
identities of its children.
 Thus, when one process creates a new process, the identity of the newly created process is
passed to the parent.
 A parent may terminate the execution of one of its children for a variety of reasons, such as
these:
1) The child has exceeded its usage of some of the resources that it has been allocated. This
requires the parent to have a mechanism to inspect the state of its children.
2) The task assigned to the child is no longer required.
3) The parent is exiting, and the operating system does not allow a child to continue if its
parent terminates.
 On such systems, if a process terminates (either normally or abnormally), then all its
children must also be terminated.

2.3 COOPERATING PROCESSES:


 The concurrent processes executing in the operating system may be either independent
processes or cooperating processes.
 A process is independent if it cannot affect or be affected by the other processes executing in
the system.
 Clearly, any process that does not share any data (temporary or persistent) with any other
process is independent.
 On the other hand, a process is cooperating if it can affect or be affected by the other
processes executing in the system.
 Clearly, any process that shares data with other processes is a cooperating process.
We may want to provide an environment that allows process cooperation for several reasons:

1) Information sharing: Since several users may be interested in the same piece of
information (for instance, a shared file), we must provide an environment to allow
concurrent access to these types of resources.
2) Computation speedup: If we want a particular task to run faster, we must break it into
subtasks, each of which will be executing in parallel with the others. Such a speedup can be
achieved only if the computer has multiple processing elements (such as CPU’S or I/O
channels).
3) Modularity: We may want to construct the system in a modular fashion, dividing the
system functions into separate processes.
4) Convenience: Even an individual user may have many tasks to work at one time. For
instance, a user may be editing, printing, and compiling in parallel.
2.4 THREADS:

 A thread is a basic unit of CPU utilization. Thread comprises a thread ID, a program
counter, a register set, and a stack.
 It shares with other threads belonging to the same process its code section, data section, and
other operating-system resources, such as open files and signals. A traditional (or
heavyweight) process has a single thread of control. If a process has multiple threads of
control, it can perform more than one task at a time.
 A thread is a flow of execution through the process code, with its own program counter that
keeps track of which instruction to execute next, system registers which hold its current
working variables, and a stack which contains the execution history.
 A thread shares with its peer threads little information like code segment, data segment and
open files.
 A thread is a single sequence stream within in a process. Because threads have some of the
properties of processes, they are sometimes called lightweight processes. In a process,
threads allow multiple executions of streams.
 Each thread belongs to exactly one process and no thread can exist outside a process.
 Each thread represents a separate flow of control. Threads have been successfully used in
implementing network servers and web servers.
 Threads are used for small tasks, whereas processes are used for more 'heavyweight' tasks.
Another difference between a thread and a process is that threads within the
same process share the same address space, whereas different processes do not.

Difference between Process and Thread:


Process Thread

Process is heavy weight or resource Thread is light weight, taking lesser


intensive. resources than a process.

Process switching needs interaction with Thread switching does not need to
operating system. interact with operating system.

In multiple processing environments, each All threads can share same set of open
process executes the same code but has its files, child processes.
own memory and file resources.

If one process is blocked, then no other While one thread is blocked and
process can execute until the first process waiting, a second thread in the same
is unblocked. task can run.

Multiple processes without using threads Multiple threaded processes use fewer
use more resources. resources.

In multiple processes each process One thread can read, write or change
operates independently of the others. another thread's data.
Advantages of Thread:
The benefits of multithreaded programming can be broken down into four major categories:
1. Responsiveness: Multithreading in an interactive application may allow a program to
continue running even if part of it is blocked or is performing a lengthy operation, thereby
increasing responsiveness to the user. For instance, a multithreaded web browser could still
allow user interaction in one thread while an image was being loaded in another thread.
2. Resource sharing: By default, threads share the memory and the resources of the process to
which they belong. The benefit of sharing code and data is that it allows an application to have
several different threads of activity within the same address space.
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.
4. Utilization of multiprocessor architectures: The benefits of multithreading can be greatly
increased in a multiprocessor architecture, where threads may be running in parallel on
different processors. A single threaded process can only run on one CPU, no matter how many
are available. Multithreading on a multi-CPU machine increases concurrency.

SINGLE AND MULTITHREADED PROCESS

Example of Threads:
Let’s suppose we have an online banking system, where people can log in and access their account
information. Whenever someone logs in to their account online, they receive a separate and unique
thread so that different bank account holders can access the central system simultaneously.

2.5 INTER PROCESS COMMUNICATION:


 Cooperating processes require an interprocess communication (IPC) mechanism that will
allow them to exchange data and information. There are two fundamental models of
interprocess communication: shared memory system and message passing system.
 In the shared-memory model, a region of memory that is shared by cooperating processes is
established. Processes can then exchange information by reading and writing data to the
shared region.
 In the message passing model, communication takes place by means of messages exchanged
between the cooperating processes.
1) Shared-Memory System:
 Interprocess communication using shared memory requires communicating processes to
establish a region of shared memory.
 Typically, a shared-memory region resides in the address space of the process creating the
shared-memory segment.
 Other processes that wish to communicate using this shared-memory segment must attach it
to their address space.
 Recall that, normally, the operating system tries to prevent one process from accessing
another process's memory.
 Shared memory requires that two or more processes agree to remove this restriction.
 They can then exchange information by reading and writing data in the shared areas.
 The form of the data and the location are determined by these processes and are not under
the operating system's control.
 The processes are also responsible for ensuring that they are not writing to the same location
simultaneously.

2) Message-Passing System:
 The function of a message passing system is to allow processes to communicate with one
another without the need to resort to shared data.
 Communication among the user processes is accomplished through the passing of messages.
 An IPC facility provides the two operations: send(message) and receive(message).
 Messages sent by a process can be of either fixed or variable size. If only fixed sized
messages can be sent, the system-level implementation is straightforward.
 On the other hand, variable-sized messages require a more complex system-level
implementation.
 If processes P and Q want to communicate, they must send messages to and receive
messages from each other; a communication link must exist between them.
 This link can be implemented in a variety of ways. We are concerned here not with the link's
physical implementation (such as shared memory, hardware bus, or network), but rather
with its logical implementation.

Naming: Processes that want to communicate must have a way to refer to each other. They
can use either direct or indirect communication.

1. Direct Communication: With direct communication, each process that wants to


communicate must explicitly name the recipient or sender of the communication. In this
scheme, the send and receive primitives are defined as:

 Send (P, message)-Send a message to process P.


 Receive (Q , message) -Receive a message from process Q
A communication link in this scheme has the following properties:

 A link is established automatically between every pair of processes that want to


communicate. The processes need to know only each other's identity to communicate.
 A link is associated with exactly two processes.
 Exactly one link exists between each pair of processes.

2. Indirect Communication:
With indirect communication, the messages are sent to and received from mailboxes, or
ports. A mailbox can be viewed abstractly as an object into which messages can be placed
by processes and from which messages can be removed. Each mailbox has a unique
identification. In this scheme, a process can communicate with some other process via a
number of different mailboxes. Two processes can communicate only if they share a
mailbox. The send and receive primitives are defined as follows:

 send (A, message) –Send a message to mailbox A.


 receive (A, message) -Receive a message from mailbox A.
In this scheme, a communication link has the following properties:

 A link is established between a pair of processes only if both members of the pair have a
shared mailbox.
 A link may be associated with more than two processes.
 A number of different links may exist between each pair of communicating processes,
with each link corresponding to one mailbox.

2.6 PROCESS SCHEDULING:

DEFINITION:
 The process scheduling is the activity of the process manager that handles the removal of
the running process from the CPU and the selection of another process on the basis of a
particular strategy.
 The act of determining which process in the ready state should be moved to the running
state is known as Process Scheduling.

PROCESS SCHEDULING QUEUES:


 The OS maintains all PCBs in Process Scheduling Queues.
 The OS maintains a separate queue for each of the process states and PCBs of all processes
in the same execution state are placed in the same queue.
 When the state of a process is changed, its PCB is unlinked from its current queue and
moved to its new state queue.
The Operating System maintains the following important process scheduling queues:

 Job queue – Job queue consists of set of all processes in the system.
 Ready queue − Ready queue consists of set of all processes residing in main memory, ready
and waiting to execute.
 Device queues − Device queue consists of set of processes waiting for an I/O device.
The OS can use different policies to manage each queue (FIFO, Round Robin, Priority, etc.).

Two-State Process Model:


Two-state process model refers to running and non-running states which are described below –

1) Running: When a new process is created, it enters into the system as in the running state.
2) Not Running: Processes that are not running are kept in queue, waiting for their turn to
execute. Each entry in the queue is a pointer to a particular process. Queue is implemented
by using linked list.

SCHEDULERS: Schedulers are special system software which handles process scheduling
in various ways. Their main task is to select the jobs to be submitted into the system and to
decide which process to run. Schedulers are of three types −

 Long-Term Scheduler
 Short-Term Scheduler
 Medium-Term Scheduler

1) Long Term Scheduler:


 It is also called a job scheduler. A long-term scheduler determines which programs are
admitted to the system for processing.
 A long term scheduler or job scheduler selects processes from job pool (mass storage
device, where processes are kept for later execution) and loads them into memory for
execution. The long term scheduler controls the degree of multiprogramming (the number
of processes in memory).
 Process loads into the memory for CPU scheduling.
 On some systems, the long-term scheduler may not be available or minimal.
 When a process changes the state from new to ready, then there is use of long-term
scheduler.
2) Short Term Scheduler:
 It is also called as CPU scheduler.
 A short term scheduler or CPU scheduler selects from the main memory among the
processes that are ready to execute and allocates the CPU to one of them.
 It is the change of ready state to running state of the process.
 Short-term schedulers, also known as dispatchers, make the decision of which process to
execute next. Short-term schedulers are faster than long-term schedulers.
 It provides lesser control over degree of multiprogramming.
3) Medium Term Scheduler:
 Medium-term scheduling is a part of swapping.
 It removes the processes from the memory.
 It reduces the degree of multiprogramming.
 The medium-term scheduler is in-charge of handling the swapped out-processes.
 A running process may become suspended if it makes an I/O request.
 Suspended processes cannot make any progress towards completion.
 In this condition, to remove the process from memory and make space for other processes,
the suspended process is moved to the secondary storage.
 This process is called swapping, and the process is said to be swapped out or rolled out.
Swapping may be necessary to improve the process mix.
 The medium term scheduler available in all systems which is responsible for the swapping
in and out operations which means loading the process into, main memory from secondary
memory (swap in) and take out the process from main memory and store it into the
secondary memory (swap out).
 During extra load, this scheduler picks out big processes from the ready queue for some
time, to allow smaller processes to execute, thereby reducing the number of processes in
the ready queue.

Comparison among Schedulers:


S.No. Long-Term Scheduler Short-Term Scheduler Medium-Term Scheduler

1 It is a job scheduler It is a CPU scheduler It is a process swapping


scheduler.

2 Speed is lesser than short Speed is fastest among Speed is in between both
term scheduler other two short and long term
scheduler.

3 It controls the degree of It provides lesser control It reduces the degree of


multiprogramming over degree of multiprogramming.
multiprogramming

4 It selects processes from It selects those processes It can re-introduce the


pool and loads them into which are ready to process into memory and
memory for execution execute execution can be continued.

2.7 SCHEDULING ALGORITHMS:


CPU Scheduling: All the processes which are ready to execute are placed in main memory
and then selection of one of those processes is known as scheduling, and after selection that
process gets the control of CPU.
Scheduling Criteria: The criteria for comparing CPU scheduling algorithms include the
following:
 CPU Utilization: It means keeping the CPU as busy as possible.
 Throughput: It is nothing but the measure of work i.e., the number of processes that are
completed per time unit.
 Turnaround Time: The interval from the time of submission of a process to the time of
completion.
 Waiting Time: The sum of the periods spent waiting in the ready queue.
 Response Time: The time from the submission of a request until the first response is
produced.
 CPU burst time: The duration for which a process gets control of the CPU and the concept
of gaining control of the CPU is the CPU burst.

A Process Scheduler schedules different processes to be assigned to the CPU based on


particular scheduling algorithms. There are six popular process scheduling algorithms. These
algorithms are either non-preemptive or preemptive.

Non-preemptive algorithms are designed so that once a process enters the running state; it
cannot be preempted until it completes its allotted time, whereas the preemptive scheduling is
based on priority where a scheduler may preempt a low priority running process anytime when
a high priority process enters into a ready state.

1)First Come First Serve (FCFS) Scheduling:


 With this scheme, the process that requests the CPU first is allocated the CPU first.
 The implementation of the FCFS policy is easily managed with FIFO queue.
 When a process enters the ready queue, its PCB (Process Control Block) is linked onto the
tail of the queue.
 When the CPU is free, it is allocated to the process at the head of the queue. The running
process is then removed from the queue.
 FCFS scheduling is non-preemptive, very simple, can be implemented with a FIFO queue,
not a good choice when there are variable burst times.
 Drawback: causes short processes to wait for longer ones.

Turn around time for P3 = 30-27=3 ms

Thus, the average waiting time is (0+ 24 + 27)/3 = 17 milliseconds.


2) Shortest Job First (SJF) Scheduling:
 When the CPU is available, it is assigned to the process that has the smallest next CPU
burst.
 If the two processes have the same length or amount of next CPU burst, FCFS scheduling
is used to break the tie.

 A more appropriate term for this scheduling method would be the shortest next CPU burst
algorithm because scheduling depends on the length of the next CPU burst of a process.
 The SJF algorithm can either be preemptive or non-preemptive.
 The choice arises when a new process arrives at the ready queue while a previous process
is still executing.
 The next CPU burst of the newly arrived process may be shorter than what is left of the
currently executing process.
 A preemptive SJF algorithm will preempt the currently executing process, whereas a, non-
preemptive algorithm will allow the currently running process to finish its CPU burst.
 Preemptive SJF scheduling, is sometimes called shortest-remaining-time-first-scheduling.

3) Priority Scheduling
 A priority is associated with each process and the CPU is allocated to the process with the
highest priority and Equal priority processes are scheduled in FCFS order.
 We can be provided that low numbers represent high priority or low numbers represent low
priority, According to the question, we need to assume anyone of the above.
 Priority scheduling can be either preemptive or non-preemptive.
 A preemptive priority scheduling algorithm will preempt the CPU, if the priority of the
newly arrived process is higher than the priority of the currently running process.
 A non-preemptive priority scheduling algorithm will simply put the new process at the head
of the ready queue.
Process Table

Waiting time for P1 = 6


Waiting time for P2 = 0
Waiting time for P3 = 16
Waiting time for P4 = 18
Waiting time for P5 = 1
Average waiting time

4) Round Robin Scheduling:


 The RR scheduling algorithm is designed especially for time sharing systems.
 It is similar to FCFS scheduling but preemption is added to switch between processes.
 A small unit of time called a time quantum or time slice is defined.
 If time quantum is too large, this just becomes FCFS.

Process Table

Let’s take time quantum = 4 ms. Then the resulting RR schedule is as Follows:

Gantt chart

P1 waits for the 6 ms (10 – 4), P2 waits for 4 ms and P3 waits for 7 ms.

Thus, Average waiting time=


5) Multiple-Level Queue Scheduling:
 This scheduling algorithm has been created for situations, in which processes are easily
classified into different groups,
 A multilevel queue scheduling algorithm partitions the ready queue into several separate
queues.
 The processes are permanently assigned to one queue, generally based on some property of
the process, such as memory size, process priority or process type.
 Multiple queues are maintained for processes with common characteristics.
 Each queue can have its own scheduling algorithm.
 Priorities are assigned to each queue.
For example, CPU-bound jobs can be scheduled in one queue and all I/O-bound jobs in
another queue. The Process Scheduler then alternately selects jobs from each queue and
assigns them to the CPU based on the algorithm assigned to the queue.
6) Multilevel Feedback Queue Scheduling:

 This scheduling algorithm allows a process to move between queues.


 The idea is to separate processes according to the characteristics of their CPU bursts.
 If a process uses too much CPU time, it will be moved to a lower priority queue. Similarly,
a process that waits too long in a lower priority queue may be moved to a higher priority
queue.

2.8 MULTI-PROCESSOR SCHEDULING:

 When multiple processors are available, then the scheduling gets more complicated, because
now there is more than one CPU which must be kept busy and in effective use at all times.
 Load sharing revolves around balancing the load between multiple processors.
 Multi-processor systems may be heterogeneous (different kinds of CPUs),
or homogenous (all same kind of CPU - in terms of functionality).

Approaches to Multiple-Processor Scheduling:

 One approach to multi-processor scheduling is asymmetric multiprocessing, in which one


processor is the master, controlling all activities and running all kernel code, while the other
processors runs only user code. This approach is relatively simple, as only one processor
accesses the system data structures, reducing the need for data sharing.
 Another approach is symmetric multiprocessing (SMP), where each processor is self-
scheduling (schedules its own jobs), either from a common ready queue or from separate
ready queues for each processor. Virtually all modern OS’s support SMP, including XP,
Win 2000, Solaris, Linux, and Mac OSX.

Load Balancing:

 An important goal in a multiprocessor system is to balance the load between processors, so


that one processor won't be sitting idle while another is overloaded.
 Systems using a common ready queue are naturally self-balancing, and do not need any
special handling. Most systems, however, maintain separate ready queues for each
processor.
 Balancing can be achieved through either push migration or pull migration:
 Push migration involves a separate process that runs periodically,(e.g. every 200
milliseconds ), and moves processes from heavily loaded processors onto less loaded
ones.
 Pull migration involves idle processors taking processes from the ready queues of other
processors.

2.9 THREAD SCHEDULING:

Types of Threads: Threads are implemented in following two ways −

 User Level Threads – They are User managed threads.


 Kernel Level Threads – They are Operating System managed threads acting on kernel.
User Level Threads:
In this case, the thread management is not done by kernel and kernel is not aware of the
existence of threads. The thread library contains code for creating and destroying threads, for
passing message and data between threads, for scheduling thread execution and for saving and
restoring thread contexts. The application starts with a single thread. User threads are supported
above the kernel and are managed without kernel support.
Kernel Level Threads:
In this case, thread management is done by the Kernel. Kernel threads are supported and
managed directly by the operating system.
Difference between User-Level & Kernel-Level Thread:
User-Level Threads Kernel-Level Thread

User-level threads are faster to create and Kernel-level threads are slower to create
manage. and manage.

Implementation is by a thread library at Operating system supports creation of


the user level. Kernel threads.

User-level thread is generic and can run Kernel-level thread is specific to the
on any operating system. operating system.

Multithreading Models:
The user threads must be mapped to kernel threads, by one of the following strategies.
 Many-To-One Model
 One-To-One Model
 Many-To-Many Model
1) MANY-TO-ONE MODEL:
 In the many-to-one model, many user-level threads are all mapped onto a single kernel
thread.
 Thread management is handled by the thread library in user space, which is efficient in
nature.

2) ONE-TO-ONE MODEL:
 The one-to-one model creates a separate kernel thread to handle each and every user thread.
 Most implementations of this model place a limit on how many threads can be created.
 Linux and Windows from 95 to XP implement the one-to-one model for threads.

3) MANY-TO-MANY MODEL:
 The many-to-many model multiplexes any number of user threads onto an equal or smaller
number of kernel threads, combining the best features of the one-to-one and many-to-one
models.
 Users can create any number of the threads.
CHAPTER-3
PROCESS SYNCHRONIZATION
 Process Synchronization means sharing system resources by processes in such a way that,
Concurrent access to shared data is handled thereby minimizing the chance of inconsistent
data.
 On the basis of synchronization, processes are categorized as one of the following two types:
1) Independent Process: Execution of one process does not affect the execution of other
processes.
2) Cooperative Process: Execution of one process affects the execution of other processes.
 Process synchronization problem arises in the case of Cooperative process because resources
are shared in Cooperative processes.
 Co-operating process may either directly share a logical address space or be allotted to the
shared data only through files or messages. This concurrent access is known as Process
synchronization.

3.1 THE CRITICAL SECTION PROBLEM:

 Critical section is a piece of code that accesses a shared resource (data structure or device)
that must not be concurrently accessed by more than one process. A critical section will
usually terminate in fixed time, and a process will have to wait a until that fixed time.
 Critical section is a code segment that can be accessed by only one process at a time. Critical
section contains shared variables which need to be synchronized to maintain consistency of
data
 Consider a system consisting of n processes (P0, P1, ………Pn -1) each process has a
segment of code which is known as critical section in which the process may be changing
common variable, updating a table, writing a file and so on.
 The important feature of the system is that when the process is executing in its critical
section no other process is to be allowed to execute in its critical section.
 The execution of critical sections by the processes is mutually exclusive.
 The critical section problem is to design a protocol that the process can use to co-operate.
 Each process must request permission to enter its critical section.
 The section of code implementing this request is the entry section.
 The critical section is followed on exit section.
 The remaining code is the remainder section.
 The general structure of a typical process Pi, is shown below.
 The entry section and exit section are enclosed in boxes to highlight these important
segments of code.

General structure of a typical process Pi


do{
entry section
critical section
exit section
remainder section
} while (TRUE);
A solution to the critical section problem must satisfy the following three conditions:

1. Mutual Exclusion: If process Pi is executing in its critical section then no any other process
can be executing in their critical section.
2. Progress: If no process is executing in its critical section and some processes wish to enter
their critical sections, then only those processes that are not executing in their remainder
sections can participate in the decision on which will enter its critical section next.
3. Bounded waiting: There exists a bound on the number of times that other processes are
allowed to enter their critical sections after a process has made a request to enter its critical
section and before that request is granted.

3.2 PETERSON’S SOLUTION:


 Peterson’s Solution is a classical software based solution to the critical section problem.
 Peterson's solution is restricted to two processes that alternate execution between their
critical sections and remainder sections.
 The processes are named Pi and Pj. The Petersons solutions ask both the processes to share
two data items.
 The two processes share two variables:
o int turn;
o Boolean flag[2];
 The variable turn indicates whose turn it is to enter its critical section. That is, if turn == i,
then process Pi; is allowed to execute in its critical section. The flag array is used to indicate
if a process is ready to enter its critical section. For example, if flag[i] is true, this value
indicates that Pi; is ready to enter its critical section.

The structure of process Pi, in Peterson's solution:


do {
flag[i] = TRUE;
turn = j;
while ( flag[j] && turn == j);
CRITICAL SECTION
flag[i] = FALSE;
REMAINDER SECTION
} while (TRUE);

Peterson’s Solution preserves all three conditions:


 Mutual Exclusion is assured as only one process can access the critical section at any time.
 Progress is also assured, as a process outside the critical section does not block other
processes from entering the critical section.
 Bounded Waiting is preserved as every process gets a fair chance.

Disadvantages of Peterson’s Solution:


 It involves Busy waiting (technique in which a process repeatedly checks to see if a
condition is true).
 It is limited to 2 processes.
Solution to the critical-section problem using locks:
do {
//acquire lock
critical section
//release lock
remainder section
} while (TRUE);

3.3 SYNCHRONIZATION HARDWARE:


 Many systems provide hardware support for critical section code.
 The critical section problem could be solved easily in a single-processor environment if we
could disallow interrupts to occur while a shared variable or resource is being modified.
 In this manner, we could be sure that the current sequence of instructions would be allowed
to execute in order without pre-emption (The act of temporarily interrupting a task being
carried out by a computer system).
 Unfortunately, this solution is not feasible in a multiprocessor environment.
 Disabling interrupt on a multiprocessor environment can be time consuming as the message
is passed to all the processors.
 This message transmission lag, delays entry of threads into critical section and the system
efficiency decreases.
 TestAndSet:
TestAndSet is a hardware solution to the synchronization problem. In TestAndSet, we have
a shared lock variable which can take either of the two values, 0 or 1.
• 0 Unlock
• 1 Lock
 Before entering into the critical section, a process inquires about the lock. If it is locked, it
keeps on waiting till it become free and if it is not locked, it takes the lock and executes the
critical section.
 Mutual-exclusion implementation with TestAndSet ( )
do {
while (TestAndSetLock(&lock) )
; // do nothing
// critical section
lock = FALSE;
// remainder section
} while (TRUE);
 In TestAndSet, Mutual exclusion and progress are preserved but bounded waiting cannot be
preserved.

3.4 SEMAPHORES:
 In 1965, Dijkstra proposed a new and very significant technique for managing concurrent
processes by using the value of a simple integer variable to synchronize the progress of
interacting processes.
 Semaphore is a data structure that is used to make sure that multiple processes do not access
a common resource or a critical section at the same time, in parallel programming
environments. Semaphores are used to avoid dead locks.
 A semaphore is a variable whose value indicates the status of a common resource. Its
purpose is to lock the resource being used. A process which needs the resource will check
the semaphore for determining the status of the resource followed by the decision for
proceeding. In multitasking operating systems, the activities are synchronized by using the
semaphore techniques.
 This integer variable is called semaphore.
 So it is basically a synchronizing tool and is accessed only through two low standard atomic
operations, wait and signal designated by P() and V() respectively.
 Mutual exclusion on the semaphore is enforced within P(S) and V(S). If a number of
processes attempt P(S) simultaneously, only one process will be allowed to proceed & the
other processes will be waiting. These operations are defined as under −

The classical definition of wait and signal are:

 Wait: Decrements the value of its argument S.

The classical definition of WAIT is:


wait (s)
{
while (s <= 0);
s--;
}

 Signal: Increments the value of its argument S.

The classical definition of the SIGNAL is:


signal (s)
{
s++;
}

Semaphores are of two types:


1) Binary Semaphore: Binary Semaphores have 2 methods associated with it (lock, unlock),
When a resource is available, the process in charge set the semaphore to 1 else 0.
2) Counting Semaphore: A counting semaphore is an integer variable which may have value
to be greater than one, typically used to allocate resources from a pool of identical
resources.

Properties of Semaphores:

1. Simple to implement
2. Works with many processes
3. Can have many different critical sections with different semaphores
4. Each critical section has unique access to semaphores
5. Can permit multiple processes into the critical section at once, if desirable.
3.5 CLASSICAL PROBLEMS OF SYNCHRONIZATION:

There are various types of problem which are proposed for synchronization scheme such as:
1) Bounded Buffer Problem:
Bounded buffer problem, which is also called producer consumer problem, is one of the
classic problems of synchronization.
Problem Statement:
There is a buffer of n slots and each slot is capable of storing one unit of data. There are two
processes running, namely, producer and consumer, which are operating on the buffer.

Bounded Buffer Problem:


A producer tries to insert data into an empty slot of the buffer. A consumer tries to remove data
from a filled slot in the buffer. As you might have guessed by now, those two processes won’t
produce the expected output if they are being executed concurrently. There needs to be a way to
make the producer and consumer work in an independent manner.
Solution:
One solution of this problem is to use semaphores. The semaphores which will be used here
are:
 mutex, a binary semaphore which is used to acquire and release the lock.
 empty, a counting semaphore whose initial value is the number of slots in the buffer, since,
initially all slots are empty.
 full, a counting semaphore whose initial value is 0.
At any instant, the current value of empty represents the number of empty slots in the buffer
and full represents the number of occupied slots in the buffer.
Producer Operation:
The pseudo code of the PRODUCER function:
do {
wait(empty); // wait until empty>0 and then decrement ‘empty’
wait(mutex); // acquire lock
/* perform the insert operation in a slot */
signal(mutex); // release lock
signal(full); // increment ‘full’
} while(TRUE);

 Looking at the above code for a producer, we can see that a producer first waits until there is
at least one empty slot.
 Then it decrements the empty semaphore because, there will now be one less empty slot,
since the producer is going to insert data in one of those slots.
 Then, it acquires lock on the buffer, so that the consumer cannot access the buffer until
producer completes its operation.
 After performing the insert operation, the lock is released and the value of full is
incremented because the producer has just filled a slot in the buffer.
Consumer Operation:
The pseudo code of the CONSUMER function:
do {
wait(full); // wait until full>0 and then decrement ‘full’
wait(mutex); // acquire the lock
/* perform the remove operation in a slot */
signal(mutex); // release the lock
signal(empty); // increment ‘empty’
} while(TRUE);

 The consumer waits until there is at least one full slot in the buffer.
 Then it decrements the full semaphore because the number of occupied slots will be
decreased by one, after the consumer completes its operation.
 After that, the consumer acquires lock on the buffer.
 Following that, the consumer completes the removal operation so that the data from one of
the full slots is removed.
 Then, the consumer releases the lock.
 Finally, the empty semaphore is incremented by 1, because the consumer has just removed
data from an occupied slot, thus making it empty.

2) Reader Writer Problem:

Reader writer problem is another example of a classic synchronization problem. There are
many variants of this problem, one of which is examined below.
Problem Statement:
There is a shared resource which should be accessed by multiple processes. There are two types
of processes in this context. They are reader and writer. Any number of readers can read from
the shared resource simultaneously, but only one writer can write to the shared resource. When
a writer is writing data to the resource, no other process can access the resource.
A writer cannot write to the resource if there are non zero number of readers accessing the
resource.
Solution:
From the above problem statement, it is evident that readers have higher priority than writer. If
a writer wants to write to the resource, it must wait until there are no readers currently
accessing that resource.
Here, we use one mutex m (for lock and unlock) and a semaphore w. An integer
variable read_count is used to maintain the number of readers currently accessing the resource.
The variable read_count is initialized to 0. A value of 1 is given initially to m and w.
Instead of having the process to acquire lock on the shared resource, we use the mutex m to
make the process to acquire and release lock whenever it is updating the read_count variable.
The code for the WRITER process looks like this:
while(TRUE) {
wait(w);
/*perform the write operation */
signal(w);
}
The code for the READER process looks like this:
while(TRUE) {
wait(m); //acquire lock
read_count++;
if(read_count == 1)
wait(w);
signal(m); //release lock
/* perform the reading operation */
wait(m); // acquire lock
read_count--;
if(read_count == 0)
signal(w);
signal(m); // release lock
}
Code Explained:
 As seen above in the code for the writer, the writer just waits on the w semaphore until it
gets a chance to write to the resource.
 After performing the write operation, it increments w so that the next writer can access the
resource.
 On the other hand, in the code for the reader, the lock is acquired whenever
the read_count is updated by a process.
 When a reader wants to access the resource, first it increments the read_count value, then
accesses the resource and then decrements the read_count value.
 The semaphore w is used by the first reader which enters the critical section and the last
reader which exits the critical section.
 The reason for this is, when the first readers enters the critical section, the writer is blocked
from the resource. Only new readers can access the resource now.
 Similarly, when the last reader exits the critical section, it signals the writer using
the w semaphore because there are zero readers now and a writer can have the chance to
access the resource.

3) Dining Philosopher Problem:


The dining philosopher’s problem is another classic synchronization problem which is used to
evaluate situations where there is a need of allocating multiple resources to multiple processes.
Problem Statement:
Consider there are five philosophers sitting around a circular dining table. The dining table has
five chopsticks and a bowl of rice in the middle as shown in the below figure.
Dining Philosophers Problem:

At any instant, a philosopher is either eating or thinking. When a philosopher wants to eat, he
uses two chopsticks - one from their left and one from their right. When a philosopher wants to
think, he keeps down both chopsticks at their original place.
Solution:
From the problem statement, it is clear that a philosopher can think for an indefinite amount of
time. But when a philosopher starts eating, he has to stop at some point of time. The
philosopher is in an endless cycle of thinking and eating.
An array of five semaphores, stick[5], for each of the five chopsticks.
The code for each PHILOSOPHER:
while(TRUE) {
wait(stick[i]);
wait(stick[(i+1) % 5]); // mod is used because if i=5, next
// chopstick is 1 (dining table is circular)
/* eat */
signal(stick[i]);
signal(stick[(i+1) % 5]);
/* think */
}

When a philosopher wants to eat the rice, he will wait for the chopstick at his left and picks up
that chopstick. Then he waits for the right chopstick to be available, and then picks it too. After
eating, he puts both the chopsticks down.
But if all five philosophers are hungry simultaneously, and each of them pickup one chopstick,
then a deadlock situation occurs because they will be waiting for another chopstick forever. The
possible solutions for this are:
 A philosopher must be allowed to pick up the chopsticks only if both the left and right
chopsticks are available.
 Allow only four philosophers to sit at the table. That way, if all the four philosophers pick
up four chopsticks, there will be one chopstick left on the table. So, one philosopher can
start eating and eventually, two chopsticks will be available. In this way, deadlocks can be
avoided.
3.6 CRITICAL REGIONS:
 According to the critical section problem using semaphore all processes must share a
semaphore variable mutex which is initialized to one.
 Each process must execute wait (mutex) before entering the critical section and execute the
signal (mutex) after completing the execution but there are various difficulties may arise
with this approach like:
Case 1: Suppose that a process interchanges the order in which the wait() and signal()
operations on the semaphore mutex are executed, resulting in the following execution:
Signal (mutex);
..........
Critical Section
..........
Wait (mutex);

In this situation several processes may be executing in their critical sections simultaneously,
which is violating mutual exclusion requirement.
Case 2: Suppose that a process replaces the signal (mutex) with wait (mutex). The execution is
as follows:
Wait (mutex);
...........
Critical Section
...........
Wait (mutex);
In this situation a deadlock will occur

Case 3: Suppose that a process omits the wait (mutex) and the signal (mutex). In this case the
mutual exclusion is violated or a deadlock will occur.

3.7 MONITORS:
 Monitor is one of the ways to achieve Process synchronization. Monitor is supported by
programming languages to achieve mutual exclusion between processes.
 It is the collection of condition variables and procedures combined together in a special kind
of module or a package.
 The processes running outside the monitor can’t access the internal variable of monitor but
can call procedures of the monitor.
 Only one process at a time can execute code inside monitors.
 The monitor is a programming-language construct that provides equivalent functionality to
that of semaphores and that is easier to control.
 Even though both the semaphores and monitors are used to achieve mutual exclusion in
parallel programming environments, they differ in the techniques used to achieve this task.
In monitors, the code that is used to achieve mutual exclusion is in a single place and is
more structured, while code for semaphores are distributed as wait and signal function calls.
Also, it is very easy to make mistakes when implementing semaphores, while there is a very
little chance to make mistakes when implementing monitors. Further, monitors use
condition variables, while semaphores do not
 Monitor is a programming language construct that is also used to avoid multiple processes
accessing a common resource at the same time therefore guarantees mutual exclusion.
Monitors use conditional variables to achieve this task.
 It has also been implemented as a program library. This allows programmers to put monitor
locks on any object.
 It is characterized as a set of programmer defined operators. Its representation consists of
declaring of variables, whose value defines the state of an instance.
 The representation of a monitor type cannot be used directly by the various processes. Thus,
a procedure defined within a monitor can access only those variables declared locally within
the monitor and its formal parameters.
 Similarly, the local variables of a monitor can be accessed by only the local procedures. The
syntax of monitor is as follows.

Monitor monitor_name
{
//Shared variable declarations
Procedure body P1 (………) {
........
}
Procedure body P2 (………) {
........
}
.
.
Procedure body Pn (………) {
........
}
{
Initialization Code
}
}

Condition Variables:
Condition variables are synchronization primitives that enable threads to wait until a particular
condition occurs.
Two different operations are performed on the condition variables of the monitor:
1) Wait.
2) Signal.
Let us say we have 2 condition variables
condition x, y; //Declaring variable

Wait operation:
x.wait (): Process performing wait operation on any condition variable is suspended. The
suspended processes are placed in block queue of that condition variable.

Signal operation:
x.signal (): When a process performs signal operation on condition variable, one of the blocked
processes is given chance.
CHAPTER-4
DEADLOCKS
 In a multiprogramming environment several processes may compete for a finite number of
resources.
 A process request resources, if the resource is available at that time a process enters the wait
state.
 Waiting process may never change its state because the resources requested are held by
other waiting process. This situation is known as deadlock.
 A deadlock is a situation in which two computer programs sharing the same resource are
effectively preventing each other from accessing the resource, resulting in both programs
ceasing to function.

DEADLOCK

Examples:

1) Process-1 requests the printer, gets it


Process-2 requests the scanner, gets it
Process-1 requests the scanner, waits
Process-2 requests the printer, waits, deadlocked!

2) A System has 2 disk drives. P1 and P2 each hold one disk drive and each needs another one.

4.1 SYSTEM MODEL:

A system consists of a finite number of resources to be distributed among a number of


competing processes. The resources are partitioned into several types each of which consists of
a number of identical instances. A process may utilize resources in the following sequence:

 Request: In this state one can request a resource. If the request cannot be granted
immediately (for example, if the resource is being used by another process), then the
requesting process must wait until it can acquire the resource.
 Use: The process can operate on the resource (for example, if the resource is a printer,
the process can print on the printer).
 Release: In this state the process releases the resources.
4.2 DEADLOCK CHARACTERIZATION:

In a deadlock process never finish executing and system resources are tied up. A deadlock
situation can arise if the following four conditions hold simultaneously in a system.

1) Mutual Exclusion: At a time only one process can use the resource. If another process
requests that resource, requesting process must wait until the resource has been released.

2) Hold and wait: A process must be holding at least one resource and waiting to additional
resource that is currently held by other processes.
3) No Preemption: Resources allocated to a process can‘t be forcibly taken out from it unless
it releases that resource after completing the task.
4) Circular Wait: There must exist a set {P0, P1, ..., Pn } of waiting processes such that P0 is
waiting for a resource that is held by P1,
P1 is waiting for a resource that is held by P2,
….,
Pn-1 is waiting for a resource that is held by Pn and
Pn is waiting for a resource that is held by P0.

4.3 METHODS FOR HANDLING DEADLOCKS:

The problem of deadlock can deal with the following 3 ways:


1) We can use a protocol to prevent or avoid deadlock ensuring that the system will never
enter to a deadlock state.
2) We can allow the system to enter a deadlock state, detect it and recover.
3) We can ignore the problem all together and pretend that deadlocks would never occur.

To ensure that deadlock never occur the system we can use either deadlock prevention or
deadlock avoidance scheme.
Deadlock prevention provides a set of methods for ensuring that at least one of the necessary
conditions cannot hold. These methods prevent deadlocks by constraining how requests for
resources can be made.
 Deadlock avoidance, on the other hand, requires that the operating system be given in
advance additional information concerning which resources a process will request and use
during its lifetime.
 With this additional knowledge, we can decide for each request whether or not the process
should wait.
 Each request requires that the system consider the resources currently available, the
resources currently allocated to each process, and the future requests and releases of each
process, to decide whether the current request can be satisfied or must be delayed.
 If a system does not employ either a deadlock-prevention or a deadlock avoidance
algorithm, then a deadlock situation may occur.
 If a system does not ensure that a deadlock will never occur, and also does not provide a
mechanism for deadlock detection and recovery, then we may arrive at a situation where the
system is in a deadlock state yet has no way of recognizing what has happened.
4.4 DEADLOCK PREVENTION:
For a deadlock to occur, each of the four necessary-conditions must hold. By ensuring that at
least on one these conditions cannot hold, we can prevent the occurrence of a deadlock.
1) Mutual Exclusion:
The mutual-exclusion condition must hold for non-sharable resources. For example, a
printer cannot be simultaneously shared by several processes. Sharable resources (Ex. read
only files), on the other hand, do not require mutually exclusive access, and thus cannot be
involved in a deadlock.
2) Hold and wait:
In order to ensure that hold and wait condition never holds in the system, we must guarantee
that whenever a process requests a resource it does not hold any other resources. Two
protocols can be used for this:
First protocol: Each process requests and be allocated all of its resources before it begins
execution. This provision can be implemented by requiring that system calls requesting
resources for a particular process precede any other system calls.
Second protocol: A process requests resources only when it has none. A process may
request some resources and use them. Before it can request any additional resources,
however, it must release all the resources that it is currently allocated.
Disadvantages for the above two protocols include:
Low resource utilization Starvation is possible.

3) No Preemption:
In order to ensure that this condition does not hold, the following protocol may be used. If
the process that is holding some resources requests another resource that cannot be
immediately allocated to it (i.e. the process must wait), then all resources currently being
held are preempted i.e. these resources are implicitly released. The preempted resources are
added to the list of resources for which the process is waiting. The process will only be
restarted when it can regain its old resources, as well as the new ones that it is requesting.
4) Circular Wait:
In order to ensure that the circular wait condition never holds, we may impose a total
ordering of all resource types i.e. we assign to each resource type a unique integer number
which allows us to compare two resources and determine whether one precedes another in
our ordering.
4.5 DEADLOCK AVOIDANCE:
 Most prevention algorithms have poor resource utilization, and hence result in reduced
throughputs.
 Instead, we can try to avoid deadlocks by making use prior knowledge about the usage of
resources by processes including resources available, resources allocated, future requests
and future releases by processes.
 Most deadlock avoidance algorithms need every process to tell in advance the maximum
number of resources of each type that it may need.
 Based on all these information we may decide if a process should wait for a resource or not
and thus avoid chances for circular wait.
 If a system is already in a safe state, we can try to stay away from an unsafe state and avoid
deadlock.
 Deadlocks cannot be avoided in an unsafe state. A system can be considered to be in safe
state if it is not in a state of deadlock and can allocate resources up to the maximum
available.
 A safe sequence of processes and allocation of resources ensures a safe state.
 Deadlock avoidance algorithms try not to allocate resources to a process if it will make the
system in an unsafe state.
 Since resource allocation is not done right away in some cases, deadlock avoidance
algorithms also suffer from low resource utilization problem.
 A resource allocation graph is generally used to avoid deadlocks. If there are no
cycles in the resource allocation graph, then there are no deadlocks. If there are cycles,
there may be a deadlock. If there is only one instance of every resource, then a cycle
implies a deadlock. Vertices of the resource allocation graph are resources and
processes. The resource allocation graph has request edges and assignment edges. An
edge from a process to resource is a request edge and an edge from a resource to
process is an allocation edge. A calm edge denotes that a request may be made in future
and is represented as a dashed line. Based on calm edges we can see if there is a chance
for a cycle and then grant requests if the system will again be in a safe state.

Consider the image with calm edges as below:

Resource-allocation graph for deadlock avoidance


If R2 is allocated to p2 and if P1 request for R2, there will be a deadlock.
An unsafe state in a resource-allocation graph.
 The resource allocation graph is not much useful if there are multiple instances for a
resource. In such a case, we can use Banker’s algorithm. In this algorithm, every
process must tell upfront the maximum resource of each type it need, subject to the
maximum available instances for each type. Allocation of resources is made only, if the
allocation ensures a safe state; else the processes need to wait. The Banker’s algorithm
can be divided into two parts: Safety algorithm if a system is in a safe state or not. The
resource request algorithm make an assumption of allocation and see if the system will
be in a safe state. If the new state is unsafe, the resources are not allocated and the data
structures are restored to their previous state; in this case the processes must wait for
the resource.

4.6 DEADLOCK DETECTION:


If deadlock prevention and avoidance are not done properly, as deadlock may occur
and only things left to do is to detect the recover from the deadlock.

If all resource types has only single instance, then we can use a graph called wait-for-
graph, which is a variant of resource allocation graph. Here, vertices represent
processes and a directed edge from P1 to P2 indicates that P1 is waiting for a resource
held by P2. Like in the case of resource allocation graph, a cycle in a wait-for-graph
indicates a deadlock. So the system can maintain a wait-for-graph and check for
cycles periodically to detect any deadlocks.

The wait-for-graph is not much useful if there are multiple instances for a resource, as
a cycle may not imply a deadlock. In such a case, we can use an algorithm similar to
Banker’s algorithm to detect deadlock.
4.7 RECOVERY FROM DEADLOCKS:

When a detection algorithm determines that a deadlock exists, several alternatives exist. One
possibility is to inform the operator that a deadlock has occurred, and to let the operator deal
with the deadlock manually. The other possibility is to let the system recover from the deadlock
automatically. There are two options for breaking a deadlock. One solution is simply to abort
one or more processes to break the circular wait. The second option is to preempt some
resources from one or more of the deadlocked processes.

1) Process Termination:
To eliminate deadlocks by aborting a process, we use one of two methods. In both methods,
the system reclaims all resources allocated to the terminated processes.
 Abort all deadlocked processes: This method clearly will break the deadlock cycle, but at a
great expense; these processes may have computed for a long time, and the results of these
partial computations must be discarded and probably recomputed later.
 Abort one process at a time until the deadlock cycle is eliminated: This method incurs
considerable overhead, since after each process is aborted, a deadlock detection algorithm
must be invoked to determine whether any processes are still deadlocked.

2) Resource Preemption:
To eliminate deadlocks using resource preemption, we successively preempt some resources
from processes and give these resources to other processes until the deadlock cycle is
broken. If preemption is required to deal with deadlocks, then three issues need to be
addressed.
 Selecting a victim: Which resources and which processes are to be preempted?
 Rollback: If we preempt a resource from a process, what should be done with that process?
Clearly, it cannot continue with its normal execution; it is missing some needed resource.
We must rollback the process to some safe state, and restart it from that state.
 Starvation: In a system where victim selection is based primarily on cost factors, it may
happen that the same process is always picked as a victim. As a result, this process never
completes its designated task, a starvation situation that needs to be dealt with in any
practical system. Clearly, we must ensure that a process can be picked as a victim only a
small finite number of times. The most common solution is to include the number of
rollbacks in the cost factor.
CHAPTER-5
MEMORY MANAGEMENT
Memory Management:
 Memory management refers to management of Primary Memory or Main Memory. Main
memory is a large array of words or bytes where each word or byte has its own address.
 Main memory provides a fast storage that can be accessed directly by the CPU. For a
program to be executed, it must in the main memory. An Operating System does the
following activities for memory management −
1) Keeps tracks of primary memory, i.e., what part of it are in use by whom, what part is not in
use.
2) In multiprogramming, the OS decides which process will get memory when and how much.
3) Allocates the memory when a process requests it to do so.
4) De-allocates the memory when a process no longer needs it or has been terminated.
 Memory consists of a large array of words or bytes, each with its own address. The CPU
fetches instructions from memory according to the value of the program counter. These
instructions may cause additional loading from and storing to specific memory addresses.
 Memory unit sees only a stream of memory addresses. It does not know how they are
generated. Program must be brought into memory and placed within a process for it to be
run.
 Memory management is the functionality of an operating system which handles or manages
primary memory and moves processes back and forth between main memory and disk
during execution.

5.1 LOGICAL VERSUS PHYSICAL ADDRESS:


 The concept of a logical address space that is bound to a separate physical address space is
central to proper memory management.
 Logical address – Address generated by the CPU; also referred to as virtual address.
 Physical address – Address seen by the memory unit.
 The set of all logical addresses generated by a program is a logical address space.
 The set of all physical addresses corresponding to these logical addresses are a physical
address space.
 The run-time mapping from logical (virtual) to physical addresses is done by a hardware
device called the memory management unit (MMU).
 The base register is also called a relocation register.

Dynamic relocation using relocation register.


 The value in the relocation register is added to every address generated by a user process at
the time it is sent to memory.
 The user program never sees the real physical addresses. The program can create a pointer to
location 346, store it in memory, manipulate it and compare it to other addresses. The user
program only deals with logical addresses.
 The memory mapping hardware converts logical addresses into physical addresses. The final
location of a referenced memory address is not determined until the reference is made.

Comparison Chart:

BASIS FOR
LOGICAL ADDRESS PHYSICAL ADDRESS
COMPARISON

Basic It is the virtual address generated The physical address is a location in


by CPU a memory unit.

Address Space Set of all logical addresses Set of all physical addresses
generated by CPU in reference to mapped to the corresponding
a program is referred as Logical logical addresses is referred as
Address Space. Physical Address.

Visibility The user can view the logical The user can never view physical
address of a program. address of program

Access The user uses the logical address The user can not directly access
to access the physical address. physical address.

Generation The Logical Address is generated Physical Address is Computed by


by the CPU MMU

5.2 SWAPPING:
 A process must be in memory to be executed. A process can be swapped temporarily out of
memory to a backing store, and then brought back into memory for continued execution.
 For example, assume a multiprogramming environment with a round robin CPU scheduling
algorithm. When a quantum expires, the memory manager will start to swap out the process
that just finished, and to swap in another process to the memory space that has been freed.
 In the mean time, the CPU scheduler will allocate a time slice to some other process in
memory.
 When each process finished its quantum, it will be swapped with another process. Ideally,
the memory manager can swap processes fast enough that some processes will be in
memory, ready to execute, when the CPU scheduler wants to re-schedule the CPU.
 The quantum must also be sufficiently large that reasonable amounts of computing are done
between swaps.
 Roll out, roll in – A variant of this swapping policy is used for priority-based scheduling
algorithms. If a higher priority process arrives and wants service, the memory manager can
swap out the lower priority process so that it can load and execute higher priority process
and the lower priority process can be swapped back in and continued. This variant is
sometimes called roll out, roll in. Normally a process that is swapped out will be swapped
back into the same memory space that it occupied previously.
 Backing store – Fast disk large enough to accommodate copies of all memory images for all
users; must provide direct access to these memory images. The system maintains a ready
queue consisting of all processes whose memory images.
 Major part of swap time is transfer time; total transfer time is directly proportional to the
amount of memory swapped.
 Modified versions of swapping are found on many systems (i.e., UNIX, Linux, and
Windows).

Swapping of two processes using a disk as a backing store

5.3 CONTIGUOUS MEMORY ALLOCATION:

Contiguous memory allocation is one of the oldest memory allocation schemes. When a process
needs to execute, memory is requested by the process. The size of the process is compared with
the amount of contiguous main memory available to execute the process. If sufficient
contiguous memory is found, the process is allocated memory to start its execution. Otherwise,
it is added to a queue of waiting processes until sufficient free contiguous memory is available.

Main memory usually has two partitions −


 Low Memory − Operating system resides in this memory.
 High Memory − User processes are held in high memory.
Operating system uses the following memory allocation mechanism.

1) Single-partition allocation: In this type of allocation, relocation-register scheme is used to


protect user processes from each other, and from changing operating-system code and data.
The operating system code and data are protected from changes made by the user processes.
We also need protect the user processes from one another. We can provide this protection by
using a relocation register.

2) Multiple-partition allocation: In this type of allocation, main memory is divided into a


number of fixed-sized partitions where each partition should contain only one process. When a
partition is free, a process is selected from the input queue and is loaded into the free partition.
When the process terminates, the partition becomes available for another process.
5.4 PAGING:
 Fragmentation occurs in a dynamic memory allocation system when most of the free blocks
are too small to satisfy any request. It is generally termed as inability to use the available
memory.
 In such situation processes are loaded and removed from the memory. As a result of this,
free blocks exists to satisfy a request but is non contiguous i.e. the memory is fragmented
into large no. of small blocks. This phenomenon is known as External Fragmentation.
 Also, at times the physical memory is broken into fixed size blocks and memory is allocated
in unit of block sizes. The memory allocated to a space may be slightly larger than the
requested memory. The difference between allocated and required memory is known
as Internal Fragmentation i.e. the memory that is internal to a partition but is of no use.
 A solution to fragmentation problem is paging. Paging is a memory management
mechanism that allows the physical address space of a process to be non-contiguous. Here
physical memory is divided into blocks of equal size called Pages. The pages belonging to a
certain process are loaded into available memory frames.
 A computer can address more memory than the amount physically installed on the system.
This extra memory is actually called virtual memory and it is a section of a hard disk that's
set up to emulate the computer's RAM. Paging technique plays an important role in
implementing virtual memory.
 Paging is a memory management technique in which the memory is divided into fixed size
pages. Paging is used for faster access to data. When a program needs a page, it is available
in the main memory as the OS copies a certain number of pages from your storage device to
main memory. Paging allows the physical address space of a process to be non-contiguous.
 Paging is a memory management technique in which process address space is broken into
blocks of the same size called pages (size is power of 2, between 512 bytes and 8192 bytes).
The size of the process is measured in the number of pages.
 Similarly, main memory is divided into small fixed-sized blocks of (physical) memory
called frames and the size of a frame is kept the same as that of a page to have optimum
utilization of the main memory and to avoid external fragmentation.
 The mapping from virtual to physical address is done by the memory management unit
(MMU) which is a hardware device and this mapping is known as paging technique.
 The Physical Address Space is conceptually divided into a number of fixed-size blocks,
called frames.
 The Logical address Space is also splitted into fixed-size blocks, called pages.
 Page Size = Frame Size

 Address generated by CPU (Logical Address) is divided into:


 Page number(p): Number of bits required to represent the pages in Logical Address
Space or Page number
 Page offset(d): Number of bits required to represent particular word in a page or page
size of Logical Address Space or word number of a page or page offset.

 Physical Address is divided into:


 Frame number(f): Number of bits required to represent the frame of Physical Address
Space or Frame number.
 Frame offset(d): Number of bits required to represent particular word in a frame or
frame size of Physical Address Space or word number of a frame or frame offset.
Address Translation:
 Page address is called logical address and represented by page number and the offset.
Logical Address = Page number + page offset
 Frame address is called physical address and represented by a frame number and
the offset.
Physical Address = Frame number + frame offset
 A data structure called page map table is used to keep track of the relation between a page
of a process to a frame in physical memory.

 When the system allocates a frame to any page, it translates this logical address into a
physical address and creates entry into the page table to be used throughout execution of the
program.
 When a process is to be executed, its corresponding pages are loaded into any available
memory frames. Suppose you have a program of 8Kb but your memory can accommodate
only 5Kb at a given point in time, then the paging concept will come into picture.
 When a computer runs out of RAM, the operating system (OS) will move idle or unwanted
pages of memory to secondary memory to free up RAM for other processes and brings them
back when needed by the program.
 This process continues during the whole execution of the program where the OS keeps
removing idle pages from the main memory and write them onto the secondary memory and
bring them back when required by the program.
Advantages and Disadvantages of Paging:

 Paging reduces external fragmentation, but still suffers from internal fragmentation.
 Paging is simple to implement and assumed as an efficient memory management technique.
 Due to equal size of the pages and frames, swapping becomes very easy. Page table requires
extra memory space, so may not be good for a system having small RAM.

5.5 STRUCTURE OF THE PAGE TABLE:


 A Page Table is the data structure used by a virtual memory system in a computer operating
system to store the mapping between virtual address and physical addresses.
 Virtual address is also known as Logical address and is generated by the CPU. While
Physical address is the address that actually exists on memory.

Hierarchical Paging:
 A logical address (on 32-bit machine with 4K(2^12=4096) page size) is divided into:
 A page number consisting of 20 bits.
 A page offset consisting of 12 bits (2^12).

 Since the page table is paged, the page number is further divided into:
 A 10-bit page number.
 A 10-bit page offset (2^10).

 Thus, a logical address is as follows:

Where p1 is a page number (index) into the page


table, and p2 is the offset (displacement) within the page of the page table.

5.6 SEGMENTATION:

A program is a collection of segments. A segment is a logical unit such as:


Main program, Procedure, Function, Method, Object, Local variables, Global variables,
Common block Stack Symbol table, Arrays
 Segmentation is a memory management technique in which each job is divided into several
segments of different sizes, one for each module that contains pieces that perform related
functions. Each segment is actually a different logical address space of the program.
 When a process is to be executed, its corresponding segmentation is loaded into non-
contiguous memory though every segment is loaded into a contiguous block of available
memory.
 Segmentation in memory management works very similar to paging but here segments are
of variable-length where as in paging pages are of fixed size.
 A program segment contains the program's main function, utility functions, data structures,
and so on. The operating system maintains a segment map table for every process and a list
of free memory blocks along with segment numbers, their size and corresponding memory
locations in main memory.
 For each segment, the table stores the starting address of the segment and the length of the
segment. A reference to a memory location includes a value that identifies a segment and an
offset.

SEGMENTATION

5.7 VIRTUAL MEMORY:


 A computer can address more memory than the amount physically installed on the system.
This extra memory is actually called virtual memory and it is a section of a hard disk that's
set up to emulate the computer's RAM.
 The main visible advantage of this scheme is that programs can be larger than physical
memory. Virtual memory serves two purposes. First, it allows us to extend the use of
physical memory by using disk. Second, it allows us to have memory protection, because
each virtual address is translated to a physical address.
Following are the situations, when entire program is not required to be loaded fully in main
memory:

 User written error handling routines are used only when an error occurred in the data or
computation.
 Certain options and features of a program may be used rarely.
 Many tables are assigned a fixed amount of address space even though only a small amount
of the table is actually used.
The ability to execute a program that is only partially in memory would counter many
benefits:
 Less number of I/O would be needed to load or swap each user program into memory.
 A program would no longer be constrained by the amount of physical memory that is
available.
 Each user program could take less physical memory; more programs could be run the same
time, with a corresponding increase in CPU utilization and throughput.

Modern microprocessors intended for general-purpose use, a memory management unit, or


MMU, is built into the hardware. The MMU's job is to translate virtual addresses into physical
addresses. A basic example is given below −

VIRTUAL MEMORY
Virtual memory is commonly implemented by demand paging. It can also be implemented in a
segmentation system. Demand segmentation can also be used to provide virtual memory.

5.8 DEMAND PAGING:


 A demand paging system is quite similar to a paging system with swapping where processes
reside in secondary memory and pages are loaded only on demand, not in advance.
 When a context switch occurs, the operating system does not copy any of the old program’s
pages out to the disk or any of the new program’s pages into the main memory.
 Instead, it just begins executing the new program after loading the first page and fetches that
program’s pages as they are referenced.

DEMAND PAGING
While executing a program, if the program references a page which is not available in the main
memory because it was swapped out a little ago, the processor treats this invalid memory
reference as a page fault and transfers control from the program to the operating system to
demand the page back into the memory.

Advantages of Demand Paging:


 Large virtual memory.
 More efficient use of memory.
 There is no limit on degree of multiprogramming.
Disadvantages of Demand Paging:
 Number of tables and the amount of processor overhead for handling page interrupts are
greater than in the case of the simple paged management techniques.

5.9 PAGE REPLACEMENT:

 Page replacement algorithms are the techniques using which an Operating System which
decides which memory pages to swap out, write to disk when a page of memory needs to be
allocated.
 In an operating system that uses paging for memory management, page replacement
algorithms are needed to decide which page needed to be replaced when new page comes in.
Whenever a new page is referred and not present in memory, page fault occurs.
 When the page (data) requested by a program is not available in the memory, it is called as a
page fault. A page fault occurs when a program accesses a page that has been mapped in
address space, but has not been loaded in the physical memory.
 Paging happens whenever a page fault occurs and a free page cannot be used for allocation
purpose accounting to reason that pages are not available or the number of free pages is
lower than required pages.
 When the page that was selected for replacement and was paged out, is referenced again, it
has to read in from disk, and this requires for I/O completion. This process determines the
quality of the page replacement algorithm: the lesser the time waiting for page-ins, the better
is the algorithm.
 A page replacement algorithm looks at the limited information about accessing the pages
provided by hardware, and tries to select which pages should be replaced to minimize the
total number of page misses, while balancing it with the costs of primary storage and
processor time of the algorithm itself.
 There are many different page replacement algorithms. We evaluate an algorithm by running
it on a particular string of memory reference and computing the number of page faults.

Reference String:

The string of memory references is called reference string. Reference strings are generated
artificially or by tracing a given system and recording the address of each memory reference.
The latter choice produces a large number of data, where we note two things.

 For a given page size, we need to consider only the page number, not the entire address.
 If we have a reference to a page p, then any immediately following references to page p will
never cause a page fault. Page p will be in memory after the first reference; the immediately
following references will not fault.
 For example, consider the following sequence of addresses − 123,215,600,1234,76,96
 If page size is 100, then the reference string is 1,2,6,12,0,0

Page Replacement Algorithms:

1) First in First Out (FIFO) algorithm:


 Oldest page in main memory is the one which will be selected for replacement.
 Easy to implement, keep a list, replace pages from the tail and add new pages at the head.

2) Optimal Page algorithm:


 An optimal page-replacement algorithm has the lowest page-fault rate of all algorithms. So
it is the best page replacement algorithm. An optimal page-replacement algorithm exists,
and has been called OPT or MIN.
 Replace the page that will not be used for the longest period of time. Use the time when a
page is to be used.

3) Least Recently Used (LRU) algorithm:


 In this algorithm page will be replaced which is least recently used.
 Easy to implement, keep a list, replace pages by looking back into time.
4) Page buffering algorithm:
 To get a process start quickly, keep a pool of free frames. On page fault, select a page to be
replaced.
 Write the new page in the frame of free pool, mark the page table and restart the process.
 Now write the dirty page out of disk and place the frame holding replaced page in free
pool.
5) Least frequently Used (LFU) algorithm:
 The page with the smallest count is the one which will be selected for replacement.
 This algorithm suffers from the situation in which a page is used heavily during the initial
phase of a process, but then is never used again.
6) Most frequently Used (MFU) algorithm:
The page with the largest count is the one which will be selected for replacement.

5.10 ALLOCATION OF FRAMES:

 We turn next to the issue of allocation. How do we allocate the fixed amount of free
memory among the various processes? If we have 93 free frames and two processes, how
many frames does each process get?
 The simplest case is the single-user system. Consider a single-user system with 128 KB of
memory composed of pages 1 KB in size. This system has 128 frames.
 The operating system may take 35 KB, leaving 93 frames for the user process.
 Under pure demand paging, all 93 frames would initially be put on the free-frame list. When
a user process started execution, it would generate a sequence of page faults.
 The first 93 page faults would all get free frames from the free-frame list. When the free-
frame list was exhausted, a page-replacement algorithm would he used to select one of the
93 in-memory pages to be replaced with the 94th, and so on.
 When the process terminated, the 93 frames would once again be placed on the free-frame
list. There are many variations on this simple strategy. We can require that the operating
system allocate all its buffer and table space from the free-frame list.
 When this space is not in use by the operating system/ it can be used to support user paging.
We can try to keep three free frames reserved on the free-frame list at all times.
 Thus, when a page fault occurs, there is a free frame available to page into. While the page
swap is taking place, a replacement can be selected, which is then written to the disk as the
user process continues to execute. Other variants are also possible, but the basic strategy is
clear: The user process is allocated any free frame.

5.11 THRASHING:
 When a process does not have enough pages: 1. The page-fault rate is very high 2. Low CPU
utilization 3. OS thinks it needs increased multiprogramming 4. Adds another process to
system
 Thrashing is when a process is busy swapping pages in and out. Thrashing results in severe
performance problems.
 A process that is spending more time paging than executing is said to be thrashing. In other
words it means that the process doesn't have enough frames to hold all the pages for its
execution, so it is swapping pages in and out very frequently to keep executing.
 Sometimes, the pages which will be required in the near future have to be swapped out.
 Initially when the CPU utilization is low, the process scheduling mechanism, to increase the
level of multiprogramming loads multiple processes into the memory at the same time,
allocating a limited amount of frames to each process.
 As the memory fills up, process starts to spend a lot of time for the required pages to be
swapped in, again leading to low CPU utilization because most of the processes are waiting
for pages.
 Hence the scheduler loads more processes to increase CPU utilization, as this continues at a
point of time the complete system comes to a stop. To prevent thrashing we must provide
processes with as many frames as they really need "right now".

5.12 MEMORY-MAPPED FILES:

 Consider a sequential read of a file on disk using the standard system calls open(), read(),
and write().
 Each file access requires a system call and disk access. This approach is known as memory
mapping a file, allows a part of the virtual address space to be logically associated with the
file.

Basic Mechanism:
 Memory mapping a file is accomplished by mapping a disk block to a page (or pages) in
memory. Initial access to the file proceeds through ordinary demand paging, resulting in a
page fault. However, a page-sized portion of the file is read from the file system into a
physical page. Subsequent reads and writes to the file are handled as routine memory
accesses, thereby simplifying file access and usage by allowing the system to manipulate
files through memory rather than incurring the overhead of using the read() and write()
system calls. Note that writes to the file mapped in memory are not necessarily immediate
(synchronous) writes to the file on disk. Some systems may choose to update the physical
file when the operating system periodically checks whether the page in memory has been
modified. When the file is closed, all the memory-mapped data are written back to disk and
removed from the virtual memory of the process. Some operating systems provide memory
mapping only through a specific system call and use the standard system calls to perform
all other file I/O. However, some systems choose to memory-map a file regardless of
whether the file was specified as memory-mapped.
 Let's take Solaris as an example. If a file is specified as memory-mapped (using the
mmap() system call), Solaris maps the file into the address space of the process. If a file is
opened and accessed using ordinary system calls, such as open(), read(), and write(),
Solaris still memory-maps the file; however, the file is mapped to the kernel address space.
Regardless of how the file is opened, then, Solaris treats all file I/O as memory-mapped,
allowing file access to take place via the efficient memory subsystem. Multiple processes
may be allowed to map the same file concurrently, to allow sharing of data. Writes by any
of the processes modify the data in virtual memory and can be seen by all others that map
the same section of the file.
CHAPTER-6
FILE SYSTEMS, IMPLEMENTATION, AND SECONDARY-STORAGE STRUCTURE

6.1 CONCEPT OF A FILE


 A file is a collection of related information that is stored on secondary storage.
 Information stored in files must be persistent i.e. not affected by power failures & system
reboots.
 Files represent both programs as well as data. Part of the OS dealing with the files is known
as file system.

The important file concepts include:


1. File attributes: A file has certain attributes which vary from one operating system to
another.
 Name: Every file has a name by which it is referred.
 Identifier: It is unique number that identifies the file within the file system.
 Type: This information is needed for those systems that support different types of files.
 Location: It is a pointer to a device & to the location of the file on that device
 Size: It is the current size of a file in bytes, words or blocks.
 Protection: It is the access control information that determines who can read, write &
execute a file.
 Time, date & user identification: It gives information about time of creation or last
modification & last use.

2. File operations: The operating system can provide system calls to create, read, write,
reposition, delete and truncate files.
 Creating files: Two steps are necessary to create a file. First, space must be found for the
file in the file system. Secondly, an entry must be made in the directory for the new file.
 Reading a file: Data are read from the file at the current position. The system must keep a
read pointer to know the location in the file from where the next read is to take place. Once
the read has been taken place, the read pointer is updated.
 Writing a file: Data are written to the file at the current position. The system must keep a
write pointer to know the location in the file where the next write is to take place. The
write pointer must be updated whenever a write occurs.
 Repositioning within a file (seek): The directory is searched for the appropriate entry &
the current file position is set to a given value. After repositioning data can be read from or
written into that position.
 Deleting a file: To delete a file, we search the directory for the required file. After deletion,
the space is released so that it can be reused by other files.
 Truncating a file: The user may erase the contents of a file but allows all attributes to
remain unchanged expect the file length which is reset to zero & the file space is released.

3. File types: The file name is spilt into 2 parts: Name & extension. Usually these two parts are
separated by a period.
The user & the OS can know the type of the file from the extension itself.
Listed below are some file types along with their extension:
File Type Extension
1) Executable File exe, bin, com (run machine
language program)
2) Object File obj, o (compiled, machine
language)
3) Source Code file C, C++, Java, pas (Source code in
various language)
4) Batch File bat, sh (commands to the
interpreter)
5) Text File txt, doc (textual data, documents)
6) Archive File arc, zip, tar (related files grouped
together into file compressed for
storage)
7) Multimedia File mpeg (Binary file containing
audio or A/V information)

6.2 ACCESS METHODS


Basically, access method is divided into 2 types:

1) Sequential access: It is the simplest access method. Information in the file is processed in
order i.e. one record after another. A process can read all the data in a file in order starting
from beginning but can‘t skip & read arbitrarily from any location. Sequential files can be
rewound. It is convenient when storage medium was magnetic tape rather than disk.
2) Direct access: A file is made up of fixed length-logical records that allow programs to read
& write records rapidly in no particular order. This method can be used when disks are used
for storing files. This method is used in many applications e.g. database systems. If an
airline customer wants to reserve a seat on a particular flight, the reservation program must
be able to access the record for that flight directly without reading the records before it. In a
direct access file, there is no restriction in the order of reading or writing. For example, we
can read block 14, then read block 50 & then write block 7 etc. Direct access files are very
useful for immediate access to large amount of information.

6.3 DIRECTORY STRUCTURE

A directory is a location for storing files on your computer. The file system of computers can be
extensive. Some systems store thousands of file on disk. To manage all these data, we need to
organize them. This organization involves the use of directories.

Operations on a directory:
 Search for a file: We need to be able to search a directory for a particular file.
 Create a file: New files are created & added to the directory.
 Delete a file: When a file is no longer needed, we may remove it from the directory.
 List a directory: We should be able to list the files of the directory.
 Rename a file: The name of a file is changed when the contents of the file changes.
 Traverse the file system: It is useful to be able to access every directory & every file within
a directory.

Structure of a directory:
The most common schemes for defining the structure of the directory are:

1) Single level directory: The simplest directory structure is the single level directory. All files
are contained in the same directory which is easy to support and understand. But this
implementation has limitations when the number of files increases or when the system has
more than one user. Since all files are in same directory, all files names must be unique.
Keeping track of so many files is a difficult task. A single user on a single level directory
may find it difficult to remember the names of all the files as the number of files increases.

2) Two level directory:


In the two level directory structures, each user has his own user file directory (UFD). The
UFD’s have similar structures but each lists only the files of a single user. When a user job
starts or a user logs in, the system’s master file directory (MFD) is searched. The MFD is
indexed by user name or account number and each entry points to the UFD for that user.
When a user refers to a particular file, only his own UFD is searched. Different users may
have files with the same name as long as all the files names within each UFD are unique.

Root of the tree is MFD. Its direct descendants are UFDs. The descendants of the UFDs are
the files themselves. The files are the leaves of the tree. The sequence of directories searched
when a file is names is called the search path. Although the two level directory structures
solves the name collision problem, it still has disadvantages. This structure isolates on user
from another. Isolation is an advantage when the users are completely independent but a
disadvantage when the users want to cooperate on some task and to access one another’s
files.
3) Tree Structured Directories: Here, we extend the two level directories to a tree of arbitrary
height. This generalization allows users to create their own subdirectories and to organize
their files accordingly. A tree is the most common directory structure. The tree has a root
directory and every file in the system has a unique path name. A directory contains a set of
files or sub directories.

Each process has a current directory. The current directory should contain most of the files that
are of current interest to the process. Path names can be of two types – absolute and relative. An
absolute path name begins at the root and follows a path down to the specified file giving the
directory names on the path. A relative path name defines a path from the current directory.
Deletion of directory under tree structured directory – If a directory is empty, its entry in the
directory that contains it can simply be deleted. If the directory to be deleted is not empty, then
use one of the two approaches –
 User must first delete all the files in that directory
 If a request is made to delete a directory, the entire directory’s files and sub directories are
also to be deleted.
A path to a file in a tree structured directory can be longer than a path in a two level directory.

4) Acyclic graph directories: A tree structure prohibits the sharing of files and directories. An
acyclic graph i.e. a graph with no cycles allows directories to share subdirectories and files. The
same file or subdirectory may be in two different directories. With a shared file, only one actual
file exists. Sharing is particularly important for subdirectories. Shared files and subdirectories
can be implemented in several ways. One way is to create a new directory entry called a link. A
link is a pointer to another file or subdirectory. Another approach in implementing shared files
is to duplicate all information about them in both sharing directories. An acyclic graph directory
structure is flexible than a tree structure but it is more complex. Several problems may exist
such as multiple absolute path names or deletion.
5) General graph directory: A problem with using an acyclic graph structure is ensuring that
there are no cycles.

The primary advantage of an acyclic graph is the relative simplicity of the algorithms to
traverse the graph and to determine when there are no more references to a file. If cycles are
allowed to exist in the directory, we can avoid searching any component twice. A similar
problem exists when we are trying to determine when a file can be deleted. The difficulty is to
avoid cycles as new links are added to the structure.

6.4 PROTECTION
When information is kept in a computer system, a major concern is its protection from physical
damage (reliability) as well as improper access.
Types of access: In case of systems that don‘t permit access to the files of other users.
Protection is not needed. So, one extreme is to provide protection by prohibiting access. The
other extreme is to provide free access with no protection. Both these approaches are too
extreme for general use. So, we need controlled access. It is provided by limiting the types of
file access. Access is permitted depending on several factors. One major factor is type of access
requested.
The different types of operations that can be controlled are:
Read, Write, Execute, Append, List, Delete
 Read: Read from the file.
 Write: Write or rewrite the file.
 Execute: Load the file into memory and execute it.
 Append: Write new information at the end of the file.
 Delete: Delete the file and tree its space for possible reuse.
 List: List the name and attributes of the file.
Access lists and groups: Various users may need different types of access to a file or directory.
So, we can associate an access lists with each file and directory to implement identity
dependent access. When a user requests access to a particular file, the OS checks the access list
associated with that file. If that user is granted the requested access, then the access is allowed.
Otherwise, a protection violation occurs & the user is denied access to the file. But the main
problem with access lists is their length. So, we use a condensed version of the access list by
classifying the users into 3 categories:

 Owners: The user who created the file.


 Group: A set of users who are sharing the files.
 Others: All other users in the system.
Here only 3 fields are required to define protection. Each field is a collection of bits each of
which either allows or prevents the access. E.g. The UNIX file system defines 3 fields of 3 bits
each: rwx
 r( read access)
 w(write access)
 x(execute access)
Separate fields are kept for file owners, group & other users. So, a bit is needed to record
protection information for each file.

6.5 FILE SYSTEM STRUCTURE


Disk is a round plate on which data can be encoded. Disks provide the bulk of secondary
storage on which a file system is maintained. They have two characteristics that make them a
convenient medium for storing multiple files:
 A disk can be rewritten in place: it is possible to read a block from the disk, modify the
block and write it back into the same place.
 A disk an access directly any given block of information it contains. It is simple to access
any file sequentially or randomly and switching from one file to another requires only
moving the read – write heads and waiting for the disk to rotate.
Rather than transferring a byte at a time, to improve I/O efficiency, I/O transfers between
memory and disk are performed in units of blocks. Each block has one or more sectors. To
provide efficient and convenient access to the disk, OS imposes one or more file systems to
allow the data to be stored, located and retrieved easily. The file system is composed of many
different levels –
Layered File System Structure
 Each level in the design uses the features of lower levels to create new features for use by
higher levels.
 The lowest level, I/O control consists of device drivers and interrupts handlers to transfer
information between the main memory and the disk system.
 The basic file system needs to issue generic commands to appropriate device driver to read
and write physical blocks on the disk.
 The file organization module knows about files and their logical blocks as well as physical
blocks. Maintains the list of free blocks, and allocates free blocks to files as needed.
 The logical file system manages metadata information. Metadata includes all of the file
system structure except the actual data.
 A file control block contains information about the file including ownership, permissions
and location of the file contents.
6.6 ALLOCATION METHODS
There are 3 methods of allocating disk space which are widely used.
1. Contiguous allocation:
 It requires each file to occupy a set of contiguous blocks on the disk.
 Number of disk seeks required for accessing contiguously allocated file is minimum.
 The IBM VM/CMS OS uses contiguous allocation. Contiguous allocation of a file is defined
by the disk address and length (in terms of block units).
 If the file is ‘n’ blocks long and starts all location ‘b‘, then it occupies blocks b, b+1, b+2,---
--------- - -b+ n-1.
 The directory for each file indicates the address of the starting block and the length of the
area allocated for each file.
 Contiguous allocation supports both sequential and direct access. For sequential access, the
file system remembers the disk address of the last block referenced and reads the next block
when necessary.
 For direct access to block ‘i’ of a file that starts at block b we can immediately access block
b + i.
 Limitations: One difficulty with contiguous allocation is finding space for a new file. It also
suffers from the problem of external fragmentation. As files are deleted and allocated, the
free disk space is broken into small pieces. A major problem in contiguous allocation is how
much space is needed for a file. When a file is created, the total amount of space it will need
must be found and allocated. Even if the total amount of space needed for a file is known in
advances, pre-allocation is inefficient. Because a file that grows very slowly must be
allocated enough space for its final size even though most of that space is left unused for a
long period time. Therefore, the file has a large amount of internal fragmentation.

2. Linked Allocation:
 Linked allocation solves all problems of contiguous allocation.
 In linked allocation, each file is linked list of disk blocks, which are scattered throughout
the disk.
 The directory contains a pointer to the first and last blocks of the file.
 Each block contains a pointer to the next block.
 These pointers are not accessible to the user. To create a new file, we simply create a new
entry in the directory.
 For writing to the file, a free block is found by the free space management system and this
new block is written to & linked to the end of the file.
 To read a file, we read blocks by following the pointers from block to block.
 There is no external fragmentation with linked allocation & any free block can be used to
satisfy a request.
 Also there is no need to declare the size of a file when that file is created. A file can
continue to grow as long as there are free blocks.
 Limitations: It can be used effectively only for sequential access files. To find the ‘i’th
block of the file, we must start at the beginning of that file and follow the pointers until we
get the ‘i’th block. So it is inefficient to support direct access files. Due to the presence of
pointers each file requires slightly more space than before. Another problem is reliability.
Since the files are linked together by pointers scattered throughout the disk. What would
happen if a pointer were lost or damaged?

3. Indexed Allocation:
 Indexed allocation solves the problem of linked allocation by bringing all the pointers
together to one location known as the index block.
 Each file has its own index block which is an array of disk block addresses. The ‘i’th entry
in the index block points to the ‘i’th block of the file.
 The directory contains the address of the index block. The read the ‘i’th block, we use the
pointer in the ‘i’th index block entry and read the desired block.
 To write into the ‘i’th block, a free block is obtained from the free space manager and its
address is put in the ‘i’th index block entry.
 Indexed allocation supports direct access without suffering external fragmentation.
 Limitations: The pointer overhead of index block is greater than the pointer overhead of
linked allocation. So here more space is wasted than linked allocation. In indexed
allocation, an entire index block must be allocated, even if most of the pointers are nil.

6.7 FREE SPACE MANAGEMENT


Since there is only a limited amount of disk space, it is necessary to reuse the space from the
deleted files. To keep track of free disk space, the system maintains a free space list. It records
all the disk blocks that are free i.e. not allocated to some file or dictionary. To create a file, we
search the free space list for the required amount of space and allocate it to the new file. This
space is then removed from the free space list. When a file is deleted, its disk space is added to
the free space list.

Implementation:
There are 4 ways to implement the free space list such as:
1) Bit Vector: The free space list is implemented as a bit map or bit vector. Each block is
represented as 1 bit. If the block is free, the bit is 1 and if it is allocated then the bit is 0. For
example, consider a disk where blocks 2, 3, 4, 5, 8, 9, 10, 11, 12, 13, 17, 18, 25, 26 & 27 are
free and rest of the blocks are allocated. The free space bit map would be
0011110011111100011000000111…………………….. The main advantage of this
approach is that it is simple and efficient to find the first free block or n consecutive free
blocks on the disk. But bit vectors are inefficient unless the entire vector is kept in main
memory. It is possible for smaller disks but not for larger ones.
2) Linked List: Another approach is to link together all the free disk blocks and keep a pointer
to the first free block. The first free block contains a pointer to the next free block and so on.
For example, we keep a pointer to block 2 as the free block. Block 2 contains a pointer to
block which points to block 4 which then points to block 5 and so on. But this scheme is not
efficient. To traverse the list, we must read each block which require a lot of I/O time.

3) Grouping: In this approach, we store the address of ‘n’ free blocks in the first free block.
The first n-1 of these blocks is actually free. The last block contains the address of another
‘n’ free block and so on. Here the addresses of a large number of free blocks can be found
out quickly.
4) Counting: Rather than keeping a list of n free disk block addresses, we can keep the address
of the first free block and the number of free contiguous blocks. So here each entry in the
free space list consists of a disk address and a count.

6.8 DIRECTORY MANAGEMENT


Directory Management Functions:
1) chdir — Change directory
2) chroot — Change the root directory
3) closedir — Close directory handle
4) dir — Return an instance of the Directory class
5) getcwd — Gets the current working directory
6) opendir — Open directory handle
7) readdir — Read entry from directory handle
8) scandir — List files and directories inside the specified path

6.9 DEVICE DRIVERS


 A device driver is a program routine that links a peripheral device to an operating system of
a computer. It is essentially a software program that allows a user to employ a device, such
as a printer, monitor, or mouse
 It is written by programmers who comprehend the detailed knowledge of the device’s
command language and characteristics and contains the specific machine language
necessary to perform the functions requested by the application.
 When a new hardware device is added to the computer, such as a CD-ROM drive, a printer,
or a sound card, its driver must be installed in order to run it. The operating system “calls”
the driver, and the driver “drives” the device. In Windows, for example, everything that is
seen on the screen is the result of the display driver (video driver).
 The display driver effectuates the visual appearance of the screen according to the precise
commands that Windows issues to it .The driver is the link between the operating system
and the peripheral device. If the peripheral device is changed, or if a bug is found in the
driver, the driver must also be changed.
 A new version of the driver is then written and released by the manufacturer of the device.
Updated drivers are usually made available on the Web sites and/or bulletin boards of
vendors. The basic input/output (I/O) hardware features, such as ports, buses, and device
controllers, accommodate a wide variety of I/O devices.
 To encapsulate the details and unique features of different devices, the kernel of an
operating system is set up to use device driver modules. The device drivers present a
uniform device-access interface to the I/O subsystem.

6.10 OVERVIEW OF MASS-STORAGE STRUCTURE


 Mass storage devices are those devices on your system available for storing large amounts
of data.
 Disks provide a bulk of secondary storage. Disks come in various sizes, speed and
information can be stored optically or magnetically. Modern disks are organized as single
one-dimensional array of logical blocks.
 Magnetic tapes were used early as secondary storage but the access time is less than disk.
 Hard disk storage drives are mainly found in computers. These storage devices have the
largest data storage capacity when compared to other devices. Hard drives permanently
retain any data recorded on them. Typically, they contain software applications, an operating
system, files and folders.
 RAM or main memory is the most important storage device. It's a temporary form of storage
commonly known as volatile storage, which implies that the data stored in this device is lost
if power is turned off.
 USB flash drives are pocket-sized hard drives used to store and transport files and folders.
They also are used to backup or archive important data. These storage devices are connected
to computers through USB sockets.
 Optical drives include CD drives and DVD drives. Data is written to the disks through an
electromagnetic wave process or laser beam. They are normally used in DVD and CD
players.
 External drives are used to transfer large files or amounts of data. These drives are plugged
into computers through USB ports.
 Tape drives were mostly used before the invention of CDs and DVDs. They have a magnetic
tape that is used to store large amounts of data. This data is stored in a sequential manner,
making it difficult to quickly find information because one has to scroll through the tape to
locate the desired information.

6.11 DISK STRUCTURE


 Disk provides bulk of secondary storage of computer system. The disk can be considered the
one I/O device that is common to each and every computer.
 Disks come in many size and speeds, and information may be stored optically or
magnetically.
 Magnetic tape was used as an early secondary storage medium, but the access time is much
slower than for disks. For backup, tapes are currently used.
 Modern disk drives are addressed as large one dimensional array of logical blocks, where
the logical block is the smallest unit of transfer.
 The actual details of disk I/O operation depend on the computer system, the operating
system and the nature of the I/O channel and disk controller hardware.
 The basic unit of information storage is a sector. The sectors are stored on a flat, circular,
media disk. This media spins close to one or more read/write heads. The heads can move
from the inner portion of the disk to the outer portion. When the disk drive is operating, the
disk is rotating at constant speed.
 To read or write, the head must be positioned at the desired track and at the beginning of the
desired sector on that track.
 Track selection involves moving the head in a movable head system or electronically
selecting one head on a fixed head system. These characteristics are common to floppy
disks, hard disks, CD-ROM and DVD.
6.12 DISK ATTACHMENT
Computers access disk storage in two ways. One way is via I/O ports (or host-attached storage);
this is common on small systems. The other way is via a remote host in a distributed file
system; this is referred to as network-attached storage.
1) Host-Attached Storage: Host-attached storage is storage accessed through local I/O ports.
These ports use several technologies. The typical desktop PC uses an I/O bus architecture
called IDE or ATA. This architecture supports a maximum of two drives per I/O bus.
2) Network-Attached Storage: A network-attached storage (NAS) device is a special-purpose
storage system that is accessed remotely over a data network. Clients access network-
attached storage via a remote-procedure-call interface such as NFS for UNIX systems or
CIFS for Windows machines.
3) Storage-Area Network: A storage-area network (SAN) is a private network (using storage
protocols rather than networking protocols) connecting servers and storage units.

6.13 DISK SCHEDULING

Disk scheduling is done by operating systems to schedule I/O requests arriving for disk. Disk
scheduling is also known as I/O scheduling. Disk scheduling is important because: Multiple I/O
requests may arrive by different processes and only one I/O request can be served at a time by
disk controller. Thus other I/O requests need to wait in waiting queue and need to be scheduled.
Two or more requests may be far from each other so can result in greater disk arm movement.
Hard drives are one of the slowest parts of computer system and thus need to be accessed in an
efficient manner.
Seek Time: Seek time is the time taken to locate the disk arm to a specified track where the
data is to be read or write. So the disk scheduling algorithm that gives minimum average seek
time is better.
Disk Response Time: Response Time is the average of time spent by a request waiting to
perform its I/O operation
Different types of scheduling algorithms are as follows:
1. First Come, First Served scheduling algorithm (FCFS).
2. Shortest Seek Time First (SSTF) algorithm
3. SCAN algorithm
4. Circular SCAN (C-SCAN) algorithm
5. Look Scheduling Algorithm

1. First Come, First Served scheduling algorithm (FCFS): FCFS is the simplest of all the
Disk Scheduling Algorithms. In FCFS, the requests are addressed in the order they arrive in
the disk queue.
Advantages: Every request gets a fair chance, No indefinite postponement
Disadvantages: May not provide the best possible service

2. Shortest Seek Time First (SSTF) algorithm: In SSTF (Shortest Seek Time First), requests
having shortest seek time are executed first. So, the seek time of every request is calculated
in advance in queue and then they are scheduled according to their calculated seek time. As
a result, the request near the disk arm will get executed first. SSTF is certainly an
improvement over FCFS as it decreases the average response time and increases the
throughput of system.
Disadvantages: Overhead to calculate seek time in advance, can cause Starvation for a
request if it has higher seek time as compared to incoming requests.

3. SCAN scheduling algorithm: In SCAN algorithm the disk arm moves into a particular
direction and services the requests coming in its path and after reaching the end of disk, it
reverses its direction and again services the request arriving in its path. So, this algorithm
works like an elevator and hence also known as elevator algorithm. As a result, the
requests at the midrange are serviced more and those arriving behind the disk arm will have
to wait.
Advantages: High throughput, Average response time
Disadvantages: Long waiting time for requests for locations just visited by disk arm.

4. C SCAN Scheduling Algorithm: In SCAN algorithm, the disk arm again scans the path
that has been scanned, after reversing its direction. So, it may be possible that too many
requests are waiting at the other end or there may be zero or few requests pending at the
scanned area. These situations are avoided in CSCAN algorithm in which the disk arm
instead of reversing its direction goes to the other end of the disk and starts servicing the
requests from there. So, the disk arm moves in a circular fashion and this algorithm is also
similar to SCAN algorithm and hence it is known as C-SCAN (Circular SCAN).
Advantages: Provides more uniform wait time compared to SCAN

5. LOOK Scheduling Algorithm: It is similar to the SCAN disk scheduling algorithm except
the difference that the disk arm in spite of going to the end of the disk goes only to the last
request to be serviced in front of the head and then reverses its direction from there only.
Thus it prevents the extra delay which occurred due to unnecessary traversal to the end of
the disk.

6.14 SWAP-SPACE MANAGEMENT


Swap space management is low level task of the operating system. The main goal for the design
and implementation of swap space is to provide the best throughput for the virtual memory
system. Virtual memory is a combination of RAM and disk space that running processes can
use. Swap space is the portion of virtual memory that is on the hard disk, used when RAM is
full.
Swap-Space Use: The operating system needs to release sufficient main memory to bring in a
process that is ready to execute. Operating system uses this swap space in various ways. Paging
systems may simply store pages that have been pushed out of main memory. Unix operating
system allows the use of multiple swap space are usually put on separate disks, so the load
placed on the I/O system by paging and swapping can be spread over the systems I/O devices.
Swap Space Location: Swap space can reside in two places:
1. Separate disk partition 2. Normal file System
If the swap space is simply a large file within the file system, normal file system routines can be
used to create it, name it and allocate its space. This is easy to implement but also inefficient.
External fragmentation can greatly increase swapping times. Caching is used to improve the
system performance. Block of information is cached in the physical memory, and by using
special tools to allocate physically continuous blocks for the swap file. Swap space can be
created in a separate disk partition. No file system or directory structure is placed on this space.
A separate swap space storage manager is used to allocate and deallocate the blocks. This
manager uses algorithms optimized for speed. Internal fragmentation may increase. Some
operating systems are flexible and can swap both in raw partitions and in file system space.
CASE STUDIES
LINUX OPERATING SYSTEM
1.1 Linux Operating System:
Linux is an operating system assembled under the model of open source software development
and mostly used for server purpose. It supports many programming languages like
C,C++,JAVA,PHP and many more.

1.2 Advantages of Linux:


 Low cost: You need not spend much money to obtain license as its softwares come from
GNU General Public License. You can also download high quality software whenever you
want, free of cost and you need not worry that your program may stop due to trail version.
You can also install it in many computers without paying.
 Performance: Linux provides high performance on workstations and on networks. It also
helps in making old computers sufficient and usable again and also can handle many users
at a time.
 Stability: You don’t have to reboot periodically to maintain performance. It can handle
large number of users and does not hang up or slow down due to memory issues.
Continuous up time up to a year or so is common.
 Flexibility: It is used for high performance applications, desktop applications and
embedded applications. You can save disk space by installing components required for a
particular use. You can restrict specific computers instead of all computers.
 Security: The security aspect of the Linux is very strong as it is very secure and it is less
prominent to viruses, even if there is an attack there would be immediate step taken by the
developers all over the world to resolve it.
 Choice: Choice is one of the greatest advantages of Linux. It gives the power to control
every aspect of the operating system. Main features that you have control are look and feel
of desktop by Windows Manager and kernel.

1.3 Disadvantages of Linux:


 Understanding: To become familiar with Linux you need to have a lot of patience and
desire to read and explore about it.
 Software: Linux has a limited selection of available softwares.
 Ease: Even though Linux has improved a lot in ease of use but windows is much easier.
 Hardware: Linux does not support many hardware devices.

1.4 Important features of Linux Operating System:

Following are some of the important features of Linux Operating System.


 Portable – Portability means softwares can works on different types of hardware in same
way. Linux kernel and application programs support their installation on any kind of
hardware platform.
 Open Source – Linux source code is freely available and it is community based
development project. Multiple teams works in collaboration to enhance the capability of
Linux operating system and it is continuously evolving.
 Multi-User – Linux is a multiuser system means multiple users can access system resources
like memory/ ram/ application programs at same time.
 Multiprogramming – Linux is a multiprogramming system means multiple applications can
run at same time.
 Hierarchical File System – Linux provides a standard file structure in which system files/
user files are arranged.
 Shell – Linux provides a special interpreter program which can be used to execute
commands of the operating system. It can be used to do various types of operations, call
application programs etc.
 Security – Linux provides user security using authentication features like password
protection/ controlled access to specific files/ encryption of data.

1.5 Organizing Directories In Linux:

Linux stores data and programs in files. These are organized in directories. In a simple way, a
directory is just a file that contains other files (or directories).

The part of the hard disk where you are authorised to save data is called your home directory.
Normally all the data you want will be saved in files and directories in your home directory. To
find your home directory (if you need), type:
echo $HOME
The symbol ~ can also be used for your home directory.

1) Creating and removing directories:

1) To make a new directory do:


mkdir directory-name
2) To remove a directory that does not files inside do:
rmdir directory-name
3) If the directory has files, you can do the following: rm -rv directory-name
and you will be asked for each file (or subdirectory) if you want to remove it; or
rm -frv directory-name
that will remove all files (and subdirectories) without asking any questions.

2) Changing the working directory:

1) To change ("enter") into a directory do: cd directory-name

This assumes that the new directory is a subdirectory of the one you are currently working on.
If that is not the case, you will have to type the name, for example:

cd /usr/local/share/bin

2) To go to your home directory do simply:


cd

3) Renaming directories:
To change the name of a directory do:
mv directory-name new-name
It will move all the files inside as well.
1.6 Process Management In Linux:

1) Linux process management follows the Unix model:


 A fork() system call creates a new process
 A new program is run after a call to exec()
2) Process control block contains all the information about the process:
 Process Identity
 Process Environment
 Process Context

1. Process Identity:
• Process ID (PID): the unique identifier for the process
• Credentials: each process has an associated UID and group Ids. Determine the process’s
rights to access system resources and files.
• Personality: Process personalities are not traditionally found on/UNIX Systems, but under
Linux each process has an associated personality identifier that can modify slightly the
semantics of certain system calls. Personalities are primarily used by emulation libraries to
request that system calls be compatible with certain flavours of UNIX.

2. Process Environment:
• Environment is inherited from its parent
• Conventionally starts with the program name
• Environment vector is a list of “NAME=VALUE” pairs
• Associates named environment variables with arbitrary textual values
• e.g., PATH=“/usr/bin;….”
• Environment variables can be used to pass data among processes
• Environment variables can be set per-process

3. Process Context:
•Process context is constantly changing state of a running program at any point in time.
Process context includes the following parts.
• Scheduling Context- is the most important part of the process context
• File Table- Is an array of pointers to kernel file structures when making file I/O, processes
refer to files by their index into this table
• Signal handler- defines the routine to be called upon some events
• Virtual memory- defines the process’s address space

1.7 Difference between Internal And External Commands In Linux:

Internal commands are the built in commands of the shell which means that when you execute
an internal command, no process will be launched to execute the command. Therefore the
speed of executing an internal command will be very high. Example – cd, pwd, echo etc.
External commands are those commands which are stored as separate binaries. Shell starts
separate sub-process to execute them. Most external commands are stored in the form of
binaries in /bin directory. To execute external command shell check $PATH variable. If
command present in the location mentioned in $PATH variable shell will execute it, otherwise
it will give error. Example – ls,mv,cat etc.

WINDOWS OPERATING SYSTEM


2.1 Windows Operating System:
Windows is family of operating system from Microsoft. If programming languages such
as Visual Basic.net, ASP.net, Visual C#, Visual C++ are used then it is better to opt windows
hosting.

2.2 Advantages:
 Ease: Microsoft Windows has made much advancement and changes which made it easy to
use the operating system. Even though it is not the easiest, it is easier than Linux.
 Software: Since there is more number of Microsoft users there are more software
programs, games and utilities for windows. All most all games are compatible to windows;
some CPU intensive and graphic intensive games are also supported.
 Hardware: All hardware manufacturers will support Microsoft windows. Due to large
number of Microsoft users and broader driver, all the hardware devices are supported.
 Front Page Extension: When using a popular web design program having windows
hosting makes it lot more easily. You don’t have to worry if it supported or not.
 Development: If you plan to develop windows based applications then windows platform
is most suggested as Linux does not support windows applications.

2.3 Disadvantages:
 Price: Microsoft windows are costly compared to Linux as each license costs between
$50.00-$100.00.
 Security: When compared to Linux it is much more prone to viruses and other attacks.
 Reliability: It needs to be rebooted periodically else there is a possibility of hang up of the
system.
 Software Cost: Even though the windows have softwares, games for free most of the
programs will cost more than $200.

2.4 Basic Features of Windows Operating System:


1) Windows Easy Transfer: One of the first things you might want to do is to transfer your
files and settings from your old computer to the brand new computer. You can do this using an
Easy Transfer Cable, CDs or DVDs, a USB flash drive, a network folder, or an external hard
disk.

2) Windows Anytime Upgrade: This feature of Windows Operating System allows you to
upgrade to any higher windows version available for your system, so you can take full
advantage of enhanced digital entertainment and other features.
3) Windows Basics: If you are new to Windows or want to refresh your knowledge about areas
such as security or working with digital pictures, these features will help you to get started.
4) Searching and Organizing: Most folders in Windows have a search box in the upper- right
corner. To find a file in a folder, type a part of the file name in the search box.
You can also use this feature when you don't know where a file is actually located or when you
want to do an advanced search. Since its will be an indexed searching the results will be very
quick and very close to your search entries.

5) Parental Controls: Parental Controls give you the means to decide when your children use
the computer, which website they visit, and which games they are allowed to play. You can also
get reports of your children's computer activity as well.

6) Ease of Access Center: Ease of Access Center is the place to find and change settings that
can enhance how you hear, see and use your computer. You can adjust text size and the speed
of your mouse. This is also where you can go to set up your screen reader and find
other helpful tools.

7) Default Programs: This is a feature of your Windows Operating System where you can
adjust and set your default programs, associate a file type or a protocol with a program, change
and set auto play settings, set program access and computer defaults.
8) Remote Desktop Connection: This feature helps a user with a graphical user interface
to another computer. It is a proprietary protocol developed by Microsoft especially for
Windows Operating System. Basically by entering the IP address of the other computer you can
directly see that computer's desktop right on to your desktop.

Conclusion: Both Windows and Linux Hosting have advantages and disadvantages. Based on
your requirements you need to opt which hosting suits better.

You might also like