Vous êtes sur la page 1sur 61

Page- 1 -

Booting Process
We switch on a particular computer then at first the BIOS
(Basic Input Output System) program will get over the control. The BIOS program is a
firmware and it is usually available on an EPROM (Erasable Programmable Read only
Memory) IC (Integrated circuit).When the BIOS program runs then at first it interacts with
all peripheral devices available and attached with the system and it writes a summary
report in some predefined memory locations of the memory known as BIOS data area
(specifically in the lower memory block). As an example location no. 413H and 414H
contain the size of the memory in the system. Location no. 417H contains different key
information and so on. After completion of this process the BIOS program produces a
beep sound to indicate the successful completion of the POST (POWER ON SELF
TEST) operation. After that BIOS executes a bootstrap loader program to load the O.S.
in the computers memory.
While in the loading process, the O.S. reads the BIOS data area
and knows regarding the system configuration. And without any cross check it
configures it self. After being fully and successfully load the O.S. takes all charges
of memory management, disk management, I/O management, deadlock management,
process scheduling and synchronization and ET.
Now days as O.S. are loaded in high memory block. So a copy or
replica of BIOS data area is also copied in high memory region. This memory is called
shadow memory. Thus a computer boots.
After successful loading of the OS it does all sorts of management related operations.
As example:

Process Management
Disk Management
I/O Management
Memory Management
CPU Scheduling
Protection and Security
Virtual Memory Management
Process Synchronization
Deadlock Management

Page- 2 -

Definitions of PROCESS
A program in execution
An asynchronous activity.
The animated spirit of a procedure.
The locus of control of a procedure in execution.
That which is manifested by the existence of a process control block in the operating
system.
That entity to which processors are assigned.
The dispatch able unit.
Process States
A process goes through a series of discrete process steps. Various events can cause a process
to change states.

A process is said to be running, if it currently has the CPU.


A process is said to be ready, if it could use CPU if one were available.
A process is said to be blocked, if it is waiting to some event to happen before it can
proceed.

When a job is admitted to the system, a corresponding process is created and normally
inserted at the back of the ready list. The process gradually moves to the head of the ready
list as the processes before it complete their turns at using the CPU.When the process reaches
the head of the list, and when the CPU becomes available the process starts using the CPU
and it is said to make a state transition from Ready state to Running state. The assignment of
the CPU to the first process on the ready list is called Dispatching and is performed by a
system entity called the dispatcher. We indicate this transition as follows:
Dispatch < process_name > : ready running
To prevent any one process from monopolizing the system, either accidentally or maliciously,
the OS sets a hardware interrupting clock (or interval timer) to allow this user to run for a
specific time interval or quantum. If the process does not voluntarily relinquish the CPU
before the time interval expires, the interrupting clock generates an interrupt, causing the OS
to regain control, then OS makes the previously running process ready and makes the first
process on the ready list running. So we have
Timerrunout < process_name > : running ready and
Dispatch < process_name > : ready running

Page- 3 -

If a running process initiates a i/p or o/p operation before its quantum expires, the running
process voluntarily relinquishes the CPU. So, the transition is
Block < process_name > : running blocked
The only other allowable state transition occurs when an i/o operations are completed. So we
have,
Wakeup < process_name > : blocked ready
On a multiprocessor system a running process may be suspended by another process running
at that moment on a different processor. So the transition
Suspend < process_name > : ready suspendedready
A suspendedready process may be made ready by another process. So the transition
Resume < process_name > : suspendedready ready

Page- 4 A blocked process may be suspended by another process. So the transition


Suspend < process_name > : blocked suspendedblocked
A suspended blocked process may be resumed by another process. So the transition
Resume < process_name > : suspendedblocked blocked
Because suspension is normally a high-priority activity it should be performed immediately.
When the completion finally occurrs, the suspendedblocked process makes the transition
Completion < process_name > : suspendedblocked suspendedready

Concurrent Processes

A process is a sequence of operations carried out one at a time. The precise definition
of an operation depends on the level of detail at which the process is described. For some
purpose we may regard a process as a single operation A, as shown on top of the figure. For
other purposes, it may be more convenient to look upon the same process as a sequence of
simpler operations B,C, D, E. And when we examine it in still more detail, previously
recognized operations can be partitioned into still simpler ones: F, G, H and so on. So a
process is described in terms of increasingly simpler operations which are carried out in
increasingly smaller grains of time.
Processes are concurrent if their executions overlap in time. The following figure
shows three concurrent processes P, Q and R.

Page- 5 -

Whether the individual operations of concurrent processes are overlapped or interleaved in


time, or both, is irrelevant. Whenever the first operation of one process started before the last
operation of another process is completed, the two processes are concurrent.
Concurrent Statements
The language notation:
cobegin S1; S2; .; Sn coend
indicates that the statements S1, S2, . Sn can be executed concurrently.
To define the effect of a concurrent statement, we must take into account the statements S0
and Sn+1, which precede and follow it in a given program:
S0 cobegin S1; S2; .; Sn coend Sn+1
This piece of program can be represented by the precedence graph shown as below:

Precedence graph of the concurrent statements

Page- 6 Draw the precedence graph for the following problems


co begin
S1;
begin
S2;
co begin S3; S4 co end
S5;
end
S6;
Co end

S1;
co begin
S2;
begin
S4;
co begin S5; S6 co end
S7;
co begin S8; S9 co end
end
S3;
co end
S10;

Precedence graph of nested concurrent statements

Page- 7 Q.1. Solve the following crossword puzzle using the given hints:

Hints:
Top-Down:
1. A program in execution.
Sideway:
1. A light-weighted process.
2. Assignment of CPU to the first process on the list.
3. Data structure containing certain important information about process.
Q.2. In a time-sharing operating system, when the time slot given to a process is completed,
the process goes from the RUNNING state to the
a) BLOCKED state
b) READY state
c) SUSPENDED state
d) TERMINATED state
Q.3. Suppose that a process is in BLOCKEND state waiting for some I/O service. When the
service is completed, its goes to the
a) RUNNING state
b) READY state
c) SUSPENDED state
d) TERMINATED state

Page- 8 Q.4. What are the ve major activities of an operating system in regard to Process management?
Q.5. When a process creates a new process using the fork() operation, which of the following
state is shared between the parent process and the child process?
a. Stack
b. Heap
c. Shared memory segments
Answers:
2.(b)Quantum is provided among n users if quantum (quantum is = 1) then a process goes to
READY state from RUNNING for getting another time slice.
3.(b)

4. a. The creation and deletion of both user and system processes


b. The suspension and resumption of processes
c. The provision of mechanisms for process synchronization
d. The provision of mechanisms for process communication
e. The provision of mechanisms for deadlock handling
5. Only the shared memory segments are shared between the parent process and the newly
forked child process. Copies of the stack and the heap are made for the newly created
process.

Page- 9 -

Process or CPU Scheduling


Scheduler decides the process to run first by using a scheduling algorithm
Desirable features of a scheduling algorithm
Fairness: Make sure each process gets its fair share of the CPU
Efficiency: Keep the CPU busy 100% of the time
Response time: Minimize response time for interactive users
Turnaround: Minimize the time batch users must wait for output
Throughput: Maximize the number of jobs processed per hour
Types of scheduling
Preemptive

Temporarily suspend the logically runnable processes


More expensive in terms of CPU time (to save the processor state)
Can be caused by Interrupt. Not dependent on the execution of current
instruction but a reaction to an external asynchronous event Trap.
Happens as a result of execution of the current instruction; used for
handling error or exceptional condition supervisor call. Explicit request to
perform some function by the kernel
Nonpreemptive
Run a process to completion
The Universal Scheduler: specified in terms of the following concepts
1. Decision Mode
Select the process to be assigned to the CPU
Priority function
Applied to all processes in the ready queue to determine the current priority
3. Arbitration rule
Applied to select a process in case two processes are found with the same
current priority
The Decision Mode

Time (decision epoch) to select a process for execution


Preemptive and nonpreemptive decision
Selection of a process occurs
1. when a new process arrives
2. when an existing process terminates

Page- 10 3. when a waiting process changes state to ready


4. when a running process changes state to waiting (I/O request)
5. when a running process changes state to ready (interrupt)
6. every q seconds (quantum-oriented)
7. when priority of a ready process exceeds the priority of a running
process

Selective preemption: Uses a bit pair (up, vp)

up set if p may preempt another process


vp set if p may be preempted by another process
The Priority Function

Defines the priority of a ready process using some parameters associated with
the process

Memory requirements

Important due to swapping overhead


Smaller memory size Less swapping overhead
Smaller memory size More processes can be serviced

Attained service time

Total time when the process is in the running state

Real time in system

Total actual time the process spends in the system since its arrival

Total service time

Total CPU time consumed by the process during its lifetime


Equals attained service time when the process terminates
Higher priority for shorter processes
Preferential treatment of shorter processes reduces the average time a process
spends in the system

External priorities

Differentiate between classes of user and system processes


Interactive processes Higher priority
Batch processes Lower priority
Accounting for the resource utilization Timeliness
Dependent upon the urgency of a task
Deadlines

Page- 11

System load

Maintain good response time during heavy load


Reduce swapping overhead by larger quanta of time
The Arbitration Rule

Random choice

Round robin (cyclic ordering)

chronological ordering (FIFO)

Time-Based Scheduling Algorithms


May be independent of required service time
First-in/First-out Scheduling
Simplest CPU-scheduling algorithm
Nonpreemptive decision mode
Upon process creation, link its PCB to rear of the FIFO queue
Scheduler allocates the CPU to the process at the front of the FIFO queue
Average waiting time can be long

Page- 12 -

-Priority function P (r) = r


Last-in/First-out Scheduling
Similar to FIFO scheduling
Average waiting time is calculated from:
P3
1

P2
3

P1
6

Average waiting time= 3 units


Substantial saving but what if the order of arrival is reversed.
Priority function P (r) = -r
Shortest Job Next Scheduling
Associate the length of the next CPU burst with each process
Assign the process with shortest CPU burst requirement to the CPU
Nonpreemptive scheduling
Specially suitable to batch processing (long term scheduling)
Ties broken by FIFO scheduling
Consider the following set of processes

Using FIFO scheduling, the average waiting time is given by


= 10.25 units
Priority function P (t) = -t

30

Page- 13 Provably optimal scheduling Least average waiting time


Moving a short job before a long one decreases the waiting time for short job
more than it increase the waiting time for the longer process
Problem: To determine the length of the CPU burst for the jobs
Longest Job First Scheduling Homework exercise
Shortest Remaining Time Scheduling
Preemptive version of shortest job next scheduling
Preemptive in nature (only at arrival time)
Highest priority to process that need least time to complete
Priority function P () =1/r
Consider the following processes

Round-Robin Scheduling
Preemptive in nature
Preemption based on time slices or time quanta
Time quantum between 10 and 100 milliseconds
All user processes treated to be at the same priority
Ready queue treated as a circular queue
New processes added to the rear of the ready queue
Preempted processes added to the rear of the ready queue
Scheduler picks up a process from the head of the queue and dispatches it
with a timer interrupt set after the time quantum
CPU burst < 1 quantum process releases CPU voluntarily
Timer interrupt results in context switch and the process is put at the rear of the
ready queue
No process is allocated CPU for more than 1 quantum in a row
Consider the following processes

Page- 14 -

Average waiting time = = 5.66 milliseconds


Let there be n processes in the ready queue, and q be the time quantum, then
each process gets of CPU time in chunks of at most q time units
Hence, each process must wait no longer than (n - 1) q time units for its next
quantum
Performance depends heavily on the size of time quantum
Large time quantum FIFO scheduling
Small time quantum Large context switching overhead
Rule of thumb: 80% of the CPU bursts should be shorter than the time
quantum
Multilevel Feedback Scheduling
Most general CPU scheduling algorithm
Background
Make a distinction between foreground (interactive) and background (batch)
processes
Different response time requirements for the two types of processes and
hence, different scheduling needs
Separate queue for different types of processes, with the process priority
being defined by the queue
Separate processes with different CPU burst requirements
Too much CPU time lower priority
I/O-bound and interactive process higher priority
Aging to prevent starvation
n different priority levels 1 n
Each process may not receive more than T time units at priority level
When a process receives time T, decrease its priority to - 1
Process may remain at the lowest priority level for infinite time
Policy Driven CPU Scheduling
Based on a policy function
Policy function gives the correlation between actual and desired resource
utilization
Attempt to strike a balance between actual and desired resource utilization
Comparison of scheduling methods

Page- 15 Average waiting time


Average turnaround time

Throughput
In communication networks, such as Ethernet or packet radio, throughput or network
throughput is the average rate of successful message delivery over a communication
channel. This data may be delivered over a physical or logical link, or pass through a certain
network node. The throughput is usually measured in bits per second (bit/s or bps), and
sometimes in data packets per second or data packets per time slot.
The system throughput or aggregate throughput is the sum of the data rates that are
delivered to all terminals in a network.
The throughput can be analyzed mathematically by means of queueing theory, where the load
in packets per time unit is denoted arrival rate , and the throughput in packets per time unit
is denoted departure rate .
Throughput is essentially synonymous to digital bandwidth consumption.

Q.1. Solve the following crossword puzzle using the given hints:

Hints:
Top-Down:
1. A small unit of time assigned to each process for utilizing the CPU.

Page- 16 -

Sideway:
1. Number of processes completed per time unit.
2. ---- chart is used for representing CPU scheduling.
3. Round Robin scheduling is a ---- scheduling.
Q.2.

If the CPU scheduling policy FCFS, the average waiting time will be
a)
b)
c)
d)

12.8 ms
8 ms
6 ms
none of these

Q.3.

If the CPU scheduling policy is SJF, the average waiting time (without pre-emption) will be
a) 16 ms
b) 12.8
c) 6.8 ms
d) none of these

Page- 17 Q.4. Suppose that the following processes arrive for execution at the times indicated. Each
process will run the listed amount of time. In answering the questions, use nonpreemptive
scheduling and base all decisions on the information you have at the time the decision must
be made.
Process
P1
P2
P3

Arrival Time

Burst Time

0.0
0.4
1.0

8
4
1

a. What is the average turnaround time for these processes with the FCFS scheduling
algorithm?
b. What is the average turnaround time for these processes with the SJF scheduling
algorithm?
Q.5. Suppose that the following processes arrive for execution at the times indicated. Each
process will run the listed amount of time. Use preemptive SJF scheduling to calculate
average waiting time.
Process
P1
P2
P3
P4

Arrival Time
0
1
2
3

Burst Time
8
4
9
5

Q.6. What advantage is there in having different time-quantum sizes on different


levels of a multilevel queuing system?
Answers:

2.

3.

Page- 18 -

4. a. 10.53
b. 9.53
5. The

Gantt chart is as follows:

Average waiting time = ((10-1-0) + (1-1) + (17-2) + (5-3))/4 = 26/4 = 6.5 milliseconds.
Average turnaround time = ((17-0) + (5-1) + (26-2) + (10-3))/4 = 52/4 = 13 milliseconds.
6. Processes that need more frequent servicing, for instance, interactive
processes such as editors, can be in a queue with a small time quantum.
Processes with no need for frequent servicing can be in a queue with a larger
quantum, requiring fewer context switches to complete the processing, and thus
making more efficient use of the computer.

Page- 19 -

Case study of Process Synchronization


Readers and Writers: Problem Definition
Two kinds of concurrent processes, called readers and writers, share a single resource.
The readers can use the resource simultaneously, but each writer must have exclusive
access to it. When a writer is ready to use the resource, it should be enabled to do so as
soon as possible.
So solution lo this kind of resource allocation problem must be of the following nature:
Request resource;
Use resource;
Release resource;
A process is called active from the moment it has requested the resource until it s
released the resource again. A process is called running from the moment it has been
granted permission to use the resource until it has released the resource again.
The state of the system can be characterized by four integers, all initialized to zero:
ar
rr
aw
rw

the number of active readers


the number of running readers
the number of active writers
the number of running writers

Correctness criteria
A solution to the simplified problem is correct if the following criteria are satisfied:
(1) Scheduling of waiting processes Readers can use the resource simultaneously and so
can writers, but the number of running processes cannot exceed the number of active
processes:
0<=rr<=ar & 0<rw<=aw
(2) Mutual exclusion of running processes : Readers and writers cannot use the resource

Page- 20 at the same time:


Not (rr> 0 & rw> 0)
(3) No deadlock of active processes: When no processes are running, active processes
can 1art using the resource within a finite time:
(rr=0&rw=0)&(ar>0orw>0)implies
(rr > 0 or rw > 0 ) within finite time
(4) Writer have priority over readers: The requirement of mutual exclusion means that
the resource can only be granted -to an active writer when there are no running readers
(rr=0). To give priority to writers, we make the slightly stronger condition that the
resource can only be granted to an active reader when there are no active writers(aw =0).

Algorithms
Procedure grant reading (var v: T; reading: semaphore);
Begin
with v do
If aw = 0 then
while rr < ar do
begin
rr:= rr + 1;
signal(reading);
end
end
Procedure grant writing (var v: T; writing: semaphore);
Begin
with v do
If rr =0 then
while rw < ado
begin
rw:= rw + 1;
signal(writing);
end
end
The readers and writers problem solved with semaphores
type T = record ar, rr, aw. rw : integer end var v : shared T; reading, writing: semaphore;
Initially ar = rr = aw = rw reading = writing = 0
cobegin
begin reader
region v do
begin
ar:=ar+ 1;
grant reading (v,reading);
end

Page- 21 wait (reading);


read;
region v do
begin
rr:=rr -1;
ar:= ar -1;
grant writing (v,writing);
end
---end
begin writer
region v do begin
aw:=aw + 1;
grant writing (v,writing);
end
wait (writing);
write;
region v do
begin
rw:=rw -1;
aw: = aw-1;
grant reading (v,reading);
end
---end
coend
A definition of binary semaphore primitives
type binary semaphore = record
value : (0.1):
queue : list of process
end.
Var s : binary semaphore;
Wait B(s)
If s.value = 1
Then s.value = 0
Else
Begin
Place this process to S. queue;

Page- 22 Block this process


End;
Signal B(s)
If s.queue is empty
Then s.value 1
Else
Begin
Remove a process from s.queue
Place process P on ready list;
End;

Page- 23 -

Q.1. Solve the following crossword puzzle using the given hints:

Hints:
Top-Down:
1. A synchronization tool having two standard atomic operations.
Sideway:
1. A situation where a process is blocking progress of another process and vice-versa.
2. In ----- exclusion at least one resource must be held in a non-sharable mode.
3. Each process has a segment of code for using resources which is called a ---- section.
Q.2. A state is safe if the system can allocated resource to each process (up to its maximum)
in some order and still avoid deadlock. Then
a) deadlock state is unsafe
b) unsafe state may lead to a deadlock situation
c) deadlock state is a subset of unsafe state.
d) all of these

Page- 24 Q.3. Mutual exclusion problem occurs between


a) two disjoint processes that do not interact.
b) processes that share resources
c) processes that do not use the same resource
d) none of these
Q.4. Suppose that a system is in an unsafe state. Show that it is possible for the processes to
complete their execution without entering a deadlock state.
Q.5. Consider a system with three resource types and the vector Available initialized to
(4,2,2). If process P0 asks for (2,2,1), it gets them. If P1 asks for (1,0,1), it gets them.
Then, if P0 asks for (0,0,1), it is blocked (resource not available). If P2 now asks for
(2,0,0), it gets the available one (1,0,0) and one that was allocated to P0 (since P0 is
blocked). P0s Allocation vector goes down to (1,2,1) and its Need vector goes up to
(1,0,1).
a. Can deadlock occur? If you answer yes, give an example. If you answer no,
specify which necessary condition cannot occur.
b. Can indenite blocking occur? Explain your answer.
Answers:
2.d)
3.b)
4. An unsafe state may not necessarily lead to deadlock, it just means that we cannot
guarantee that deadlock will not occur. Thus, it is possible that a system in an unsafe state
may still allow all processes to complete without deadlock occurring. Consider the situation
where a system has 12 resources allocated among processes P0, P1,and P2.The
resources are allocated according to the following policy:
P0
P1
P2

Max
10
4
9

Current
5
2
3

Need
5
2
6

5. a. Deadlock cannot occur because preemption exists.


b. Yes. A process may never acquire all the resources it needs if they are continuously
preempted by a series of requests such as those of process C.

Page- 25 PAGING
In computer operating systems there are various ways in which the operating system can
store and retrieve data from secondary storage for use in main memory. One such memory
management scheme is referred to as paging. In the paging memory-management scheme,
the operating system retrieves data from secondary storage in same-size blocks called pages.
The main advantage of paging is that it allows the physical address space of a process to be
noncontiguous. Prior to paging, systems had to fit whole programs into storage contiguously
which caused various storage and fragmentation problems.[1]
Paging is an important part of virtual memory implementation in most contemporary generalpurpose operating systems, allowing them to use disk storage for data that does not fit into
physical Random-access memory (RAM). Paging is usually implemented as architecturespecific code built into the kernel of the operating system.
Overview
The main functions of paging are performed when a program tries to access pages that are
not currently mapped to physical memory (RAM). This situation is known as a page fault.
The operating system must then take control and handle the page fault, in a manner invisible
to the program. Therefore, the operating system must:
1.
2.
3.
4.
5.

Determine the location of the data in auxiliary storage.


Obtain an empty page frame in RAM to use as a container for the data.
Load the requested data into the available page frame.
Update the page table to show the new data.
Return control to the program, transparently retrying the instruction that caused the
page fault.

Because RAM is faster than auxiliary storage, paging is avoided until there is not enough
RAM to store all the data needed. When this occurs, a page in RAM is moved to auxiliary
storage, freeing up space in RAM for use. Thereafter, whenever the page in secondary
storage is needed, a page in RAM is saved to auxiliary storage so that the requested page can
then be loaded into the space left behind by the old page. Efficient paging systems must
determine the page to swap by choosing one that is least likely to be needed within a short
time. There are various page replacement algorithms that try to do this.
Most operating systems use some approximation of the least recently used (LRU) page
replacement algorithm (the LRU itself cannot be implemented on the current hardware) or
working set based algorithm.
If a page in RAM is modified (i.e. if the page becomes dirty) and then chosen to be swapped,
it must either be written to auxiliary storage, or simply discarded.
To further increase responsiveness, paging systems may employ various strategies to predict
what pages will be needed soon so that it can preemptively load them.

Page- 26 Demand paging


When demand paging is used, no preemptive loading takes place. Paging only occurs at the
time of the data request, and not before. In particular, when a demand pager is used, a
program usually begins execution with none of its pages pre-loaded in RAM. Pages are
copied from the executable file into RAM the first time the executing code references them,
usually in response to page faults. As such, much of the executable file might never be loaded
into memory if pages of the program are never executed during that run.
Anticipatory paging
This technique preloads a process's non-resident pages that are likely to be referenced in the
near future (taking advantage of locality of reference). Such strategies attempt to reduce the
number of page faults a process experiences.
Memory segmentation
In computing, memory segmentation is one of the most common ways to achieve memory
protection; another common one is paging. In a computer system using segmentation, an
instruction operand that refers to a memory location includes a value that identifies a segment
and an offset within that segment. A segment has a set of permissions, and a length,
associated with it. If the currently running process is allowed by the permissions to make the
type of reference to memory that it is attempting to make, and the offset within the segment
is within the range specified by the length of the segment, the reference is permitted;
otherwise, a hardware exception is raised.
Moreover, as well as its set of permissions and length, a segment also has associated with it
information indicating where the segment is located in memory. It may also have a flag
indicating whether the segment is present in main memory or not; if the segment is not
present in main memory, an exception is raised, and the operating system will read the
segment into memory from secondary storage. The information indicating where the segment
is located in memory might be the address of the first location in the segment, or might be the
address of a page table for the segment, if the segmentation is implemented with paging. In
the first case, if a reference to a location within a segment is made, the offset within the
segment will be added to address of the first location in the segment to give the address in
memory of the referred-to item; in the second case, the offset of the segment is translated to a
memory address using the page table.

Thrashing
Most programs reach a steady state in their demand for memory locality both in terms of
instructions fetched and data being accessed. This steady state is usually much less than the
total memory required by the program. This steady state is sometimes referred to as the
working set: the set of memory pages that are most frequently accessed.

Page- 27 Virtual memory systems work most efficiently when the ratio of the working set to the total
number of pages that can be stored in RAM is low enough that the time spent resolving page
faults is not a dominant factor in the workload's performance. A program that works with
huge data structures will sometimes require a working set that is too large to be efficiently
managed by the page system resulting in constant page faults that drastically slow down the
system. This condition is referred to as thrashing: pages are swapped out and then accessed
causing frequent faults.
The Optimal Page Replacement Algorithm
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 Not Recently Used Page Replacement Algorithm
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 1until the operating system resets it to 0 in software
The First-In, First-Out (FIFO) Page Replacement Algorithm
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.
The Least Recently Used (LRU) Page Replacement Algorithm
A good approximation to the optimal algorithm is based on the observation that pages that
have been heavily used in the last few instructions will probably be heavily used again in the
next few. Conversely, pages that have not been used for pages will probably remain unused
for a long time. This idea suggests a realizable algorithm: when a page fault occurs, throw
out the page that has been unused for the longest time. This strategy is called LRU paging.

Page- 28 -

Memory protection
Memory protection is a way to control memory access rights on a computer, and is a part of
most modern operating systems. The main purpose of memory protection is to prevent a
process from accessing memory that has not been allocated to it. This prevents a bug within a
process from affecting other processes, or the operating system itself.
Q.1. Solve the following crossword puzzle using the given hints:

Hints:
Top-Down:
1. The page replacement algorithm having the least page-fault rate.
Sideway:
2.
3.
4.
5.

------ of reference is a property of processes in execution.


Sharp decrement of CPU utilization.
------- paging uses lazy swapper.
------- memory is a technique that allows the execution of processes that may not be
completely in memory.
Q.2. Determine the number of page faults when references to pages occur in the following
order: 1 2, 4, 5, 2, 1, 2, 4. Assume that the main memory can accommodate 3 pages and
the main memory already has the pages 1 and 2, with page having been brought earlier
than page 2, (LRU algorithm is used)
a)
b)
c)
d)

3
5
4
none of these

Page- 29 -

Q.3. If there are 32 segments, each of size 1 k byte, then the logical address should have
a) 13 bits
b) 14 bits
c) 15 bits
d) 16 bits
Q.4. Name two differences between logical and physical addresses.
Q.5. Why are page sizes always powers of 2?
Q.6. In a paged memory, the page hit ratio is 0.35. The time required to access a page in
secondary memory is equal to 100 ns. The time required to access a page in primary
memory is 10 ns. The average time required to access a page is
a) 3.0 ns
b) 68.0 ns
c) 68.5 ns
d) 78.5 ns
Answers:
2.

3.

Page- 30 4. A logical address does not refer to an actual existing address; rather, it refers to an
abstract address in an abstract address space. Contrast this with a physical address that
refers to an actual physical address in memory. A logical address is generated by the CPU
and is translated into a physical address by the memory management
unit(MMU).Therefore, physical addresses are generated by the MMU.
5. Recall that paging is implemented by breaking up an address into a page and offset
number. It is most efficient to break the address into X page bits and Y offset bits, rather than
perform arithmetic on the address to calculate the page number and offset. Because each bit
position represents a power of 2, splitting an address between bits results in a page size that is
a power of 2.
6.

Page- 31 -

File system
A file system is a method of storing and organizing computer files and their data. Essentially,
it organizes these files into a database for the storage, organization, manipulation, and
retrieval by the computer's operating system.
File systems are used on data storage devices such as a hard disks or CD-ROMs to maintain
the physical location of the files. Beyond this, they might provide access to data on a file
server by acting as clients for a network protocol (e.g., NFS, SMB, or 9P clients), or they
may be virtual and exist only as an access method for virtual data (e.g., procfs). It is
distinguished from a directory service and registry.

Aspects of file systems


Most file systems make use of an underlying data storage device that offers access to an array
of fixed-size physical sectors, generally a power of 2 in size (512 bytes or 1, 2, or 4 KiB are
most common). The file system is responsible for organizing these sectors into files and
directories, and keeping track of which sectors belong to which file and which are not being
used. Most file systems address data in fixed-sized units called "clusters" or "blocks" which
contain a certain number of disk sectors (usually 1-64). This is the smallest amount of disk
space that can be allocated to hold a file.
However, file systems need not make use of a storage device at all. A file system can be used
to organize and represent access to any data, whether it's stored or dynamically generated
(e.g., procfs).

File names
A file name is a name assigned to a file in order to secure storage location in the computer
memory. By this file name a file can be further accessed. Whether the file system has an
underlying storage device or not, file systems typically have directories which associate file
names with files, usually by connecting the file name to an index in a file allocation table of
some sort, such as the FAT in a DOS file system, or an inode in a Unix-like file system.
Directory structures may be flat, or allow hierarchies where directories may contain
subdirectories. In some file systems, file names are structured, with special syntax for
filename extensions and version numbers. In others, file names are simple strings, and perfile metadata is stored elsewhere.

Metadata
Other bookkeeping information is typically associated with each file within a file system.
The length of the data contained in a file may be stored as the number of blocks allocated for
the file or as an exact byte count. The time that the file was last modified may be stored as
the file's timestamp. Some file systems also store the file creation time, the time it was last
accessed, and the time that the file's meta-data was changed. (Note that many early PC

Page- 32 operating systems did not keep track of file times.) Other information can include the file's
device type (e.g., block, character, socket, subdirectory, etc.), its owner user-ID and groupID, and its access permission settings (e.g., whether the file is read-only, executable, etc.).
Arbitrary attributes can be associated on advanced file systems, such as NTFS, XFS,
ext2/ext3, some versions of UFS, and HFS+, using extended file attributes. This feature is
implemented in the kernels of Linux, FreeBSD and Mac OS X operating systems, and allows
metadata to be associated with the file at the file system level. This, for example, could be the
author of a document, the character encoding of a plain-text document, or a checksum.

Hierarchical file systems


The hierarchical file system was an early research interest of Dennis Ritchie of Unix fame;
previous implementations were restricted to only a few levels, notably the IBM
implementations, even of their early databases like IMS. After the success of Unix, Ritchie
extended the file system concept to every object in his later operating system developments,
such as Plan 9 and Inferno.

Facilities
Traditional file systems offer facilities to create, move and delete both files and directories.
They lack facilities to create additional links to a directory (hard links in Unix), rename
parent links (".." in Unix-like OS), and create bidirectional links to files.
Traditional file systems also offer facilities to truncate, append to, create, move, delete and
in-place modify files. They do not offer facilities to prepend to or truncate from the
beginning of a file, let alone arbitrary insertion into or deletion from a file. The operations
provided are highly asymmetric and lack the generality to be useful in unexpected contexts.
For example, interprocess pipes in Unix have to be implemented outside of the file system
because the pipes concept does not offer truncation from the beginning of files.

Secure access
Secure access to basic file system operations can be based on a scheme of access control lists
or capabilities. Research has shown access control lists to be difficult to secure properly,
which is why research operating systems tend to use capabilities. [citation needed] Commercial file
systems still use access control lists.

Types of file systems


File system types can be classified into disk file systems, network file systems and special
purpose file systems.

Page- 33 -

Disk file systems


A disk file system is a file system designed for the storage of files on a data storage device,
most commonly a disk drive, which might be directly or indirectly connected to the
computer. Examples of disk file systems include FAT (FAT12, FAT16, FAT32, exFAT),
NTFS, HFS and HFS+, HPFS, UFS, ext2, ext3, ext4, btrfs, ISO 9660, ODS-5, Veritas File
System, ZFS and UDF. Some disk file systems are journaling file systems or versioning file
systems.
ISO 9660 and Universal Disk Format are the two most common formats that target Compact
Discs and DVDs. Mount Rainier is a newer extension to UDF supported by Linux 2.6 series
and Windows Vista that facilitates rewriting to DVDs in the same fashion as has been
possible with floppy disks.

Flash file systems


A flash file system is a file system designed for storing files on flash memory devices. These
are becoming more prevalent as the number of mobile devices is increasing, and the capacity
of flash memories increase.
While a disk file system can be used on a flash device, this is suboptimal for several reasons:

Erasing blocks: Flash memory blocks have to be explicitly erased before they can be
rewritten. The time taken to erase blocks can be significant, thus it is beneficial to
erase unused blocks while the device is idle.
Random access: Disk file systems are optimized to avoid disk seeks whenever
possible, due to the high cost of seeking. Flash memory devices impose no seek
latency.
Wear levelling: Flash memory devices tend to wear out when a single block is
repeatedly overwritten; flash file systems are designed to spread out writes evenly.

Log-structured file systems have many of the desirable properties for a flash file system.
Such file systems include JFFS2 and YAFFS.

Tape file systems


A tape file system is a file system and tape format designed to store files on tape in a selfdescribing form. Magnetic tapes are sequential storage media, posing challenges to the
creation and efficient management of a general-purpose file system. IBM has recently
announced and made available as open source a new file system for tape called LTFS "Linear
Tape File System" or "Long Term File System". LTFS allows to directly create files on tape
and work with them like working with files on a disk drive.

Page- 34 -

Database file systems


A new concept for file management is the concept of a database-based file system. Instead of,
or in addition to, hierarchical structured management, files are identified by their
characteristics, like type of file, topic, author, or similar metadata.

Transactional file systems


Each disk operation may involve changes to a number of different files and disk structures. In
many cases, these changes are related, meaning that it is important that they all be executed
at the same time. For example, in the case of a bank sending money to another bank
electronically, the bank's computer will "send" the transfer instruction to the other bank and
also update its own records to indicate the transfer has occurred. If for some reason the
computer crashes before it has had a chance to update its own records, then on reset, there
will be no record of the transfer but the bank will be missing some money.
Transaction processing introduces the guarantee that at any point while it is running, a
transaction can either be finished completely or reverted completely (though not necessarily
both at any given point). This means that if there is a crash or power failure, after recovery,
the stored state will be consistent. (Either the money will be transferred or it will not be
transferred, but it won't ever go missing "in transit".)
This type of file system is designed to be fault tolerant, but may incur additional overhead to
do so.
Journaling file systems are one technique used to introduce transaction-level consistency to
file system structures.

Network file systems


A network file system is a file system that acts as a client for a remote file access protocol,
providing access to files on a server. Examples of network file systems include clients for the
NFS, AFS, SMB protocols, and file-system-like clients for FTP and WebDAV.

Shared disk file systems


A shared disk file system is one in which a number of machines (usually servers) all have
access to the same external disk subsystem (usually a SAN). The file system arbitrates access
to that subsystem, preventing write collisions. Examples include GFS from Red Hat, GPFS
from IBM, and SFS from DataPlow.

Page- 35 -

Special purpose file systems


A special purpose file system is basically any file system that is not a disk file system or
network file system. This includes systems where the files are arranged dynamically by
software, intended for such purposes as communication between computer processes or
temporary file space.
Special purpose file systems are most commonly used by file-centric operating systems such
as Unix. Examples include the procfs (/proc) file system used by some Unix variants, which
grants access to information about processes and other operating system features.
Deep space science exploration craft, like Voyager I & II used digital tape-based special file
systems. Most modern space exploration craft like Cassini-Huygens used Real-time
operating system file systems or RTOS influenced file systems. The Mars Rovers are one
such example of an RTOS file system, important in this case because they are implemented
in flash memory.

File systems and operating systems


Most operating systems provide a file system, as a file system is an integral part of any
modern operating system. Early microcomputer operating systems' only real task was file
management a fact reflected in their names (see DOS). Some early operating systems had
a separate component for handling file systems which was called a disk operating system. On
some microcomputers, the disk operating system was loaded separately from the rest of the
operating system. On early operating systems, there was usually support for only one, native,
unnamed file system; for example, CP/M supports only its own file system, which might be
called "CP/M file system" if needed, but which didn't bear any official name at all.
Because of this, there needs to be an interface provided by the operating system software
between the user and the file system. This interface can be textual (such as provided by a
command line interface, such as the Unix shell, or OpenVMS DCL) or graphical (such as
provided by a graphical user interface, such as file browsers). If graphical, the metaphor of
the folder, containing documents, other files, and nested folders is often used (see also:
directory and folder).

Flat file systems


In a flat file system, there are no subdirectorieseverything is stored at the same (root) level
on the media, be it a hard disk, floppy disk, etc. While simple, this system rapidly becomes
inefficient as the number of files grows, and makes it difficult for users to organize data into
related groups.
Like many small systems before it, the original Apple Macintosh featured a flat file system,
called Macintosh File System. Its version of Mac OS was unusual in that the file
management software (Macintosh Finder) created the illusion of a partially hierarchical filing
system on top of EMFS. This structure meant that every file on a disk had to have a unique

Page- 36 name, even if it appeared to be in a separate folder. MFS was quickly replaced with
Hierarchical File System, which supported real directories.
A recent addition to the flat file system family is Amazon's S3, a remote storage service,
which is intentionally simplistic to allow users the ability to customize how their data is
stored. The only constructs are buckets (imagine a disk drive of unlimited size) and objects
(similar, but not identical to the standard concept of a file). Advanced file management is
allowed by being able to use nearly any character (including '/') in the object's name, and the
ability to select subsets of the bucket's content based on identical prefixes.

File systems under Unix-like operating systems


Unix-like operating systems create a virtual file system, which makes all the files on all the
devices appear to exist in a single hierarchy. This means, in those systems, there is one root
directory, and every file existing on the system is located under it somewhere. Unix-like
systems can use a RAM disk or network shared resource as its root directory.
Unix-like systems assign a device name to each device, but this is not how the files on that
device are accessed. Instead, to gain access to files on another device, the operating system
must first be informed where in the directory tree those files should appear. This process is
called mounting a file system. For example, to access the files on a CD-ROM, one must tell
the operating system "Take the file system from this CD-ROM and make it appear under
such-and-such directory". The directory given to the operating system is called the mount
point - it might, for example, be /media. The /media directory exists on many Unix systems
(as specified in the File system Hierarchy Standard) and is intended specifically for use as a
mount point for removable media such as CDs, DVDs, USB drives or floppy disks. It may be
empty, or it may contain subdirectories for mounting individual devices. Generally, only the
administrator (i.e. root user) may authorize the mounting of file systems.
Unix-like operating systems often include software and tools that assist in the mounting
process and provide it new functionality. Some of these strategies have been coined "automounting" as a reflection of their purpose.
1. In many situations, file systems other than the root need to be available as soon as the
operating system has booted. All Unix-like systems therefore provide a facility for
mounting file systems at boot time. System administrators define these file systems in
the configuration file fstab or vfstab in Solaris Operating Environment, which also
indicates options and mount points.
2. In some situations, there is no need to mount certain file systems at boot time,
although their use may be desired thereafter. There are some utilities for Unix-like
systems that allow the mounting of predefined file systems upon demand.
3. Removable media have become very common with microcomputer platforms. They
allow programs and data to be transferred between machines without a physical
connection. Common examples include USB flash drives, CD-ROMs, and DVDs.
Utilities have therefore been developed to detect the presence and availability of a
medium and then mount that medium without any user intervention.

Page- 37 4. Progressive Unix-like systems have also introduced a concept called supermounting;
see, for example, the Linux supermount-ng project. For example, a floppy disk that
has been supermounted can be physically removed from the system. Under normal
circumstances, the disk should have been synchronized and then unmounted before its
removal. Provided synchronization has occurred, a different disk can be inserted into
the drive. The system automatically notices that the disk has changed and updates the
mount point contents to reflect the new medium. Similar functionality is found on
Windows machines.
5. A similar innovation preferred by some users is the use of autofs, a system that, like
supermounting, eliminates the need for manual mounting commands. The difference
from supermount, other than compatibility in an apparent greater range of
applications such as access to file systems on network servers, is that devices are
mounted transparently when requests to their file systems are made, as would be
appropriate for file systems on network servers, rather than relying on events such as
the insertion of media, as would be appropriate for removable media.

File systems under Microsoft Windows

Directory listing in a Windows command shell


Windows makes use of the FAT and NTFS file systems.

FAT
The File Allocation Table (FAT) filing system, supported by all versions of Microsoft
Windows, was an evolution of that used in Microsoft's earlier operating system (MS-DOS
which in turn was based on 86-DOS). FAT ultimately traces its roots back to the short-lived
M-DOS project and Standalone disk BASIC before it. Over the years various features have
been added to it, inspired by similar features found on file systems used by operating systems
such as Unix.

Page- 38 Older versions of the FAT file system (FAT12 and FAT16) had file name length limits, a limit
on the number of entries in the root directory of the file system and had restrictions on the
maximum size of FAT-formatted disks or partitions. Specifically, FAT12 and FAT16 had a
limit of 8 characters for the file name, and 3 characters for the extension (such as .exe). This
is commonly referred to as the 8.3 filename limit. VFAT, which was an extension to FAT12
and FAT16 introduced in Windows NT 3.5 and subsequently included in Windows 95,
allowed long file names (LFN).
FAT32 also addressed many of the limits in FAT12 and FAT16, but remains limited compared
to NTFS.
exFAT (also known as FAT64) is the newest iteration of FAT, with certain advantages over
NTFS with regards to file system overhead. But unlike prior versions of FAT, exFAT is only
compatible with newer Windows systems, such as Windows 2003 and Windows 7.

NTFS
NTFS, introduced with the Windows NT operating system, allowed ACL-based permission
control. Hard links, multiple file streams, attribute indexing, quota tracking, sparse files,
encryption, compression, reparse points (directories working as mount-points for other file
systems, symlinks, junctions, remote storage links) are also supported, though not all these
features are well-documented.
Unlike many other operating systems, Windows uses a drive letter abstraction at the user
level to distinguish one disk or partition from another. For example, the path C:\WINDOWS
represents a directory WINDOWS on the partition represented by the letter C. The C drive is
most commonly used for the primary hard disk partition, on which Windows is usually
installed and from which it boots. This "tradition" has become so firmly ingrained that bugs
came about in older applications which made assumptions that the drive that the operating
system was installed on was C. The tradition of using "C" for the drive letter can be traced to
MS-DOS, where the letters A and B were reserved for up to two floppy disk drives. This in
turn derived from CP/M in the 1970s, which however used A: and B: for hard drives, and C:
for floppy disks, and ultimately from IBM's CP/CMS of 1967.
Network drives may also be mapped to drive letters.

Distributed file system


In computing, a distributed file system or network file system is any file system that allows
access to files from multiple hosts sharing via a computer network.[1] This makes it possible
for multiple users on multiple machines to share files and storage resources.
The client nodes do not have direct access to the underlying block storage but interact over
the network using a protocol. This makes it possible to restrict access to the file system
depending on access lists or capabilities on both the servers and the clients, depending on
how the protocol is designed.

Page- 39 In contrast, in a shared disk file system all nodes have equal access to the block storage
where the file system is located. On these systems the access control must reside on the
client.
Distributed file systems may include facilities for transparent replication and fault tolerance.
That is, when a limited number of nodes in a file system go offline, the system continues to
work without any data loss.
The difference between a distributed file system and a distributed data store can be vague,
but DFSes are generally geared towards use on local area networks.

Virtual file system


A virtual file system (VFS) or virtual filesystem switch is an abstraction layer on top of a
more concrete file system. The purpose of a VFS is to allow client applications to access
different types of concrete file systems in a uniform way. A VFS can, for example, be used to
access local and network storage devices transparently without the client application noticing
the difference. It can be used to bridge the differences in Windows, Mac OS and Unix
filesystems, so that applications can access files on local file systems of those types without
having to know what type of file system they are accessing.
A VFS specifies an interface (or a "contract") between the kernel and a concrete file system.
Therefore, it is easy to add support for new file system types to the kernel simply by fulfilling
the contract. The terms of the contract might change incompatibly from release to release,
which would require that concrete file system support be recompiled, and possibly modified
before recompilation, to allow it to work with a new release of the operating system; or the
supplier of the operating system might make only backward-compatible changes to the
contract, so that concrete file system support built for a given release of the operating system
would work with future versions of the operating system.

Page- 40 -

Hierarchical directory system


Single-Level Directory
A single directory for all users.
All files must have unique names problematic when there are multiple users or
when the number of files increases

Two-Level Directory
Create a separate directory for each user
- Efficient searching: file search confined to user directory
- Different users can have files with the same name

To support file sharing, one user must be able to name a file in another users
directory
- Every file has a path name = user name + file name

Page- 41 Tree-Structured Directories


Directory structure is a tree of arbitrary height allow users to create their own
subdirectories
- A directory (or subdirectory) contains a set of files or subdirectories
When reference is made to a file
- Current working directory is searched.
- If the file is not found, directories in the user defined search path will be searched.
A user can access a file by specifying the files absolute path name or relative path
name
- Absolute path name: begin at the root

E.g., /spell/mail/ptr/last

- Relative path name: a path from the current directory

E.g., current working directory = /spell/mail


relative path name = ptr/last

Page- 42 -

How to delete a non-empty directory?


-Approach 1: Will not delete a directory unless it is empty (MS DOS)
- Provide the option to delete all the files and subdirectories
(UNIX rm command with r option)
Acyclic-Graph Directories
Allow directories to have shared subdirectories and files
- A shared subdirectory or file exists in two or more directories
Only one actual file exists for a shared file, changes made by one user are visible to
others.
How to implement shared files and subdirectories?
- Create a new directory entry called a link a pointer to another file or subdirectory
A link may be implemented as an absolute or relative path name.
Traversing the file system: dont want to traverse shared structures more than once
- Solution: ignore links when traversing
Deletion: deleting a file entry leaves the links dangling
- Solution1: Leave the links until an attempt is made to use them, get illegal file name
error (UNIX, Windows)
-Solution2: Preserve the file until all references to it are deleted
Need keep a count of the number of references to the file.

Page- 43 -

General Graph Directory


Problems with cycles:
Traversing might encounter infinite loop
- Solution: mark every directory that has been visited during the traverse, do not visit a
marked directory again
No longer simple to delete a file: reference count may be non-zero even when its no
longer possible to refer to a file or directory
- Solution: garbage collection - traversing the entire file system and mark everything that can
be accessed, then delete everything not marked.

Q.1. Solve the following crossword puzzle using the given hints:

Hints:
Top-Down:
1. -------- contains information about the file.
2. A sequence of logical records.
Sideway:
1. A graph representing a directory scheme with no cycle.
2. A table used as a linked list and has one entry for each disk block.
Q.2.In which of the following directory systems, is it possible to have multiple complete
paths for a file, starting from the root directory
a) Single level directory
b) Two level directory
c) Tree structured directory
d) Acyclic graph directory

Page- 44 -

Q.3.Which types of organization are supported by magnetic tape?


a) random files
b) contiguous sequential file
c) indexed sequential file
d) all of these
Q.4. File records length
a) should always be fixed
b) should always be variable
c) depends upon the size of the file
d) should be chosen to match the data character
Q.5.Disadvantage of single level directory is
a) the confusion of files names between different users
b) the confusion of files data
c) both (a) and (b) above
d) none of the above
Q.6.Which structure prohibits the sharing of files and directories
a) tree structure
b) one level directory
c) two level structure
d) none of these
Answers:
2.(d)
3. (b)
4. (c)
5. (a)
6. (a)

Page- 45 Disk Management


Terminologies
Sector
Track
Cylinder
Allocation unit
Capacity
Density
Read write head
Read write head
Assembly
Platter
Spindle rod
Transfer time
Seek time
Latency time

Disk sections
Partition table
Boot sector with
Boot signature (55AAH)
FAT # 1
FAT # 2
Root sector
Cluster

Disk Partition
Logical partition
(Using S/W e.g. Fdisk)
Physical partition
(Multiple HDD)
Bad block Management
Interleave factor
The main difference between FD and HD is that in FD the data will be stored in the form of
magnetic particles And in HD it will be in the form of magnetic bubbles.
Two types of HDD s are possible.
IDE (Integrated Device Electronics)
SCSI (Small Computer System Interface).
In IDE, bad blocks are marked as occupied by S/Ws. But in SCSI, bad blocks are replaced by
good blocks taken from reserve pool of good blocks.

Page- 46 The portion of the track enclosed with in a sector is called Allocation unit. The partial
allocation of allocation unit Is not possible. In FD and HD the size of allocation Units are
512 bytes and 2048 bytes respectively.

Page- 47 -

INPUT/OUTPUT DEVICES:
BLOCK DEVICES: It stores information in fixed size blocks (128 bytes to 1024

bytes) and they can be read/written independently. It may suffer from seek/latency
time
(e.g.
disks)
CHARACTER DEVICES: It delivers/accepts a stream of characters without any

block structures. There is no seek time here. (e.g. mouse, printer, terminals, network
interface).
Device Controllers
I/O units typically consist of a mechanical component and an electronic component called
device controller or adapter. A controller can handle 2,4 or 8 identical devices. The O.S. deals
with device controllers with standard interfaces (ANSI, IEEE, ISO, or defacto one) but not
with devices directly.

A model for connecting the CPU, memory, controllers and I/O devices
Each controller has a few registers that are used for communicating with the CPU. On some
computers, these registers are the part of the regular memory address space. This scheme is
called Memory-mapped I/O.
In I/O - mapped I/O performs I/O by writing commands (e.g. READ, WRITE, SEEK,
FORMAT etc.) with parameters. After acceptance of the command the controller goes alone
and completes the job. After completion, I/O generates interrupt to inform O.S. to regain its
control. CPU gets required data and information from pre specified register from the
controller.

Page- 48 Direct Memory Access (DMA):


DMA was invented to free the CPU from I/O bound low-level work. Thus it resists wastage
of CPU time. CPU provides DMA controller with certain information: number of blocks to
move, destination memory address and source block address and direction of the flow of
information e.g. R/W operation.

A DMA transfer is done entirely by the controller. The DMA controller stores the read
block into its buffer and verifies the checksum and copies it to the specified memory address.
Then it increments and decrements the DMA address and DMA count respectively. The
process is repeated until the count exhausts. After completion DMA informs O.S. through
interrupt and O.S. takes action accordingly. DMA improves I/O performance. To synchronize
with CPU, DMA uses two signals HOLD and HLDA (HOLD ACK) DMA operation can be
continued due to the presence of buffer in the controller circuit.
Spooling (Simultaneous Peripheral Operation Online):
It is a way of dealing with dedicated I/O devices in a multiprogramming system. It creates a
special process, called a daemon, and a special directory, called a spooling directory.
Spooling is not only for printers but also for network file transfer by network daemon. Emails are also stored in spool directory first and then transmitted later.
Principles of I/O Software:
The primary goal is device independence. So that a program can access any file from any
HDD or FDD independently.
Uniform naming is the name of a file or a device should simply be a string or an integer and
not depend on the device in any way. Any FDD or HDD or CDROM can be mounted to a file
system to access files from it uniformly.
Error handling techniques may be handled as close to the hardware as possible. Read errors
caused by dusts on the read/write head will go away if the operation is repeated.
Synchronous (blocking) and asynchronous (interrupt driven) transfers are possible. In
asynchronous CPU transfers data until the interrupt arrives. In synchronous-after a READ
command the program suspends until the buffer is empty.
I/O devices may be sharable (e.g. disks, may be accessed from different terminals) or
dedicated (e.g. printer, can be accessed by a single user at a time).

Page- 49 I/O S/W operates in four layers:


Interrupt Handlers: When an interrupt occurs then a process can block itself by
DOWN on a semaphore, a WAIT on a condition variable, or a RECEIVE on a message.
Device Drivers: It is the only part of O.S. that knows the no. of registers in controllers
and other disk details.
Device-independent I/O S/W: It performs the I/O functions that are common to all
devices, and to provide a uniform interface to the user level S/W. I-node contains the major
and minor device numbers.
User space I/O S/W: user program may use different functions calls to interact with
I/O devices e.g. count = write (fd, buffer, nbytes); spooling is another solution.

Disk error handling


Disks are subject to a wide variety of errors
1. Programming error (e.g. request for nonexistent sector)
2. Transient checksum error (e.g. caused by dust on the head)
3. Permanent checksum error (e.g. disk block physically damaged)
4. Seek error (e.g. the arm sent to cylinder 6but it went to 7)
5. Controller error (e.g. controller refuses to accept commands).
Track-at-a-time caching
This property maintains a secret track at-a-time cache, unknown to the deviceindependent software. If a sector that is in the cache in needed, no disk transfer is required.

Page- 50 The main disadvantages are software complexity and buffer requirement and it is useless if
CPU asks DMA to do the job.
RAM DISKS
A Ram disk uses a pre allocated portion of the main memory for storing the blocks. It has
no seek or rotational delay suitable for frequently accessible data and programs. It is volatile
in nature and not permanent.

Clocks
It is essential to the operation of any time-sharing system.
Clock Hardware
It has three H/W components: a crystal oscillator mounted under tension, a down counter and
a holding register holding the initial count. When the counter gets to zero, it causes a CPU
interrupt. O.S. then deals with the situation. Clock has two modes of operations. In one shot
mode the CKT produces an interrupt after counter counts to zero from the initial given count.
In square- wave mode, after getting to zero and causing the interrupt, the holding register is
automatically copied into the counter, and the whole process is repeated indefinitely
producing clock ticks.
Clock Software
Clock S/W or driver performs following duties:
1. Maintaining the time of day
2. Preventing processes from running longer than they are allowed to
3. Accounting for CPU usage
4. Handling the ALARM system call made by user processes
5. Proving watch dog timers for parts of the system itself
6. Doing profiling, monitoring and statistics gathering.

Page- 51 -

Let us consider an example that signals are pending for 4203,4207,4213,4215 and
4216. Then it can be implemented as.

Terminals

Terminal Types
Terminal Hardware

Page- 52 Since computers and terminals work with characters but they can communicate
transmitting one bit at a time. So UART is used for character to serial and serial to character
conversions. UARTS are attached to the computer by plugging RS-232 interface cards into
the bus.

Memory mapped terminals


Memory mapped terminal are
interfaced via a special memory
called video RAM, which forms
part of the computers address
space and is addressed by CPU
the same way as the rest of
memory. Video controller gets
bytes from buffer and converse
it analog signal for monitor to
display.

Input Software
It operates in two different modes (1) raw mode (character oriented) (2) cooked mode (line
oriented). In first mode the characters are processed as when obtained from keyboard after
keeping them in memory buffer. In cooked mode, characters must be stored until an entire
line has been accumulated, because the user may decide subsequently to erase part of it.
Buffering is common here in cooked mode different characters are available e.g. kill, erase,
filler characters etc.

Page- 53 Output Software


It has got many different duties:
1. Move cursor up, down, left, or right one position.
2. Move cursor to (x, y) co-ordinate.
3. Insert character or line at cursor.
4. Delete character or line at cursor.
5. Scroll screen up or down n lines.
6. Clear screen from cursor to end of line or end of screen.
7. Enter reverse video, underlining, blinking, or normal mode.
8. Create, destroy, move, or otherwise manage windows.
Q.1. Solve the following crossword puzzle using the given hints:

Hints:
Top-Down:
1. It is a way of dealing with dedicated I/O devices in a multiprogramming system.
2. ---- was invented to free the CPU from I/O bound low-level work.
Sideway:
1. It is essential to the operation of any time-sharing system.
2. DMA controller initiates this signal to interrupt the CPU.

Page- 54 Q.2.Terminals can accommodate


a) inputs only
b) outputs only
c) both input and output
d) turnaround document only
Q.3. Which of the following statements is incorrect for a micro-processor system using I/O
mapped I/O ?
a) I/O address space are better
b) I/O and memory spaces are distinct
c) Memory space available are greater
d) Not all data transfer instruction are available
Q.4. State three advantages of placing functionality in a device controller, rather than in the
kernel. State three disadvantages.
Q.5. How does DMA increase system concurrency? How does it complicate hardware
design?
Answers:
2. b)
3. a)
4. Three advantages:
Bugs are less likely to cause an operating system crash.
Performance can be improved by utilizing dedicated hardware and hard-coded
algorithms.
The kernel is simplied by moving algorithms out of it.
Three disadvantages:
Bugs are harder to xa new rmware version or new hardware is needed.
Improving algorithms likewise require a hardware update rather than just a kernel or
device-driver update.
Embedded algorithms could conict with applications use of the device, causing
decreased performance.
5. DMA increases system concurrency by allowing the CPU to perform tasks while the DMA
system transfers data via the system and memory buses. Hardware design is complicated
because the DMA controller must be integrated into the system, and the system must allow
the DMA controller to be a bus master. Cycle stealing may also be necessary to allow the
CPU and DMA controller to share use of the memory bus.

Page- 55 Architecture of UNIX system

Page- 56 -

UNIX SYSTEM STRUCTURE


GENERAL OVERVIEW
Several reasons are sited for the popularity of UNIX system
The system is written in a high level language, making it easy to read, understand, change
and move to other machines. It was estimated that the first system in C was 20 to 40 % larger
and slower because it was not written in assembly language, but the advantages of using a
high level language have overcome the disadvantages.
It has a simple user interface that has the power to provide the services that users want.
It provides primitives that permit complex programs to be built from simpler programs.
It uses a hierarchical file system that allows easy maintenance and efficient
implementation.
It uses a consistent format for files, the byte stream, making application programs easier
to write.
It provides simple, consistent interface to peripheral devices.
It is a multi-user, multiprocessor system; each user can execute several processes
simultaneously.
It hides the machine architecture from the user, making it easier to write programs that run
on different hardware implementations.
System Structure
The high level layered architecture of UNIX is shown in figure. The hardware at the
center of diagram provides the operating system with the basic services. The operating
system interacts directly with the hardware, providing common services to the programs and
insulating them from hardware details. Viewing the system as a set of layers, the operating
system is commonly called the system kernel, or just the kernel, emphasizing its isolation
from user programs. Because programs are independent of the underlying hardware it is easy
to move them between UNIX systems running on different hardware if the programs do not
make any assumptions about the underlying hardware. For instance, programs that assume
the size of a machine word are more difficult to move to other machines than programs that
do not make this assumption.
Programs such as shell and editors ( ed and vi ) shown in the outer layers interact with the
kernel by invoking a well defined set of system calls. The system calls instruct the kernel to
do various operations for the calling program and exchange data between the kernel and the
program. Several programs are is standard system configuration and are known as
commands, but private user programs may also exist in this layer like the program a.out, the
standard name for executable files produced by the C compiler.

Page- 57 For example, the standard C compiler, cc, is in the outer most layer : it invokes a C
preprocessor, two-pass compiler, assembler, and loader ( link-editor ), all separate lower level
programs. Although a two-level hierarchy of application programs is seen, users can extend
the hierarchy to whatever levels are required.

High-level features of UNIX


The File System
The UNIX file system is characterized by :
A hierarchical structure
Consistent treatment of file data
The ability to create and delete files
Dynamic growth of files
The protection of file data
The treatment of peripheral devices (such as terminals and tape units ) as files.
The file system is organized as a tree with a single root node called root (written / ); every
non leaf node of the file system structure is a directory of files, and files at the leaf nodes of
the tree are either directories, regular files, or special device files. The name of a file is given
by a path name that describes how to locate the file in the file system hierarchy. A path name
is a sequence of component names separated by slash characters.
Processing Environment
A program is an executable file, and a process is an instance of the program in execution.
Many processes can execute simultaneously on UNIX systems (this feature is some times
called multiprogramming or multitasking) with no logical limit to their number, and many
instances of a program (such as copy) can exist simultaneously in the system.
Building Block Primitives
The UNIX system provides operating system primitives that enable users to write small,
modular programs that can be used as building blocks to build more complex programs. One
such primitive visible to shell users is the capability to redirect I/O. Processes conventionally
have access to three files: they read from their standard input files, write to their standard
output files, and write error messages to their standard error files. Processes executing at a
terminal typically use the terminal for these three files, but each may be redirected
independently. For instance, the command line
Ls
Lists all files in the current directory on the standard output, but the command line
ls > output
Redirects the standard output to the file called output in the current directory, using the
creat system call.

Page- 58 -

The Inode
An Inode contains the owners user identification and owners group identification,
protection bits physical disk addresses for the contents of the file, file size, time of creation,
time of last use, time of last modification to the file, time of last modification to the mode,
the number of links to the file, and an indication of whether the file i s a directory, an ordinary
the, a character special file (which represents a character. oriented device), or a pipe.
File blocks on disk can be contiguous, but it is more likely that they will be dispersed. The
inode contains the information needed to locate a block in a file, The inode data structure
tends to provide fast access tor small files; larger files, by far in the minority on typical
UNIX systems, can require longer access times.
The inode contains the information needed to locate all of a files physical blocks, The
information points directly to the first blocks of a file, and then uses various levels of
indirection to point to the remaining blocks.
The block locator information in the mode consists of 13 fields. Fields 0 through 9 are direct
block addresses; they point successively to the first 10 blocks of a file. Since the vast
majority of UNIX files are small these ten fields often suffice to locate all of a files
information directly.
Field l0 is an indirect block addresses; it points to a block containing the next group of block
addresses; this block can contain as many block addresses as will fit (bIocksize/
blockaddresssize) normally several hundred entries.
-

Field 11 contains a double-indirect block address, It points to a block containing indirect


block addresses; this block, in turn, points to blocks containing direct block addresses.
Field 12 contains a triple-indirect block address, This points to a block of double indirect
block addresses, Each entry in this block points to a block of indirect addresses, Each entry in
these blocks point to a block of direct addresses. Each entry in these blocks points to a block
of the file.

Page- 59 -

Page- 60 -

Bibliography:

OPERATING SYSTEM CONCEPT Silberschatz Galvin

OPERATING SYSTEM PRINCIPLES Hansen

Web references:
www.memorymanagement.org
www.webopedia.com/file_management_system.html
en.wikipedia.org/wiki/Unix_directory_structure

Vous aimerez peut-être aussi