Download as pdf or txt
Download as pdf or txt
You are on page 1of 25

https://sites.google.

com/site/computing9691/

Chapter 3.1 The Functions of Operating Systems

3.1 (a) The Main Features of Operating Systems

The operating system (OS) must provide and manage hardware resources as well as
provide an interface between the user and the machine and between applications
software and the machine. The OS must also provide other services such as data
security.

Originally, if a program needed input, the program would have to contain the code to
do this, similarly if output were required. This led to duplication of code so the idea
of an OS was born. The OS contained the necessary input and output functions that
could be called by an application. Similarly, disk input and output routines were
incorporated into the OS. This led to the creation of subroutines to do these simple
tasks, such as read a character from a keyboard or send a character to a printer. The
joining together of all these basic input and output routines led to the input-output
control system (IOCS). Originally, the IOCS could only read a punched card or send
data to a card punch. However, as new input and output media, such as magnetic tape
and disk, were developed the IOCS became more complex.

Another complication was added when assembly and high-level languages were
developed as the machine did not use these languages. Machines use binary codes for
very simple instructions. With the development of these new types of programming
language a computer would have to

 load an assembler, compiler or interpreter,


 load the assembly or high-level program,
 do the translation,
 store the results somewhere in memory,
 execute the program,
 read input data,
 output the results.

The system had now become too complex for the human user to be able to organise it
all. Also, as the processor could work much faster than the manual operator and the
input and output devices, much time was wasted.

Further, to make full use of the processor, more than one program should be stored in
memory and the processor should give time to each of the programs. Suppose two
programs are stored in memory and, if one is using an input or output device (both
very slow compared to the processor), it makes sense for the other program to use the
processor. In fact this can be extended to more than two programs as shown in Fig.
3.1.a.1.

The OS must now manage the memory so that all three programs shown in Fig.
3.1.a.1 are kept separate as well as any data that they use. It must also schedule the
jobs into a sequence that makes best use of the processor.

Page 1 of 25
https://sites.google.com/site/computing9691/
https://sites.google.com/site/computing9691/

Using I/O Using


Program A processor required processor

Using I/O Using


Program B processor required processor

Using I/O
Program C processor required

Processor Processor in use Processor in use

Processor idle

Fig. 3.1.a.1

The I/O phase should not hold up the processor too much which can easily happen if
the I/O devices are very slow, like a keyboard or printer. This can be overcome by
using Simultaneous Peripheral Operations On-Line (spooling). The idea is to store all
input and output on a high-speed device such as a disk. Fig. 3.1.a.2 shows how this
may be achieved,

Input Output
device Input Output device
spool spool

Application
Read program Write
process process

Fig. 3.1.a.2

Another problem is that programs may not be loaded into the same memory locations
each time they are loaded. For example, suppose that three programs are loaded in
the order A, B, C on one occasion and in the order C, A, B on another occasion. The
results are shown in Fig. 3.1.a.3.

Page 2 of 25
https://sites.google.com/site/computing9691/
https://sites.google.com/site/computing9691/

OS OS

Program A
Program C

Program B

Program A
Program C

Program B

Free Free

Fig. 3.1.a.3

A further problem occurs if two or more users wish to use the same program at the
same time. For example, suppose user X and user Y both wish to use a compiler for
C++ at the same time. Clearly it is a waste of memory if two copies of the compiler
have to be loaded into main memory at the same time. It would make much more
sense if user X's program and user Y's program are stored in main memory together
with a single copy of the compiler as shown in Fig. 3.1.a.4.

OS
User X's
program and data

User Y's
Program
and data

Compiler

Free

Fig. 3.1.a.4

Now the two users can use the compiler in turns and will want to use different parts of
the compiler. Also note that there are two different sets of data for the compiler, user
X's program and user Y's program. These two sets of data and the outputs from the
Page 3 of 25
https://sites.google.com/site/computing9691/
https://sites.google.com/site/computing9691/

compiler for the two programs must be kept separate. Programs such as this compiler,
working in the way described, are called re-entrant.

Memory management, scheduling and spooling are described in more detail in the
following Sections.

Distributed systems have operating systems that arrange for the sharing of the
resources of the system by the users of that system. No action is required from the
user. An example would be when a user asks for a particular resource in a network
system, the resource would be allocated by the O.S. in a way that is transparent to the
user.

Page 4 of 25
https://sites.google.com/site/computing9691/
https://sites.google.com/site/computing9691/

3.1 (b) Interrupts

The simplest way of obeying instructions is shown in Fig. 3.1.b.1.

Start

Fetch instruction

Execute instruction

Any more instructions?


Yes
No

End

Fig. 3.1.b.1

This is satisfactory so long as nothing goes wrong. Unfortunately things do go wrong


and sometimes the normal order of operation needs to be changed. For example, a
user has used up all the time allocated to his use of the processor. This change in
order is instigated by messages to the processor, called interrupts. There are a number
of different types of interrupt. The nature of each of these types of interrupt is

 I/O interrupt
o Generated by an I/O device to signal that a job is complete or an error
has occurred. E.g. printer is out of paper or is not connected.
 Timer interrupt
o Generated by an internal clock indicating that the processor must
attend to time critical activities (see scheduling later).
 Hardware error
o For example, power failure which indicates that the OS must close
down as safely as possible.
 Program interrupt
o Generated due to an error in a program such as violation of memory
use (trying to use part of the memory reserved by the OS for other use)
or an attempt to execute an invalid instruction (such as division by
zero).

Page 5 of 25
https://sites.google.com/site/computing9691/
https://sites.google.com/site/computing9691/

If the OS is to manage interrupts, the sequence in Fig. 3.1.b.1 needs to be modified as


shown in Fig. 3.1.b.2.

Start

Fetch instruction

Execute instruction

Is there an interrupt?
No
Yes

Service the interrupt

Any more instructions?


Yes
No

End

Fig. 3.1.b.2

This diagram shows that, after the execution of an instruction, the OS must see if an
interrupt has occurred. If one has occurred, the OS must service the interrupt if it is
more important than the task already being carried out (see priorities later). This
involves obeying a new set of instructions. The real problem is 'how can the OS
arrange for the interrupted program to resume from exactly where it left off?' In order
to do this the contents of all the registers in the processor must be saved so that the OS
can use them to service the interrupt. Chapter 3.3 explains registers that have to have
their contents stored as well as explaining the processing cycle in more detail.

Another problem the OS has to deal with happens if an interrupt occurs while another
interrupt is being serviced. There are several ways of dealing with this but the
simplest is to place the interrupts in a queue and only allow return to the originally
interrupted program when the queue is empty. Alternative systems are explained in
Section 3.1.c. Taking the simplest case, the order of processing is shown in
Fig.3.1.b.3.

Page 6 of 25
https://sites.google.com/site/computing9691/
https://sites.google.com/site/computing9691/

Start

Fetch instruction

Yes
Execute instruction

Any more instructions?

Is there an interrupt
No in the interrupt queue?
No Yes

Service the next interrupt


End in the interrupt queue

Fig. 3.1.b.3

The queue of interrupts is the normal first in first out (FIFO) queue and holds
indicators to the next interrupt that needs to be serviced.

Page 7 of 25
https://sites.google.com/site/computing9691/
https://sites.google.com/site/computing9691/

3.1 (c) Scheduling

The earliest operating systems were used to control single-user computer systems. In
those days, the operating system would read in one job, find the data and devices the
job needed, let the job run to completion, and then read in another job. In contrast, the
computer systems that modern OS manages are capable of multiprogramming, or
executing many programs concurrently. With multiprogramming, when a job cannot
use the processor, the system can suspend, or interrupt, the job, freeing the processor
to work on another job.

OS makes multiprogramming possible by capturing and saving all the relevant


information about the interrupted program before allowing another program to
execute. When the interrupted program is ready to begin executing again, it can
resume execution just where it left off. Multiprogramming allows OS to run
thousands of programs simultaneously for users who might be working on different
projects at different physical locations around the world.

So, one of the tasks of the OS is to arrange the jobs that need to be done into an
appropriate order. The order may be chosen to ensure that maximum use is made of
the processor; another order may make one job more important than another. In the
latter case the OS makes use of priorities.

Suppose the processor is required by program A, which is printing wage slips for the
employees of a large company, and by program B, which is analysing the annual,
world-wide sales of the company which has a turnover of many millions of pounds.

Program A makes little use of the processor and is said to be I/O bound. Program B
makes a great deal of use of the processor and is said to be processor bound.

If program B has priority over program A for use of the processor, it could be a long
time before program A can print any wage slips. This is shown in Fig. 3.1.c.1.

B using processor I/O B using processor

A waiting for processor I/O A waiting for processor

A using processor

Fig. 3.1.c.1

Page 8 of 25
https://sites.google.com/site/computing9691/
https://sites.google.com/site/computing9691/

Fig. 3.1.c.2 shows what happens if A is given priority over B for use of the processor.
This shows that the I/O bound program can still run in a reasonable time and much
better throughput is achieved.

B using B using B using I/O B using I/O


processor processor processor processor

I/O I/O I/O I/O

A using processor A using processor A using processor A using processor

Fig. 3.1.c.2
The objectives of scheduling are to

 maximise the use of the whole of the computer system;


 be fair to all users;
 provide a reasonable response time to all users, whether they are on-line users
or a batch processing user;
 prevent the system failing if it is becoming overloaded;
 make sure that the system is consistent by always giving similar response
times to similar activities from day to day.

To achieve these objectives some criteria are needed in order to determine the order in
which jobs are executed. The following is a list of criteria which may be used to
determine a schedule which will achieve the above objectives.

 Priority. Give some jobs a greater priority than others when deciding which
job should be given access to the processor.
 I/O or processor bound. If a processor bound job is given the main access to
the processor it could prevent the I/O devices being serviced efficiently.
 Type of job. Batch processing, on-line and real-time jobs all require different
response times.
 Resource requirements. The amount of time needed to complete the job, the
memory required, I/O and processor time.
 Resources used so far. The amount of processor time used so far, how much
I/O used so far.
 Waiting time. The time the job has been waiting to use the system.

In order to understand how scheduling is accomplished it is important to realise that


any job may be in one, and only one, of three states. A job may be ready to start,
running on the system or blocked because it is waiting for a peripheral, for example.
Fig. 3.1.c.3 shows how jobs may be moved from one state to another. Note that a job
can only enter the running state from the ready state. The ready and blocked states
Page 9 of 25
https://sites.google.com/site/computing9691/
https://sites.google.com/site/computing9691/

are queues that may hold several jobs. On a standard single processor computer only
one job can be in the running state. Also, all jobs entering the system normally enter
via the ready state and (normally) only leave the system from the running state.

Enter the
system READY BLOCKED

RUNNING

Leave the
system
Fig. 3.1.c.3
When entering the system a job is placed in the ready queue by a part of the OS called
the High Level Scheduler (HLS). The HLS makes sure that the system is not over
loaded.

Sometimes it is necessary to swap jobs between the main memory and backing store
(see Memory Management in Section 3.1.d. This is done by the Medium Level
Scheduler (MLS).

Moving jobs in and out of the ready state is done by the Low Level Scheduler (LLS).
The LLS decides the order in which jobs are to be placed in the running state. There
are many policies that may be used to do scheduling, but they can all be placed in one
of two classes. These are pre-emptive and non-pre-emptive policies.

A pre-emptive scheme allows the LLS to remove a job from the running state so that
another job can be placed in the running state. In a non-pre-emptive scheme each job
runs until it no longer requires the processor. This may be because it has finished or
because it needs an I/O device.

Some common scheduling policies are

 First Come First Served (FCFS)


 Shortest Job First (SJF)
 Round Robin (RR)
 Shortest Remaining Time (SRT)
 Multi-level Feedback Queues (MFQ)

and there are many more.

Page 10 of 25
https://sites.google.com/site/computing9691/
https://sites.google.com/site/computing9691/

 FCFS
o simply means that the first job to enter the ready queue is the first to
enter the running state. This favours long jobs.

 SJF
o simply means sort jobs in the ready queue in ascending order of time
expected to be needed by each job. New jobs are added to the queue in
such a way as to preserve this order.
 RR
o this gives each job a maximum length of processor time (called a time
slice) after which the job is put at the back of the ready queue and the
job at the front of the queue is given use of the processor. If a job is
completed before the maximum time is up it leaves the system.
 SRT
o the ready queue is sorted on the amount of expected time still required
by a job. This scheme favours short jobs even more than SJF. Also
there is a danger of long jobs being prevented from running.
 MFQ
o involves several queues of different priorities with jobs migrating
downwards.

For SJF the short jobs are processed first depending on the time required. They will be
sorted in this order once. While SRT will mean that once an interrupt is raised the
queue will be reshuffled again with the shortest job first. In this way SRT favours
short jobs more than SJF.

There are other ways of allocating priorities. Safety critical jobs will be given very
high priority, on-line and real time applications will also have to have high priorities.
For example, a computer monitoring the temperature and pressure in a chemical
process whilst analysing results of readings taken over a period of time must give the
high priority to the control program. If the temperature or pressure goes out of a pre-
defined range, the control program must take over immediately. Similarly, if a bank's
computer is printing bank statements over night and someone wishes to use a cash
point, the cash point job must take priority. This scheme is shown in Fig. 3.1.c.4; this
shows that queues are needed for jobs with the same priority.

Priority 1 (high) Queue


P
r
o
Priority 2 Queue c
e
Priority 3 Queue s
s
o
r
Priority 4 (low) Queue

Fig. 3.1.c.4

Page 11 of 25
https://sites.google.com/site/computing9691/
https://sites.google.com/site/computing9691/

In this scheme, any job can only be given use of the processor if all the jobs at higher
levels have been completed. Also, if a job enters a queue that has a higher priority
than the queue from which the running program has come, the running program is
placed back in the queue from which it came and the job that has entered the higher
priority queue is placed in the running state.

Multi-level feedback queues work in a similar way except that each job is given a
maximum length of processor time. When this time is up, and the job is not
completely finished, the job is placed in the queue which has the next lower priority
level. At the lowest level, instead of a first in first out queue a round robin system is
used. This is shown in Fig. 3.1.c.5.

Priority 1 (high) Queue


P
r
Time up
o
Priority 2 Queue c
e
Priority 3 Queue s
s
o
r
Priority 4 (low) RR Queue

Fig. 3.1.c.5

Glossary of Terms

Active Set: The jobs being processed by a system at a given time.


Control Unit: The device that allows jobs to enter the system from the memory queue.
CPU Utilization: The percentage of time the CPU is busy and not waiting for
peripheral devices to complete processing a job.
Degree of Multiprogramming/ Multiprogramming Level (MPL)/ Load: The number
of active processes in a system.
Memory Queue: Jobs are held in the memory queue until resources in the system are
free to serve the job.
Response Time: The amount of time a job is at a server, including the service time.
Server: Also referred to as a device. A component of a system that serves a job.
Service Time: The amount of time a server takes to complete work on a task.
Throughput: The number of jobs completed by the system or by a server per unit time.
Visit Ratio: The number of times a job is serviced by a server before exiting the
system.

Page 12 of 25
https://sites.google.com/site/computing9691/
https://sites.google.com/site/computing9691/

3.1 (d) Memory Management

This section can become very complex. In an examination the questions will be
limited to basic definitions and explanations. Calculations of the addresses and other
detail will not be required; they are included here for completeness of the topic for
those students who wish to understand in more detail.

In order for a job to be able to use the processor the job must be stored in the
computer's main memory. If there are several jobs to be stored, they, and their data,
must be protected from the actions of other jobs.

Suppose jobs A, B, C and D require 50k, 20k, 10k and 30k of memory respectively
and the computer has a total of 130k available for jobs. (Remember the OS will
require some memory.) Fig. 3.1.d.1 shows one possible arrangement of the jobs.

Free 20k

Job D 30k

Job C 10k
130k available
Job B 20k
for jobs

Job A 50k

OS

Fig 3.1.d.1

Now suppose job C terminates and job E, requiring 25k of memory, is next in the
ready queue. Clearly job E cannot be loaded into the space that job C has
relinquished. However, there is 20k + 10 k = 30k of memory free in total. So the OS
must find some way of using it. One solution to the problem would be to move job D
up to job B. This would make heavy use of the processor as not only must all the
instructions be moved but all addresses used in the instructions would have to be
recalculated because all the addresses will have changed.
Page 13 of 25
https://sites.google.com/site/computing9691/
https://sites.google.com/site/computing9691/

When jobs are loaded into memory, they may not always occupy the same locations.
Supposing, instead of jobs A, B, C and D being needed and loaded in that order, it is
required to load jobs A, B, D and E in that order. Now job D occupies different
locations in memory to those shown above. So again there is a problem of using
different addresses.

The OS has the task of both loading the jobs and adjusting the addresses. The part of
the OS which carries out these tasks is a program called the loader. The calculation of
addresses can be done by recalculating each address used in the instructions once the
address of the first instruction is known. Alternatively, relative addressing can be
used. That is, addresses are specified relative to the first instruction.

Another problem to be solved is when to move jobs. Possible solutions are

 whenever a job terminates;


 when a new job is too large for any existing space;
 at regular intervals;
 when the user decides.

This system is known as variable partitioning with compaction. Imagine that each job
needs a space to fit into, this space is the partition. Each of the jobs requires a
different size of space, hence “variable partitions”. These variable partitions are
normally called segments and the method of dividing memory up is called
segmentation. We also saw that sometimes it is necessary to move jobs around so that
they fill the ‘holes’ left by jobs that leave, this is called “compaction”.

An alternative method is to divide both the memory and the jobs into fixed size units
called “pages”. As an example, suppose jobs A, B, C, D and E consist of 6, 4, 1, 3
and 2 pages respectively. Also suppose that the available memory for jobs consists of
12 pages and jobs A, B and C have been loaded into memory as shown in Fig. 3.1.d.2.

Job A Job B Job C Memory


Page 6 Page 4 Page 1 Free
Page 5 Page 3 C1
Page 4 Page 2 B4
Page 3 Page 1 B3
Page 2 B2
Page 1 B1
A6
A5
A4
A3
A2
A1

Fig. 3.1.d.2

Page 14 of 25
https://sites.google.com/site/computing9691/
https://sites.google.com/site/computing9691/

Now suppose job B terminates, releasing four pages, and jobs D and E are ready to be
loaded. Clearly we have a similar problem to that caused by segmentation. The 'hole'
consists of four pages into which job D (three pages) will fit, leaving one page plus
the original one page of free memory. E consists of two pages, so there is enough
memory for E but the pages are not contiguous, in other words they are not joined
together and we have the situation shown in Fig. 3.1.d.3.

Job E Memory
Page 2 Free
Page 1 C1
Free
D3
D2
D1
A6
A5
A4
A3
A2
A1

Fig. 3.1.d.3

The big difference between partitioning and paging is that jobs do not have to occupy
contiguous pages. Thus the solution is shown in Fig. 3.1.d.4.

Memory
E2
C1 E split
E1
D3
D2
D1
A6
A5
A4
A3
A2
A1

Fig. 3.1.d.4

The problem with paging is again address allocation. This can be overcome by
keeping a table that shows which memory pages are used for the job pages. Then, if
each address used in a job consists of a page number and the distance the required
location is from the start of the page, a suitable conversion is possible.

Page 15 of 25
https://sites.google.com/site/computing9691/
https://sites.google.com/site/computing9691/

Suppose, in job A, an instruction refers to a location that is on page 5 and is 46


locations from the start of page 5. This may be represented by

5 46

Now suppose we have the following table

Job Page Memory Page


A1 4
A2 5
A3 6
A4 7
A5 8
A6 9

We see that page A5 is stored in page 8 of memory, thus

5 46 Becomes 8 46

Paging uses fixed length blocks of memory. An alternative is to use variable length
blocks. This method is called segmentation. In segmentation, programmers divide
jobs into segments, possibly of different sizes. Usually, the segments would consist
of data, or sub-routines or groups of related sub-routines.

Since segments may be of different lengths, address calculation has to be carefully


checked. The segment table must not only contain the start position of each segment
but also the size of each segment. This is needed to ensure that an address does not
go out of range. Fig. 3.1.d.5 shows how two jobs may be stored in memory. In this
case the programmer split Job A into 4 segments and Job B into 3 segments. These
two jobs, when loaded into memory, took up the positions shown in the Figure.

Page 16 of 25
https://sites.google.com/site/computing9691/
https://sites.google.com/site/computing9691/

Job A Job B Memory


Segment A4 Free
Segment B3
A4
Segment A3
Segment B2
Segment A2 A3

Segment A1 Segment B1 B1

B3

A2

B2

A1

Fig. 3.1.d.5

Page 17 of 25
https://sites.google.com/site/computing9691/
https://sites.google.com/site/computing9691/

Now suppose that an instruction specifies an address as segment 3, displacement


(from start of segment) 132. The OS will look up, in the process segment table, the
basic address (in memory) of segment 3. The OS checks that the displacement is not
greater than the segment size. If it is, an error is reported. Otherwise the
displacement is added to the base address to produce the actual address in memory to
be used. The algorithm for this process is

1. Get segment number.


2. Get displacement.
3. Use segment number to find length of segment from segment table.
4. If displacement is greater than segment size,
4.1 produce error message
4.2 stop.
5. Use segment number to find base address of segment from segment table.
6. Add displacement to base address to produce physical address.

This is also shown in Fig. 3.1.d.6.

Segment Number Displacement Physical Address


3 132 3632

+
Segment Table
Seg. No. Seg. Size Base Address
1
2
3 1500 3500
4

Fig. 3.1.d.6

Paging and segmentation lead to another important technique called virtual memory.
We have seen that jobs can be loaded into memory when they are needed using a
paging technique. When a program is running, only those pages that contain code that
is needed need be loaded. For example, suppose a word processor has been written
with page 1 containing the instructions to allow users to enter text and to alter the text.
Also suppose that page 2 contains the code for formatting characters, page 3 the code
for formatting paragraphs and page 4 contains the code for cutting, copying and
pasting. To run this word processor only page 1 needs to be loaded initially. If the
user then wants to format some characters so that they are in bold, then page 2 will
have to be loaded. Similarly, if the user wishes to copy and paste a piece of text, page
4 will have to be loaded. When other facilities are needed, the appropriate page can
be loaded. If the user now wishes to format some more characters, the OS does not
need to load page 2 again as it is already loaded.

Page 18 of 25
https://sites.google.com/site/computing9691/
https://sites.google.com/site/computing9691/

Now, what happens if there is insufficient space for the new page to be loaded? As
only the page containing active instructions need to be loaded, the new page can
overwrite a page that is not currently being used. For example, suppose the user
wishes to use paragraph formatting; then the OS can load page 3 into the memory
currently occupied by page 2. Clearly, this means that programs can be written and
used that are larger than the available memory.
There must be some system that decides which pages to overwrite. There are many
systems such as overwrite the page that has not been used for the longest period of
time, replace the page that has not recently been used or the first in first out method.
All of these create extra work for the OS.

To further complicate matters not every page can be overwritten. Some pages contain
a job's data that will change during the running of a program. To keep track of this
the OS keeps a flag for each page that can be initially set to zero. If the content of the
page changes, the flag can be set to 1. Now, before overwriting a page, the OS can
see if that page has been changed. If it has, then the OS will save the page before
loading a new page in its place. The OS now has to both load and save pages. If the
memory is very full, this loading and saving can use up a great deal of time and can
mean that most of the processor's time is involved in swapping pages. This situation
is called disk threshing.

Systems can use both multi-programming and virtual memory. Also, virtual memory
can use segmentation as well as paging although this can become very complex.

Page 19 of 25
https://sites.google.com/site/computing9691/
https://sites.google.com/site/computing9691/

3.1 (e) Spooling

Spooling was mentioned in Section 3.1.a and is used to place input and output on a
fast access device, such as disk, so that slow peripheral devices do not hold up the
processor. In a multi-programming, multi-access or network system, several jobs may
wish to use the peripheral devices at the same time. It is essential that the input and
output for different jobs do not become mixed up. This can be achieved by using
Simultaneous Peripheral Operations On-Line (spooling).

Suppose two jobs, in a network system, are producing output that is to go to a single
printer. The output is being produced in sections and must be kept separate for each
job. Opening two files on a disk, one for each job, can do this. Suppose we call these
files File1 and File2. As the files are on disk, job 1 can write to File1 whenever it
wishes and job 2 can write to File2. When the output from a job is finished, the name
(and other details) of the file can be placed in a queue. This means that the OS now
can send the output to the printer in the order in which the file details enter the queue.
As the name of a file does not enter the queue until all output from the job to the
corresponding file is complete, the output from different jobs is kept separate.

Spooling can be used for any number of jobs. It is important to realise that the output
itself is not placed in the queue. The queue simply contains the details of the files that
need to be printed so that the OS sends the contents of the files to the printer only
when the file is complete. The part of the OS that handles this task is called the
spooler or print spooler.

It should be noted that spooling not only keeps output from different jobs separate, it
also saves the user having to wait for the processor until the output is actually printed
by a printer (a relatively slow device). Spooling is used on personal computers as
well as large computer systems capable of multi-programming.

Page 20 of 25
https://sites.google.com/site/computing9691/
https://sites.google.com/site/computing9691/

3.1. (f) Desktop PC Operating Systems

There are basically two types of OS used on PC's. These are command driven and
those that use a graphical user interface (GUI) such as MS-DOS and Windows. These
differ in the way the user uses them and in the tasks that can be carried out.

All OS's for PC's allow the user to copy, delete and move files as well as letting the
user create a hierarchical structure for storing files. They also allow the user to check
the disk and tidy up the files on the disk.

However, Windows allows the user to use much more memory than MS-DOS and it
allows multi-tasking. This is when the user opens more than one program at a time
and can move from one to another. In fact the OS is swapping between the tasks so
fast that the user is not aware of the swapping. Try playing a CD while writing a
report! To do this, Windows uses the memory management techniques described in
Section 3.1.c. In order to multi-task, Windows gives each application a very short
period of time, called a time-slice. When a time-slice is up, an interrupt occurs and
Windows passes control to the next application.

The OS supplies the user, and applications programs, with facilities to handle input
and output, copy and move files, handle memory allocation and any other basic tasks.

In this Section you will see how an OS is loaded and how it controls the PC.

Whenever PC is turned ON, BIOS saved in ROM takes the control, and it performs
a lot of operations. It checks the hardware, ports etc and finally it loads the Master
Boot Record (MBR) program into RAM and transfers control to it. MBR is saved on
the first physical sector of the hard disk. MBR contains a small program known
as bootstrap loader (responsible for booting into any OS) and partition table.
Functions of MBR are as given below:-

 The boot process starts by executing code in the first sector of the disk, MBR.
 The MBR looks over the partition table to find the Active Partition (Hard disk’s
primary partition that holds the OS).
 Control is passed to that partition's boot record (PBR) to continue booting. This is
the logical first sector that is 512 bytes sector at the start of a Primary Partition,
which contains some programs to initialize or run OS files. The PBR locates the
system-specific boot files.
 Then these following boot files continue the process of loading and initializing the
rest of the OS.
o IO.SYS – A binary file that provides basic input/output interface between the
ROM BIOS and the Hardware
o MSDOS.SYS – A binary file considered to be the core of the DOS operating
system
o CONFIG.SYS – A text file used to load drivers and memory managers and
also use to configure the system to the user’s needs
o COMMAND.COM – DOS user interface loads the command prompt which
interprets DOS commands
Page 21 of 25
https://sites.google.com/site/computing9691/
https://sites.google.com/site/computing9691/

o AUTOEXEC.BAT – A text file that contains setting up display settings,


environment variables and routines

In the case of Windows, the operating system loads into different parts of memory.
The OS then guarantees the use of a block of memory to an application program and
protects this memory from being accessed by another application program.

If an application program needs to use a particular piece of hardware, Windows will


load the appropriate device driver.

Windows also uses virtual memory if an application has not been allocated sufficient
main memory.

If an application needs to use a hardware device, Windows checks to see if that device
is available. If it is, the application is given the use of that device. If not, the request
is placed in a queue. In the case of a slow peripheral such as a printer, Windows
saves the output to the hard disk first and then does the printing in the background so
that the user can continue to use the application. If further printing is needed before
other printing is completed, then spooling is used as described in Section 3.1.e.

Any OS has to be able to find files on a disk and to be able to store user's files. To do
this, the OS uses the File Allocation Table (FAT). This table uses a linked list to
point to the blocks on the disk that contain files. In order to do this the OS has a
routine that will format a disk. This simply means dividing the disk radially into
sectors and into concentric circles called tracks. Two or more sectors on a single
track make up a cluster. This is shown in Fig. 3.1.f.1.

Cluster Sectors
using 3
sectors

Tracks

Fig 3.1.f.1

Page 22 of 25
https://sites.google.com/site/computing9691/
https://sites.google.com/site/computing9691/

A typical FAT table is shown in Fig 3.1.f.2. The first column gives the cluster
number and the second column is a pointer to the next cluster used to store a file. The
last cluster used has a null pointer (usually FFFF) to indicate the end of the linking.
The directory entry for a file has a pointer to the first cluster in the FAT table. The
diagram shows details of two files stored on a disk.

Cluster Pointer
Pointer from 0 FFFD
directory entry for 1 FFFF
File 1 2 3
3 5
Pointer from 4 6
directory entry for 5 8
File 2 6 7
7 10
8 9
9 FFFF End of File 1 is in
10 11 cluster 9
11 FFFF
End of File 2 is in
cluster 11
Fig. 3.1.f.2

In order to find a file, the OS looks in the directory for the filename and, if it finds it,
the OS gets the cluster number for the start of the file. The OS can then follow the
pointers in the FAT to find the rest of the file.

In this table any unused clusters have a zero entry. Thus, when a file is deleted, the
clusters that were used to save the file can be set to zero. In order to store a new file,
all the OS has to do is to find the first cluster with a zero entry and to enter the cluster
number in the directory. Now the OS only has to linearly search for clusters with zero
entries to set up the linked list.

It may appear that using linear searches will take a long time. However, the FAT
table is normally loaded into RAM so that continual disk accesses can be avoided.
This will speed up the search of the FAT.

Note that Windows 95/98 uses virtual FAT (VFAT) which allows files to be saved 32
bits at a time (FAT uses 16 bits). It also allows file names of up to 255 characters.
Windows 98 uses FAT 32 which allows hard drives greater than 2 Gbytes to be
formatted.

Page 23 of 25
https://sites.google.com/site/computing9691/
https://sites.google.com/site/computing9691/

Glossary of Terms

FAT: File Allocation Table, a data structure present in all FAT volumes/HDD
partitions
FAT12/ FAT16/ FAT32: FAT file system using 12/16/32-bit cluster addressing
respectively
FAT or FATxx: File systems that use File Allocation Tables, etc.
VFAT: The 32-bit code used to operate the file system in Win9x GUI mode
Cluster: Single unit of data storage at the FATxx file system logic level
Sector: Single unit of storage at the physical disk level
Physical sector address: Sector address in absolute physical hardware terms
CHS sector address: As above, expressed in Cylinder, Head, Sector terms
Logical sector address: Sector address relative to the FATxx volume
Folder: A collection of named items as seen via Windows Explorer
File Folder: Modern Windows-speak for "directory"
Directory: A file system data structure that lists files and/or directories
Directory entry: Points to a file or directory, and contains info about it
Attributes: A collection of bits in a directory entry that describes it.

Page 24 of 25
https://sites.google.com/site/computing9691/
https://sites.google.com/site/computing9691/

3.1 Example Questions

1. Explain how an interrupt is handled by a processor which is working on


another task. (4)

2. State three different types of interrupt that may occur and say in what order the
three interrupts would be handled if they all arrived at the processor together,
giving a reason for your answer. (5)

3. Explain the difference between


(i) Input/output bound jobs and
(ii) Processor bound jobs.
Explain how the computer should prioritise the two types of job if it is going to
make maximum use of the system. (4)
4. Describe two types of scheduling that are used by computer processing
systems. (4)

5. Explain how interrupts are used in a round robin scheduling operating system.
(3)
6. a) Explain the difference between paging and segmenting when referring to
memory management techniques. (2)
b) Describe how virtual memory can allow a word processor and a spreadsheet to
run simultaneously in the memory of a computer even though both pieces of
software are too large to fit into the computer’s memory. (3)

7. Describe how a PC operating system uses a file allocation table to find files when
necessary.

8. What is the difference between multiprogramming and multitasking? (4)

Page 25 of 25
https://sites.google.com/site/computing9691/

You might also like