Operating System
Operating System
Introduction to Operating
Systems
1.0 Objectives
1.1 Introduction
The hardware—the central processing unit (CPU), the memory, and the
input/output (I/O) devices—provides the basic computing resources for the
system. The application programs—such as word processors, spreadsheets,
compilers, and web browsers—define the ways in which these resources are used
to solve users' computing problems. The operating system controls and
coordinates the use of the hardware among the various application programs for
the various users.
Features of OS
File
Management I/O
Management
Print
Management
Disk
Management
Process
Management
The hardware-the central processing unit (CPU), the memory, and the
input/output (I/O) devices-provides the basic computing resources for the system.
The application programs-such as word processors, spreadsheets, compilers,
and web browsers-define the ways in which these resources are used to solve
users' computing problems. The operating system controls and coordinates the
use of the hardware among the various application programs for the various
users.
1] Single process
2] Multi process.
Single process operating systems are capable of working on one task at a time
while multi process operating systems can work on several processes at once by
breaking the tasks into threads. Smallest part of programs that can be scheduled
for execution is called as a thread. There are several terms related to
multiprocessing which are as follows
1] Co-operative Multitasking
2] Preemptive multitasking.
Multithreading.
4] Desktop PCs, workstations and laptops are used to install desktop operating
Systems.
Environment.
Features of NOS
5] Generally server grade computers are used for installation of network operating
system.
7] It provides high security that includes user level, share level as well as file level.
8] It provides backup tools to take the backup of important data. Backup can be
scheduled in non working hours also.
10] Network operating systems are as follows: Windows Server 2000, Windows
Server 2003, Windows Server 2008.Red Hat Enterprise Linux Server 4.0, and
5.0, UNIX, Novell's Netware 4.x, 5.x and 6.x servers etc.
Apart from being as a User interface between system hardware and User
applications operating system have other functions which are as follows
1] Memory management
2] Process Management
3] Disk Management
4] I/O management
5] Device Management
6] Backup Management
7] Security Management.
system.
network environment.
The specific services provided, of course, differ from one operating system to
another but we can identify common classes. These services are provided for the
convenience of the programmer to make the programming task easier.
The common services provided by the operating system is listed in following figure
1. User Interface :
User interface is a medium through which user actually interacts with the
2. Program Execution :
The purpose of computer system is to allow the users to execute programs in
an efficient manner. The operating system provides an environment where
the user can conveniently run these programs. OS takes care of assigning
work to the CPU (CPU job scheduling) for the purpose of program execution.
Every program that runs on computer system needs memory. This memory
allocation is done by operating systems. Also multitasking, multiprogramming
etc features are provided by OS. After executing the program, de-allocation of
memory is done by OS.The OS must be able to load the program into
memory and to execute it. The program must be able to terminate its
execution either normally or abnormally.
3. I/O Operations :
Each program requires an input and after processing the input submitted by
user it produces output. This involves the use of I/O devices. The input may
be either from the file on the disk or from some other input device. The output
may be written to some file on the disk or sent to some output devices such
4. File-system manipulation :
While working on the compute, generally a user is required to manipulate
various types of files like as opening a file, saving a file and deleting a file
from the storage disk. Program needs to read a file or write a file. The OS
gives the permission to the program for operation on file. Maintain details of
files or directories with their respective details. This is an important task that
is also performed by the operating system.
5. Communications :
Operating system performs the communication among various types of
processes in the form of shared memory. In multitasking environment, the
processes need to communicate with each other and to exchange their
information. These processes are created under a hierarchical structure
where the main process is known as parent process and the sub processes
are known as child processes.
6. Error Detection:
Error can occur anytime and anywhere. Error may occur in CPU, in I/O
devices or in the memory hardware. Operating system deals with hardware
problems. To avoid hardware problems the operating system constantly
monitors the system for detecting the errors and fixing these errors (if found).
The main function of Operating system is to detect the errors like bad sector
on hard disk, errors related to I/O devices. After detecting the errors, OS
takes appropriate action for consistent computing.
7. Resource Allocation :
In the multitasking environment, when multiple jobs are running at a time, it is
the responsibility of an OS to allocate the required resources (like CPU, main
memory, tape drive or secondary storage etc) to each process for its better
8. Accounting :
OS keeps an account of all the resources accessed by each process or user.
In multitasking, accounting enhances the system performance with the
allocation of resources to each process ensuring the satisfaction to each
process.
9. Protection :
The owners of information stored in a multi user or networked computer
system may want to control use of that information i.e. access to data and
other related privileges like reading, writing, executing etc.
Even the concurrent processes should not interfere with each other which
may cause damage to the information. Protection: This involves ensuring that
all access to system resources is controlled. Security: Unwanted users
requires user authentication. The defending of external I/O devices from
invalid access is important. It is important to protect the system and keep it
secured.
UNIX is an operating system which was first developed in the 1960s, and has been
under constant development ever since. By operating system, we mean the suite of
programs which make the computer work. It is a stable, multi-user, multi-tasking
system for servers, desktops and laptops.
UNIX systems also have a graphical user interface (GUI) similar to Microsoft
Windows which provides an easy to use environment. However, knowledge of
UNIX is required for operations which aren't covered by a graphical program, or for
when there is no windows interface available, for example, in a telnet session.
The UNIX operating system is a set of programs that act as a link between the
computer and the user.
The computer program that allocates the system resources and coordinates all the
details of the computer's internals is called the operating system or the kernel.
Users communicate with the kernel through a program known as the shell. The
shell is a command line interpreter; it translates commands entered by the user and
converts them into a language that is understood by the kernel.
There are various UNIX variants available in the market. Solaris UNIX, AIX, HP
UNIX and BSD are a few examples. Linux is also a flavor of UNIX which is
freely available.
Several people can use a UNIX computer at the same time; hence UNIX is
called a multiuser system.
A user can also run multiple programs at the same time; hence Unix is a
multitasking environment
There are many different versions of UNIX, although they share common
similarities. The most popular varieties of UNIX are Sun Solaris, GNU/Linux, and
MacOS X.
Here in the School, we use Solaris on our servers and workstations, and Fedora
Linux on the servers and desktop PCs.
Kernel − The kernel is the heart of the operating system. It interacts with the
hardware and most of the tasks like memory management, task scheduling and
file management.
Shell − The shell is the utility that processes your requests. When you type in a
command at your terminal, the shell interprets the command and calls the
program that you want. The shell uses standard syntax for all commands. C
Shell, Bourne Shell and Korn Shell are the most famous shells which are
available with most of the Unix variants.
Commands and Utilities − There are various commands and utilities which you
can make use of in your day to day activities. cp, mv, catand grep, etc. are few
examples of commands and utilities. There are over 250 standard commands
plus numerous others provided through 3rd party software. All the commands
come along with various options.
Files and Directories − All the data of Unix is organized into files. All files are
then organized into directories. These directories are further organized into a
tree-like structure called the file system.
System Boot up
If you have a computer which has the Unix operating system installed in it, then you
simply need to turn on the system to make it live.
As soon as you turn on the system, it starts booting up and finally it prompts you to log
into the system, which is an activity to log into the system and use it for your day-to-
day activities.
Login Unix
When you first connect to a Unix system, you usually see a prompt such as the
following −
login:
Type your user id at the login prompt, and then press ENTER. Your user id
is case-sensitive, so be sure you type it exactly as your system administrator
has instructed.
Type your password at the password prompt, and then press ENTER. Your
password is also case-sensitive.
If you provide the correct user id and password, then you will be allowed to enter
into the system. Read the information and messages that comes up on the
screen, which is as follows.
login :amrood
amrood's password:
You will be provided with a command prompt (sometime called the $ prompt) where
you type all your commands. For example, to check calendar, you need to type
the cal command as follows −
$ cal
June 2009
Su Mo Tu We Th Fr Sa
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
Change Password
All Unix systems require passwords to help ensure that your files and data remain your
own and that the system itself is secure from hackers and crackers. Following are the
steps to change your password −
Step 2 − Enter your old password, the one you're currently using.
Step 3 − Type in your new password. Always keep your password complex enough so
that nobody can guess it. But make sure, you remember it.
$ passwd
Note − We have added asterisk (*) here just to show the location where you need to
enter the current and new passwords otherwise at your system. It does not show you
any character when you type.
$ ls -l
total 19621
Here entries starting with d..... represent directories. For example, uml, univ and
urlspedia are directories and rest of the entries are files.
The easiest way to find out "who you are" is to enter the whoami command −
$ whoami
amrood
Try it on your system. This command lists the account name associated with the
current login. You can try who am i command as well to get information about
yourself.
There are three commands available to get you this information, based on how much
you wish to know about the other users: users, who, and w.
$ users
amroodbabluqadir
$ who
Try the w command on your system to check the output. This lists down information
associated with the users logged in the system.
Logging Out
When you finish your session, you need to log out of the system. This is to ensure that
nobody else accesses your files.
To log out
Just type the logout command at the command prompt, and the system will
clean up everything and break the connection.
1 halt
2 init 0
3 init 6
4 poweroff
5 reboot
6 shutdown
characters.
Windows XP supports
3] maximum ----------- CPUs.
file systems.
Match the
followings
Operating System can be divided into 2 groups i.e. single and multi process.
Multitasking is the capability of operating system to handle more than one task at a
time.
The main benefit of using XP include its reliability, performance, security, ease of
use, support for remote users, management and development capabilities. Windows
Vista is also language neutral
1.3 - 1.4
1.5 - 1.6
Fals
4] True 5] True 6] e
Fals
6] True 7] True 8] e
Suggested readings
References used:
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
_____________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
_____________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
_____________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
Chapter: 2
2.0 Objectives
2.1 Introduction
2.5.1 Short
2.5.2 Medium
2.6 Scheduling:
2.6.1 Preemptive
2.6.2 Non-preemptive
2.7.1 FCFS
2.7.2 SJFS
2.7.4 RR
2.0 OBJECTIVES
The user views his job as a collection of tasks he wants the computer system to
perform for him. The user may subdivide his job into job steps, which are sequentially
processed sub tasks (e.g., compile, load, execute). The system creates processes to do
the computation of the job steps.
For more general multiprogramming systems, the job scheduler chooses a small
subset of the jobs submitted and lets them "into" the system. That is, the job scheduler
creates processes for these jobs and assigns the processes some resources. It must
decide, for example, which two or three jobs of the 100 submitted will have any
The operating system is responsible for several important aspects of process and
thread management: the creation and deletion of both user and system processes; the
scheduling of processes; and the provision of mechanisms for synchronization,
communication, and deadlock handling for processes.
A process is more than the program code, which is sometimes known as the text
section. It also includes the current activity, as represented by the value of the program
counter and the contents of the processor‘s registers. A process generally also includes
the process stack, which contains temporary data (such as function parameters, return
addresses, and local variables), and a data section, which contains global variables. A
As a process executes, it changes state. The state of a process is defined in part by the
current activity of that process. A process may be in one of the following states:
• Waiting. The process is waiting for some event to occur (such as an I/O completion or
reception of a signal).
Process state. The state may be new, ready, running, waiting, halted, and so on.
• Program counter. The counter indicates the address of the next instruction to be
executed for this process.
• CPU registers. The registers vary in number and type, depending on the computer
architecture. They include accumulators, index registers, stack pointers, and general-
purpose registers, plus any condition-code information. Along with the program counter,
this state information must be saved when an interrupt occurs, to allow the process to
be continued correctly afterward.
Accounting information. This information includes the amount of CPU and real time
used, time limits, account numbers, job or process numbers, and so on.
• I/O status information. This information includes the list of I/O devices allocated to
the process, a list of open files, and so on. In brief, the PCB simply serves as the
repository for any information that may vary from process to process.
1. When the operating system received the signal that my I/O process was finished,
the traffic controller module changed my CPU ______________
1. In _____________ each process in turn is run to a time quantum limit, such as 100
ms.
2. In _____________ if the process used its entire quantum last time, it goes to the end
of the list. If it used only half (due to I/O wait), it goes to the middle. Besides being "fair,"
this works nicely for I/O-bound jobs.
The Operating System maintains the following important process scheduling queues −
Job queue − This queue keeps all the processes in the system.
Ready queue − This queue keeps a set of all processes residing in main
memory, ready and waiting to execute. A new process is always put in this queue.
Long-Term Scheduler
Short-Term Scheduler
Medium-Term Scheduler
The primary objective of the job scheduler is to provide a balanced mix of jobs,
such as I/O bound and processor bound. It also controls the degree of
multiprogramming. If the degree of multiprogramming is stable, then the average rate of
process creation must be equal to the average departure rate of processes leaving the
system.
The Scheduling algorithms can be divided into two categories with respect to how they
deal with clock interrupts.
Non-preemptive Scheduling
1. In non-preemptive system, short jobs are made to wait by longer jobs but the overall
treatment of all processes is fair.
2. In non-preemptive system, response times are more predictable because incoming
high priority jobs cannot displace waiting jobs.
3. In non-preemptive scheduling, a scheduler executes jobs in the following two
situations.
a. When a process switches from running state to the waiting state.
b. When a process terminates.
Preemptive Scheduling
A scheduling discipline is preemptive if, once a process has been given the CPU can
taken away.
The strategy of allowing processes that are logically run able to be temporarily
suspended is called Preemptive Scheduling and it is contrast to the "run to completion"
method.
P0 0-0=0
P1 5-1=4
P3 16 - 3 = 13
The processer should know in advance how much time process will take.
P0 3-0=3
P1 0-0=0
P2 16 - 2 = 14
Processes with same priority are executed on first come first served basis.
P0 9-0=9
P1 6-1=5
P2 14 - 2 = 12
P3 0-0=0
It is often used in batch environments where short jobs need to give preference.
Once a process is executed for a given time period, it is preempted and other
process executes for a given time period.
P0 (0 - 0) + (12 - 3) = 9
P1 (3 - 1) = 2
P3 (9 - 3) + (17 - 12) = 11
Ex: Cash machine hands you cash and deducts amount from your account
ACID Properties
A transaction is a very small unit of a program and it may contain several low level
tasks. A transaction in a database system must maintain Atomicity,
Consistency, Isolation, and Durability − commonly known as ACID properties − in order
to ensure accuracy, completeness, and data integrity.
Atomicity − This property states that a transaction must be treated as an atomic unit,
that is, either all of its operations are executed or none. There must be no state in a
database where a transaction is left partially completed. States should be defined either
before the execution of the transaction or after the execution/abortion/failure of the
transaction.
Consistency − The database must remain in a consistent state after any transaction.
No transaction should have any adverse effect on the data residing in the database. If
the database was in a consistent state before the execution of a transaction, it must
remain consistent after the execution of the transaction as well.
Durability − The database should be durable enough to hold all its latest updates
even if the system fails or restarts. If a transaction updates a chunk of data in a
Isolation − In a database system where more than one transaction are being
executed simultaneously and in parallel, the property of isolation states that all the
transactions will be carried out and executed as if it is the only transaction in the
system. No transaction will affect the existence of any other transaction.
1. This configuration flexibility is useful if there are some jobs that require the
full complement of memory and/or I/O ___________
so critical that the various orders of scheduling them result in different computations.
In many instances, the job scheduling and process scheduling algorithms must
interact closely.
As a compromise, we can adopt the philosophy that it is far better to give a few jobs at a
time a chance than to starve them all! For example, we may allow two to five users to
be ready at a time.
The basic concepts here are: (l) multiprogramming "in the small" for two to five
jobs, process-scheduling every few ms; and (2) timeshare "in the large," where every
few 100 ms or seconds one ready job is placed in hold status and one of the hold status
jobs is made ready. (See Figure 2.13) Thus, over a period of a minute or so, every job
has had its turn, and furthermore, the system runs fairly efficiently.
The WAIT and SIGNAL mechanisms can be used for other purposes, such as
waiting for I/O completion. After an I/O request (i.e., SIO instruction) has been issued,
the process can be blocked by a WAlT (X) where X is a status byte associated with the
I/O device (e.g., the lock byte can be stored in the device's Unit Control Block as shown
in the sample operating system). When the I/O completion interrupt occurs, it is
converted into a SIGNAL (X).
Running
Hold Completed
Ready Blocked
Processor management has major functions: (1) job scheduling, (2) process
scheduling, and (3) traffic control (such as inter process communication and
synchronization). Job schedulers range from very simple, even manually done,
algorithms to complex automated schedulers that consider the mix of jobs waiting to be
run (i.e., in the hold state) as well as the available resources of the system. A unipro-
gramming operating system or simple priority-based process scheduler does not
provide the same degree of optimization available in an adaptive process scheduling
algorithm. In any type of system the interaction between job scheduling and process
scheduling must always be carefully considered. If the job scheduler keeps dumping
more and more jobs on an already overloaded process scheduler, system performance
will suffer greatly.
Considerable research and study are still needed to resolve many of the
problems connected with interprocess communication and synchronization. These
features are very important to modern modular operating systems, as illustrated by their
extensive usage in the sample operating system.
1. Round robin
1. Device resources
2. Coordinated job scheduling
Suggested readings
References used:
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
_____________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
_____________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
_____________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
_____________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
Chapter 3:
3.0 Objectives
3.1 Introduction
3.7 Summary
3.0 Objectives
3.1 Introduction
An independent process is not affected by the execution of other processes while a co-
operating process can be affected by other executing processes. Though one can think
that those processes, which are running independently, will execute very efficiently but
in practical, there are many situations when co-operative nature can be utilised for
increasing computational speed, convenience and modularity. Inter process
communication (IPC) is a mechanism which allows processes to communicate each
other and synchronize their actions. The communication between these processes can
be seen as a method of co-operation between them. Processes can communicate with
each other using these two ways:
1. Shared Memory
2. Message passing
The Figure below shows a basic structure of communication between processes via
shared memory method and via message passing.
Between related processes initiating from only one process, such as parent and child
processes.
Following are some important terms that we need to know before proceeding further on
this topic.
Message Queues − Communication between two or more processes with full duplex
capacity. The processes will communicate with each other by posting a message and
retrieving it out of the queue. Once retrieved, the message is no longer available in the
queue.
Where several processes access and manipulate the same data concurrently and the
outcome of the execution depends on the particular order in which the access takes
place.
Its solution is that these processes must be synchronized in some way. We must
guarantee that only one process at a time can be manipulating this resource.
Consider a system consisting of n processes {P0, P1,…, Pn-1}. Each process has a
segment of code, called a Critical section, in which the process may be changing
common variables, updating a table, writing a file and so on.
The important feature of the system is that when one process is executing in its critical
section no other process is to be allowed to execute in its critical section. That is, no two
processes are executing in their critical sections at the same time.
The critical section problem is to design a protocol that the processes can use to
cooperate. Each process must request permission to enter its critical section.
The section of code implementing this request is the entry section. The critical section
may be followed by an exit section. The remaining code is the remainder section. The
general structure of a typical process p is shown as below :
do
Entry section
Critical section
Remainder section
} while(True);
1. Entry Section : Each process must request permission to enter its critical section;
processes may go to critical section through entry section.
2. Exit Section : Each critical section is terminated by exit section.
3. Remainder section : The code after exit section is remainder section.
A solution to the critical section problem must satisfy the following three
requirements :
1. Mutual Exclusion : If process Pi is executing in its critical section, the no other
processes can be executing in their critical sections. So mutual exclusion can
be defined as : ― A way of making sure that if one process is using a shared
modifiable data , the other processes will be excluded from doing the same
thing ―. We need four conditions to have a good solution for the mutual
exclusion is :
i) No two processes may at the same moment inside their critical section.
ii) No assumptions are made about relative speeds of processes or
number of CPU‘s
iii) No process should outside its critical section block other processes.
iv) No process should wait arbitrary long to enter its 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 deciding which
will enter its critical section next and this selection cannot be postponed
indefinitely.
1. Disabling Interrupts :
This is the simplest solution. When process enters in critical region, interrupts are
disabled by it and once it leaves critical section , it again enables interrupts.
Because of either clock or interrupt, CPU makes switching from one process to
other. When interrupts are disabled, CPU switching will nbot happen.
Here process can complete its shared memory operations without any fear and
bothering about other process to enter.
Important thing is that we have to give power to a process to disable interrupt. That will
be unwise because if the processes disables the interrupts and do not make them
enable then many problems can occur. Only kernels can easily enable and disable the
interrupts. So it is not a good approach for mutual exclusion.
2. Lock Variables :
This could be one of the solutions. Here we can declare two variables one single and
shared(lock) initialized to 0. If the process finds that lock is 0 then it enters into critical
region and makes lock variable 1 and just before leaving it is again set to 0.
If another process enters then it can see that lock variable is 1 then it waits till it
becomes 0. There could another case where process keep waiting and if the lock
variable becomes 0 then one more process may enters and tries to make that lock
variable to 1 before waiting process makes it. So this approach is also not that effective
because this solution will bring race condition.
The only problem with the lock variable solution is that the action of testing the
variable and the action of setting the variable are executed as separate instructions. If
these operations could be combined into one indivisible step, this could be a workable
solution. These steps can be combined, with a little help from hardware, into what is
known as a TSL or TEST and SET LOCK instruction. A call to the TSL instruction
copies the value of the lock variable and sets it to a nonzero (locked) value, all in one
step. While the value of the lock variable is being tested, no other process can enter its
critical section, because the lock is set.
If a process tests a variable which is locked, it will continue to test the variable
again and again until it can enter its critical section. In other words, as long as a
process is denied access to its critical section, it will stay in a tight loop and wait until it
can proceed, all the while wasting processor time. This continuous testing of the lock
variable is called busy waiting. Mutual exclusion policies that require busy waiting
waste valuable processor time, and in some cases can lead to situations where a
process will test the lock variable forever, a very undesirable occurrence.
3. Strict Alteration : In strict alteration, variable named turn is used to run two
processes alternately. All processes share the common integer variable ‗turn‘
initialise as 0 or 1. If ‗turn =I‘, then process Pi is allowed to execute in its critical
section. This algorithm ensures that only one process at a time can be in critical
section but does not satisfy the progress condition.
Now look at some inter process communication primitives is the pair of steep-
wakeup
.Sleep :
It is a system call that causes the caller to block, that is, be suspended
until some other process wakes it up.
Wakeup
Both 'sleep' and 'wakeup' system calls have one parameter that represents a
memory address used to match up 'sleeps' and 'wakeups' .
4. Peterson’s Solution
Peterson‘s Solution is a classical software based solution to the critical section
problem.
Semaphores :
Wait () operation was originally referred as P and signal operation was called as V.
Wait(s)
While s<=0;
s--;
Signal(s)
S++;
Only one operation i.e. either wait() or signal() can access the value of semaphore and
modify it.
Binary semaphores can be used in critical section when multiple processes are
involved.
Counting semaphores can be used for controlling the access to the resources whose
instances are finite number. Every process that needs resource performs the wait()
operation on semaphore and decrements it.
When process releases the resource it uses signal() operation and thus semaphore is
incremented. When semaphores value is zero, it indicated that all resources are used.
At this stage if any process needs any resources, that processes will be blocked till the
semaphores value becomes greater than one.
Let us assume, multiple processes are using the same region of code and if all want to
access parallelly then the outcome is overlapped. Say, for example, multiple users are
using one printer only (common/critical section), say 3 users, given 3 jobs at same
time, if all the jobs start parallelly, then one user output is overlapped with another. So,
we need to protect that using semaphores i.e., locking the critical section when one
process is running and unlocking when it is done. This would be repeated for each
user/process so that one job is not overlapped with another job.
Counting Semaphores − Semaphores which allow arbitrary resource count are called
counting semaphores.
Assume that we have 5 printers (to understand assume that 1 printer only accepts 1
job) and we got 3 jobs to print. Now 3 jobs would be given for 3 printers (1 each). Again
Step 2 − Perform operations on the semaphore i.e., allocate or release or wait for the
resources (semop())
Monitors :
Syntax of Monitor
Variables;
Condition variables;
Procedure P1{…}
Procedure P2 {…}
Condition Variables
Two different operations are performed on the condition variables of the monitor.
Wait.
signal.
Signal operation
x.signal(): When a process performs signal operation on condition variable, one of the
blocked processes is given chance.
Below are some of the classical problem depicting flaws of process synchronization in
systems where cooperating processes are present.
Because the buffer pool has a maximum size, this problem is often called the
Bounded buffer problem.
Solution to this problem is, creating two counting semaphores "full" and "empty"
to keep track of the current number of full and empty buffers respectively.
In this problem there are some processes(called readers) that only read the
shared data, and never change it, and there are other processes(called writers)
who may change the data in addition to reading, or instead of reading it.
There are various type of readers-writers problem, most centred on relative
priorities of readers and writers.
3.7 Summary
Suggested readings
References used:
6. Abraham-Silberschatz-Operating-System-Concepts---9th edition
7. Operating systems by William Stallings
8. Operating systems fundamental concepts
9. www.tutorialspoint.com
10. Operating systems by Achyut Godbole
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
_____________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
_____________________________________________________________________________________
______________________________________________________________________________________
_____________________________________________________________________________________
4.0 Objectives
4.1 Introduction
4.4.1 Contiguous
4.4.2 Non-Contiguous
4.5 Paging
4.8 Summary
4.0 OBJECTIVES
To provide a detailed description of various ways of organizing memory
hardware.
To explore various techniques of allocating memory to processes.
To discuss in detail how paging works in contemporary computer systems.
To describe the benefits of a virtual memory system.
To explain the concepts of demand paging, page-replacement algorithms,
and allocation of page frames.
To discuss the principles of the working-set model.
To examine the relationship between shared memory and memory-mapped
4.1 Introduction
The main purpose of a computer system is to execute programs. These
programs, together with the data they access, must be at least partially in main memory
during execution. To improve both the utilization of the CPU and the speed of its
response to users, a general-purpose computer must keep several processes in
memory. Many memory-management schemes exist, reflecting various approaches,
and the effectiveness of each algorithm depends on the situation. Selection of a
memory-management scheme for a system depends on many factors, especially on the
hardware design of the system. Most algorithms require hardware support
As a result of CPU scheduling, we can improve both the utilization of the CPU
and the speed of the computer‘s response to its users. To realize this increase in
performance, however, we must keep several processes in memory—that is, we must
share memory.
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. Memory management keeps track of each and
every memory location, regardless of either it is allocated to some process or it is free. It
checks how much memory is to be allocated to processes. It decides which process will
get memory at what time. It tracks whenever some memory gets freed or unallocated
and correspondingly it updates the status.
This scheme allows the operating system to change the value of the registers but
prevents user programs from changing the registers‘ contents. The operating system,
executing in kernel mode, is given unrestricted access to both operating-system
memory and users‘ memory. This provision allows the operating system to load users‘
programs into users‘ memory, to dump out those programs in case of errors, to access
• Load time. If it is not known at compile time where the process will reside in memory,
then the compiler must generate relocatable code. In this case, final binding is delayed
until load time. If the starting address changes, we need only reload the user code to
incorporate this changed value.
Execution time. If the process can be moved during its execution from one memory
segment to another, then binding must be delayed until run time. Special hardware must
be available for this scheme to work, as will be discussed Most general-purpose
operating systems use this method
However, the execution-time address binding scheme results in differing logical and
physical addresses. In this case, we usually refer to the logical address as a virtual
address. We use logical address and virtual address interchangeably in this text.
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 is a
physical address space. Thus, in the execution-time address-binding scheme, the
logical and physical address spaces differ. The run-time mapping from virtual to
physical addresses is done by a hardware device called the memory-management
unit (MMU).We can choose from many different methods to accomplish such mapping,.
For the time being, we illustrate this mapping with a simple MMU scheme that is a
generalization of the base-register scheme The base register is now called a relocation
register. The value in the relocation register is added to every address generated by a
user process at the time the address is sent to memory For example, if the base is at
14000, then an attempt by the user to address location 0 is dynamically relocated to
location 14000; an access to location 346 is mapped to location 14346. The user
program never sees the real physical addresses. The program can create a pointer to
4.5 Paging
Hardware Support
Each operating system has its own methods for storing page tables. Some allocate a
page table for each process. A pointer to the page table is stored with the other register
values (like the instruction counter) in the process control block. When the dispatcher is
told to start a process, it must reload the user registers and define the correct hardware
page-table values from the stored user page table. Other operating systems provide
one or at most a few page tables, which decreases the overhead involved when
processes are context-switched. The hardware implementation of the page table can be
done in several ways. In the simplest case, the page table is implemented as a set of
dedicated registers. These registers should be built with very high-speed logic to make
The standard solution to this problem is to use a special, small, fast lookup hardware
cache called a translation look-aside buffer (TLB). The TLB is associative, high-
speed memory. Each entry in the TLB consists of two parts: a key (or tag) and a value.
When the associative memory is presented with an item, the item is compared with all
keys simultaneously. If the item is found, the corresponding value field is returned. The
search is fast; a TLB lookup in modern hardware is part of the instruction pipeline,
essentially adding no performance penalty. To be able to execute the search within a
pipeline step, however, the TLB must be kept small. It is typically between 32 and 1,024
Segmentation
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.
User written error handling routines are used only when an error occurred in the
data or computation.
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.
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.
• Certain options and features of a program may be used rarely. For instance, the
routines on U.S. government computers that balance the budget have not been used in
many years. Even in those cases where the entire program is needed, it may not all be
needed at the same time. The ability to execute a program that is only partially in
memory would confer many benefits:
• Less I/O would be needed to load or swap user programs into memory, so each user
program would run faster. Thus, running a program that is not entirely in memory would
benefit both the system and the user.
The virtual address space of a process refers to the logical (or virtual) view of
how a process is stored in memory. Typically, this view is that a process begins at a
certain logical address—say, address 0—and exists in contiguous memory, as shown in
Figure 9.2. Recall from Chapter 8, though, that in fact physical memory may be
organized in page frames and that the physical page frames assigned to a process may
not be contiguous. It is up to the memory management unit (MMU) to map logical pages
to physical page frames in memory.
If a process of ten pages actually uses only half of them, then demand paging saves the
I/O necessary to load the five pages that are never used. We could also increase our
degree of multiprogramming by running twice as many processes. Thus, if we had forty
frames, we could run eight processes, rather than the four that could run if each
required ten frames (five of which were never used). If we increase our degree of
multiprogramming, we are over-allocating memory. If we run six processes, each of
which is ten pages in size but actually uses only five pages, we have higher CPU
utilization and throughput, with ten frames to spare. It is possible, however, that each of
these processes, for a particular data set, may suddenly try to use all ten of its pages,
When a page fault occurs, the operating system has to choose a page to re-move
from memory to make room for the page that has to be brought in. If the page that
is to be removed has been modified in memory, it must be rewritten to: the disk to
bring the disk copy up to date. If, however, the page has not been changed (e.g.,
a page contains program text), the disk copy is already up to date, so no rewrite is
needed. The page to be read in just overwrites the page being evicted.
While it would be possible to pick a random page to replace at each page fault,
system performance is much better if a page that is not heavily used is chosen. If
a heavily used page is removed, it will probably have to be brought back
The best possible page replacement algorithm is easy to describe but impossible to
implement. It goes like this. At the moment that a page fault occurs, some set of
pages is in memory. One of these pages will be referenced on the very next
instruction (the page containing that instruction). Other pages may not be referenced
until 10, 100, or perhaps 1000 instructions later. Each page can be labeled with the
number of instructions that will be executed before that page is first referenced.
The optimal page algorithm simply says that the page with the highest label should
be removed. If one page will not be used for 8 million instructions and another page
will not be used for 6 million instructions, removing the former pushes the page fault
that will fetch it back as far into the future as possible. Computers, like people, try to
put off unpleasant events for as long as they can.
The only problem with this algorithm is that it is unrealizable. At the time of the page
fault, the operating system has no way of knowing when each of the pages will be
referenced next. (We saw a similar situation earlier with the shortest job first scheduling
algorithm how can the system tell which job is shortest?) Still, by running a program on a
simulator and keeping track of all page references, it is possible to implement optimal page
replacement on the second run by using the page reference information collected during the
first run.
In this way it is possible to compare the performance of realizable algorithms with the
best possible one. If an operating system achieves a performance of, say, only 1
percent worse than the optimal algorithm, effort spent in looking for a better algorithm
will yield at most a 1 percent improvement.
In order to allow the operating system to collect useful statistics about which
pages are being used and which ones are not, most computers with virtual memory
have two status bits associated with each page. R is set whenever the page is
referenced (read or written). M is set when the page is written to (i.e., modified). The
bits are contained in each page table entry. It is important to realize that these bits
must be updated on every memory reference, so it is essential that they be set by the
hardware. Once a bit has been set to 1, it stays 1 until the operating system resets it
to 0 in software.
If the hardware does not have these bits, they can be simulated as follows. When a
process is started up, all of its page table entries are marked as not in memory. As soon
as any page is referenced, a page fault will occur. The operating system then sets the R
bit (in its internal tables), changes the page table entry to point to the correct page, with
mode READ ONLY, and restarts the instruction. If the page is subsequently written on,
another page fault will occur, allowing the operating system to set the M bit and change
the page's mode to READ/WRITE.
The R and M bits can be used to build a simple paging algorithm as follows. When a
process is started up, both page bits for all its pages are set to 0 by the operating
system. Periodically (e.g., on each clock interrupt), the R bit is cleared, to distinguish
pages that have not been referenced recently from those that have been.
When a page fault occurs, the operating system inspects all the pages and
divides them into four categories based on the current values of their R and M bits.
Class 0 : not referenced, not modified. Class 1 : not referenced, modified. Class 2
referenced, not modified. Class 3: referenced, modified. Although class I pages seem,
at first glance, impossible, they occur when a class 3 page has its R bit cleared by a
The NRU (Not Recently Used) algorithm removes a page at random from the lowest
numbered nonempty class. Implicit in this algorithm is that it is better to remove a
modified page that has not been referenced in at least one clock tick (typically 20
msec) than a clean page that is in heavy use. The main attraction of NRU is that it is
easy to understand, efficient to implement, and gives a performance that, while
certainly not optimal, is often adequate.
One possibility is to find the product that the supermarket has been stocking the
longest (i.e., something it began selling 120 years ago) and get rid of it on the grounds
that no one is interested any more. In effect, the supermarket maintains a linked list of
all the products it currently sells in the order they were introduced. The new one goes
on the back of the list; the one at the front of the list is dropped.
As a page replacement algorithm, the same idea is applicable. The operating system
maintains a list of all pages currently in memory, with the page at the head of the list
the oldest one and the page at the tail the most recent arrival. On a page fault, the
page at the head is removed and the new page added to the tail of the list. When
applied to stores, FIFO might remove mustache wax, but it might also remove flour,
salt, or butter. When applied to computers the same problem arises. For this reason,
FIFO in its pure form is rarely used.
0 3 7 8 12 14 15 18
Most recently loaded page
A B C D E F G H
3 7 8 12 14 15 18 20
B C D E F G H A
Summary
1. CPU fetches the instruction from memory according to the value of ______________.
2. A memory buffer used to accommodate a speed differential is called__________.
3. Run time mapping from virtual to physical address is done by ____________.
4. The address of a page table in memory is pointed by ___________.
1. Frames
2. Context-switch
3. Page number
4. Page
1. True
2. False
3. True
1. Program counter
2. Cache
3. Memory management unit
4. Page table base register.
References used:
Notes
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
_______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
File Systems
5.0 Objectives
5.1 Introduction
5.0 Objectives
To explain the function of file systems
To describe the interfaces to file systems
To discuss file-system design tradeoffs, including access methods, file
sharing, file locking, and directory structures
To explore file-system protection
5.1 Introduction
A file system is the part of the operating system that is responsible for
managing files and the resources on which these reside. Without a file system,
efficient computing would essentially be impossible. This chapter discusses the
Given that main memory is volatile, i.e., does not retain information when power
is turned off, and is also limited in size, any computer system must be equipped with
secondary memory on which the user and the system may keep information for
indefinite periods of time. By far the most popular secondary memory devices are disks
for random access purposes and magnetic tapes for sequential, archival storage. Since
these devices are very complex to interact with, and, in multiuser systems are shared
among different users, operating systems (OS) provide extensive services for managing
data on secondary memory. These data are organized into files, which are collections of
data elements grouped together for the purposes of access control, retrieval, and
modification.
The file system, in collaboration with the I/O system, has the following three basic
functions:
1. Present a logical or abstract view of files and directories to the users by hiding the
physical details of secondary storage devices and the I/O operations for communicating
with the devices.
2. Facilitate efficient use of the underlying storage devices.
3. Support the sharing of files among different users and applications. This includes
providing protection mechanisms to ensure that information is exchanged in a controlled
and secure manner.
The first function exists because physical device interfaces are very complex.
They also change frequently as new devices replace outdated ones. The I/O system,
provides the first level of abstraction on top of the hardware devices. It presents an
interface where devices may be viewed as collections or streams of logical blocks,
The primary function of this level is to use the symbolic file name to retrieve the
descriptive information necessary to manipulate the file. This information is then
passed to the basic file system module, which opens the file for access and returns the
corresponding open file ID to the directory management module. Depending on the
user-level command being processed, the open file ID may be returned to the user for
subsequent read/write access to the file, or it may be used by the directory
management module itself. For example, a search through the hierarchy structure
requires that the directory management repeatedly opens and reads subdirectories to
find a desired file. At each step of the search, the directory management routines must
call upon the lower-level basic file system to open these subdirectories.
Basic File System This part activates and deactivates files by invoking opening
and closing routines. It is also responsible for verifying the access rights of the caller
on each file request. The basic file system maintains information about all open files in
main memory data structures called open file tables (OFT). The open file ID that is
returned to the caller when a file is opened points directly to the corresponding entry in
an open file table. Using this ID instead of the symbolic file name allows subsequent
read and write operations to bypass the directory management and basic file system
modules when accessing the file data.
Logical Records
Logical records may be of fixed or variable length. In the first case, a logical record
can be a single byte, a word, or a structure of arbitrarily nested fixed-length
components. Regardless of the complexity of each record, all records within a file must
have the same length. In the second case, records may have different lengths; the size
or length of a record is typically recorded as part of each record so that access method
operations can conveniently locate the end of any given record. Fixed-length record files
are easier to implement and are the most common form supported by modern OSs.
Record Addressing
To access a record within a file, the operation must address it in some way. This can be
done either implicitly or explicitly. For implicit addressing, all records are accessed in
Each OS implements its own view of what specific attributes should be maintained. The
following types of information are generally considered:
• Ownership. This records the name of the file owner. In most systems, the file
creator is its owner. Access privileges are usually controlled by the owner, who
may then grant them to others.
• File Size. The file system needs current file size information to effectively manage its
blocks on disk. File size is also important for the user, and hence is readily available
at the user level, typically as one of the results of a directory scan operation.
• File Use. For a variety of reasons, including security, recovery from failure, and
performance monitoring, it is useful to maintain information about when and how
the file has been used. This may include the time of its creation, the time of its
last use, the time of its last modification, the number of times the file has been
opened, and other statistical information.
• File Disposition. A file could be temporary, to be destroyed when it is closed,
when a certain condition is satisfied, or at the termination of the process for which
it was created; or it may be stored indefinitely as a permanent file.
• Protection. This information includes who can access a file and how a file can
5.2.1 Create/Delete
Before a file can be used in any way, it must be created. The create command, which
generally accepts a symbolic file name as one of its parameters, creates the file identity
so that it can be referred to in other commands by its symbolic name. The delete or
destroy command reverses the effect of the creation by eliminating the file and all its
contents from the file system. Since deleting a file by mistake is a common problem
with potentially serious consequences, most file systems will ask for confirmation before
actually performing the operation. Another common safety measure is to delete any file
only tentatively so that it can later be recovered if necessary. For example, the Windows
OS will place a file to be deleted into a special directory called the Recycle Bin, where
it remains indefinitely. Only when the Recycle Bin is explicitly emptied, e.g., to free up
disk space, is the file deleted irrevocably.
5.2.4 Seek/Rewind
Purely sequential access is too restrictive for many applications. To avoid having to
read a file each time from the beginning, a seek command is frequently provided. It
moves the current record pointer to an arbitrary position within the file. Thus a seek
followed by a read or write essentially emulates the effect of a direct access. How the
seek operation is implemented depends on how the file is organized internally, but it can
usually be done much more efficiently than reading all records from the beginning.
(Note that the seek operation discussed here is a high-level file operation, and should
not be confused with a disk seek operation, which moves the disk‘s read/write head to a
File Descriptors
Section 10.3 introduced types of descriptive information associated with a file, including
its name, type, internal organization, size, ownership and protection information, and its
location on secondary memory. Where this information is kept is an important design
decision. One extreme is to maintain the descriptive information dispersed throughout
different data structures based on its use by different subsystems or applications. For
example, some information can be kept in the parent directory, some on a dedicated
portion of the disk, and some with the file itself. The other extreme—a cleaner solution
keeps all descriptive information about a file segregated in a separate data structure,
pointed to from the parent directory. This data structure is generally referred to as the
file descriptor.
Opening and closing of files involve two components of the file descriptor:
1) protection information to verify the legality of the requested access;
2) location information necessary to find the file data blocks on the secondary storage
device.
The implementation of the open and close functions vary widely with different file
systems, but the following list gives the typical tasks performed in some form as part of
these functions.
Open
• Using the protection information in the file descriptor, verify that the process (user)
has the right to access the file and perform the specified operations.
• Find and allocate a free entry in the OFT.
• Allocate read/write buffers in main memory and other resources as necessary for
the given type of file access.
• Complete the components of the OFT entry. This includes initialization information,
such as the current position (zero) of a sequentially accessed file. It also
includes relevant information copied from the file descriptor, such as the file length
and its location on the disk. Additional runtime information, such as the pointers
to the allocated buffers or other resources, also is placed into the OFT entry.
• If all of the above operations are successful, return the index or the pointer to the
allocated OFT entry to the calling process for subsequent access to the file.
Close
Sequential Access
read n
write n
position to n
read next
write next
rewrite n
n= relative block number
A hard link ( usually just called a link ) involves multiple directory entries that both
refer to the same file. Hard links are only valid for ordinary files in the same file system.
A symbolic link that involves a special file, containing information about where to
find the linked file. Symbolic links may be used to link directories and/or files in other file
systems, as well as ordinary files in the current file system. Windows only supports
symbolic links, termed shortcuts.
Hard links require a reference count, or link count for each file, keeping track of
how many directory entries are currently referring to this file. Whenever one of the
references is removed the link count is reduced, and when it reaches zero, the disk
space can be reclaimed.
For symbolic links there is some question as to what to do with the symbolic links
when the original file is moved or deleted: One option is to find all the symbolic links
and adjust them also. Another is to leave the symbolic links dangling, and discover that
they are no longer valid the next time they are used.
Sub-trees can become disconnected from the rest of the tree and still not have their
reference counts reduced to zero. Periodic garbage collection is required to detect and
resolve this problem. ( chkdsk in DOS and fsck in UNIX search for these problems,
among others, even though cycles are not supposed to be allowed in either system.
Disconnected disk blocks that are not marked as free are added back to the file systems
with made-up file names, and can usually be safely deleted. )
Once a file system is mounted onto a mount point, any further references to that
directory actually refer to the root of the mounted file system.
Any files ( or sub-directories ) that had been stored in the mount point directory prior to
mounting the new file system are now hidden by the mounted file system, and are no
longer available. For this reason some systems only allow mounting onto empty
directories.
File systems can only be mounted by root, unless root has previously configured certain
file systems to be mountable onto certain pre-determined mount points. ( E.g. root may
allow users to mount floppy file systems to /mnt or something like it. ) Anyone can run
the mount command to see what file systems are currently mounted.
Multiple Users
The advent of the Internet introduces issues for accessing files stored on
remote computers
o The original method was ftp, allowing individual files to be
transported across systems as needed. Ftp can be either account
and password controlled, or anonymous, not requiring any user
name or password.
o Various forms of distributed file systems allow remote file systems
to be mounted onto a local directory structure, and accessed using
normal file access commands. ( The actual files are still transported
across the network as needed, possibly using ftp as the underlying
transport mechanism. )
o The WWW has made it easy once again to access files on remote
systems without mounting their file systems, generally using
(anonymous) ftp as the underlying file transport mechanism.
Failure Modes
File Replication
Keeping multiple copies of a file on different servers has several important benefits:
• Availability. When a server holding the only copy of a file crashes, the file becomes
inaccessible. With additional replicas, users may continue accessing the file unimpeded.
• Reliability. When a file server crashes, some files may be left in an inconsistent state.
Having multiple independent copies of a file is an important tool for the recovery
process.
File replication is similar to file-level caching in the client. In both cases, multiple copies
of a file are maintained on different machines. The main difference is that caching only
maintains a temporary copy in the client when the file is being used. With file replication,
the copy is permanent. Furthermore, a cached copy is often kept on the client‘s
machine, and a replicated file is kept on a separate server that may be a different
machine from the client‘s.
Again, the problem with file replication is consistency. Similar to caching, the system
must guarantee that all update operations are applied to all replicas at the same time or
the file semantics must be relaxed. There are two main protocols the file system can
follow when reading and writing file replicas to keep them consistent:
A file management system should not be confused with a file system, which
manages all types of data and files in an operating system (OS), or a database
management system (DBMS), which has relational database capabilities and includes a
programming language for further data manipulation.
Suggested readings
References used:
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
_____________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
_____________________________________________________________________________________
______________________________________________________________________________________
_____________________________________________________________________________________
I/O Systems
6.0 Objectives
6.1 Introduction
6.7 Summary
6.0 Objectives
6.1 Introduction
One of the important jobs of an Operating System is to manage various I/O devices
including mouse, keyboards, touch pad, disk drives, display adapters, USB devices,
Bit-mapped screen, LED, Analog-to-digital converter, On/off switch, network
connections, audio I/O, printers etc.
Block devices − A block device is one with which the driver communicates by
sending entire blocks of data. For example, Hard disks, USB cameras, Disk-On-
Key etc.
Device drivers are software modules that can be plugged into an OS to handle a
particular device. Operating System takes help from device drivers to handle all I/O
devices.
The Device Controller works like an interface between a device and a device driver. I/O
units (Keyboard, mouse, printer, etc.) typically consist of a mechanical component and
an electronic component where electronic component is called the device controller.
There is always a device controller and a device driver for each device to communicate
with the Operating Systems. A device controller may be able to handle multiple
devices. As an interface its main task is to convert serial bit stream to block of bytes,
perform error correction as necessary.
Any device connected to the computer is connected by a plug and socket, and the
socket is connected to a device controller. Following is a model for connecting the
CPU, memory, controllers, and I/O devices where CPU and device controllers all use a
common bus for communication.
I/O Hardware:
Incredible variety of I/O devices
Storage (disk, tapes)
Transmission (network connections, Bluetooth)
Human-interface (screen, keyboard, mouse)
Common concepts – signals from I/O devices interface with computer
Port – connection point for device (e.g., serial port)
Bus – a set of wires and a rigidly defined protocol
daisy chain or shared direct access
PCI bus common in PCs and servers, PCI Express (PCIe) (>16GB/s)
expansion bus connects relatively slow devices
Controller (host adapter) – electronics that operate port, bus, device
Sometimes integrated
Sometimes separate circuit board (host adapter)
Contains processor, microcode, private memory, bus controller, etc.
One or more platters in the form of disks covered with magnetic media. Hard
disk platters are made of rigid metal, while "floppy" disks are made of more
flexible plastic.
Each platter has two working surfaces. Older hard disk drives would sometimes
not use the very top or bottom surface of a stack of platters, as these surfaces
were more susceptible to potential damage.
Each working surface is divided into a number of concentric rings
called tracks. The collection of all tracks that are the same distance from the
edge of the platter, (i.e. all tracks immediately above one another in the following
diagram) is called a cylinder.
Each track is further divided into sectors, traditionally containing 512 bytes of
data each, although some modern disks occasionally use larger sector sizes.
(Sectors also include a header and a trailer, including checksum information
among other things. Larger sector sizes reduce the fraction of the disk consumed
by headers and trailers, but increase internal fragmentation and the amount of
disk that must be marked bad in the case of errors. )
The data on a hard drive is read by read-write heads. The standard configuration
(shown below) uses one head per surface, each on a separate arm, and
controlled by a common arm assembly which moves all heads simultaneously
from one cylinder to another. (Other configurations, including independent read-
write heads, may speed up disk access, but involve serious technical difficulties.)
The storage capacity of a traditional disk drive is equal to the number of heads
(i.e. the number of working surfaces), times the number of tracks per surface,
times the number of sectors per track, times the number of bytes per sector. A
In operation the disk rotates at high speed, such as 7200 rpm (120 revolutions
per second.) The rate at which data can be transferred from the disk to the
computer is composed of several steps:
o The positioning time, a.k.a. the seek time or random access time is the
time required to move the heads from one cylinder to another, and for the
heads to settle down after the move. This is typically the slowest step in
the process and the predominant bottleneck to overall transfer rates.
We say that the "read/write head is at cylinder #2", when we mean that the top read-
write head is at track #2 of the top surface, the next head is at track #2 of the next
surface, the third head is at track #2 of the third surface, etc.
The unit of information transfer is the sector (though often whole tracks may be read
and written, depending on the hardware).
As far as most file systems are concerned, though, the sectors are what matter. In fact
we usually talk about a 'block device'. A block often corresponds to a sector, though it
need not do: several sectors may be aggregated to form a single logical block.
Disk Structure
Disk drives can be attached either directly to a particular host (a local disk) or to a
network.
Disk scheduling is 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:
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.
Rotational Latency: Rotational Latency is the time taken by the desired sector of
disk to rotate into a position so that it can access the read/write heads. So the disk
scheduling algorithm that gives minimum rotational latency is better.
Transfer Time: Transfer time is the time to transfer the data. It depends on the
rotating speed of the disk and number of bytes to be transferred.
Disk Access Time: Disk Access Time is:
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:
Disadvantages:
2. SSTF: 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.
Advantages:
Disadvantages:
3. SCAN: 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
Low variance of response time
Average response time
Disadvantages:
Long waiting time for requests for locations just visited by disk arm
4. CSCAN: 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 CSAN 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).
6.7 Summary
An I/O system is required to take an application I/O request and send it to the
physical device, then take whatever response comes back from the device and send it
to the application. I/O devices can be divided into two categories −
Slow devices like keyboards will generate an interrupt to the main CPU after
each byte is transferred. If a fast device such as a disk generated an interrupt for each
byte, the operating system would spend most of its time handling these interrupts. So a
typical computer uses direct memory access (DMA) hardware to reduce this overhead.
Direct Memory Access (DMA) means CPU grants I/O module authority to read
from or write to memory without involvement. DMA module itself controls exchange of
data between main memory and the I/O device. CPU is only involved at the beginning
and end of the transfer and interrupted only after entire block has been transferred.
1. Device Driver
2. host controller, disk controller
1. False
2. True
Suggested readings
7. Operating System Concepts by Abraham Silberschatz, Peter B. Galvin &
Greg Gagne.
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
_____________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
_____________________________________________________________________________________
______________________________________________________________________________________