You are on page 1of 26

1) Suppose that the following processes arrive for execution at the times

indicated. Each process will run for the amount of time listed. Non-pre-emptive
scheduling is used, and all decisions are based on the information at the time
the decision must be made.

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?

c. Compute the average turnaround time if the CPU is left idle for the first 1 unit and
then SJF scheduling is used.

Solution:

1. Suppose the following three processes arrive for execution at the arrival times
indicated.

Process Arrival Time Burst Time

P1 0.0 8
P2 0.4 4
P3 1.0 1

a. What is the average wait time for these three processes using the
FCFS algorithm?
b. What is the average wait time, using the non-preemptive SJF
algorithm?
c. What is the average wait time, using Shortest Remaining Time First
(the preemptive version of SJF)?

Note! You cannot schedule a process to execute before it has arrived!

Answers:

Average wait times:

a. FCFS 6.2
b. SJF 5.2
c. SRTF 2.0

Calculation Details: Gantt charts

a) First Come First Serve


____________________________________
| P1 | P2 | P3 |
____________________________________
8 12 13

b) Shortest Job First


____________________________________
| P1 | P3 | P2 |
____________________________________
8 9 13

c) Shortest Remaining Time First


_____________________________________________
| P1 | P2 | P3 | P2 | P1 |
_____________________________________________
0.4 1 2 5.4 13

Calculation Details: Wait times


| | FCFS | SJF | SRTF |
|Process | Finish-Arr-CPU=Wait | Finish-Arr-CPU=Wait | Finish-Arr-CPU=Wait |
|________|_____________________|_____________________|_____________________|
| P1 | 8 - 0.0 - 8.0 = 0.0 | 8 - 0.0 - 8.0 = 0.0 |13 - 0.0 - 8.0 = 5.0 |
| P2 |12 - 0.4 - 4.0 = 7.6 |13 - 0.4 - 4.0 = 8.6 |5.4- 0.4 - 4.0 = 1.0 |
| P3 |13 - 1.0 - 1 = 11.0 | 9 - 1.0 - 1.0 = 7.0 | 2 - 1.0 - 1.0 = 0.0 |
___________________________________________________________________________
Average 6.2 5.2 2.0

2) Consider the following set of processes, with the length of the CPU burst
time given in milliseconds:

The processes are assumed to have arrived in the order P1, P2, P3, P4, P5, all at
time 0.

a. Draw four Gantt charts that illustrate the execution of these processes using the
following scheduling algorithms: FCFS, SJF, Non- pre- emptive priority (a larger
priority number implies a higher priority), and RR (quantum = 2).

b. What is the turnaround time of each process for each of the scheduling algorithms
in part a?

c. What is the waiting time of each process for each of these scheduling algorithms?

d. Which of the algorithms results in the minimum average waiting time (over all
processes)?

Solution:
3) The following processes are being scheduled using a Pre-emptive, Round
Robin scheduling algorithm. The length of a time quantum is 10 units.

a. Show the scheduling order of the processes using a Gantt chart.

b. What is the turnaround time for each process?

c. What is the waiting time for each process?

d. What is the CPU utilization rate?


Solution:

Answer:

 a) A GANTT chart, also known as a generalised activity normalisation time table, is a


sort of diagram in which a number of horizontal lines are displayed to illustrate the
quantity of work or production completed in a given period of time in relation to the
amount scheduled for those projects.

b) Turnaround time (TAT) is the period of time between when a process is submitted
and when it is finished.
It can alternatively be viewed as the total of the times spent waiting to execute on the
CPU, waiting in the ready queue or memory, and performing input/output.

P1:20-0-20,

P2:80-25=55,

P3:90-30=60,

P4:75-60=15,

P5: 120-100 = 20,

P6: 115-105 = 10

c) The amount of time a process spends in the ready state while it waits for the CPU
is known as waiting time.

Consider, for illustration, that we are utilising the First Come First Serve scheduling
algorithm and that the arrival times of the three processes below are 0 ms, 0 ms, and
2 ms.

The waiting times for the three processes will therefore be as follows: P1: 0 ms

P1:0,

p2:40,

P3:35,

P4:0,

P5:10,

P6:0

d) The percentage of the CPU utilised during the designated time period is
summarised in the CPU Utilization report.

Typically, the Core uses between 30 and 40 percent of the overall CPU capacity
during off-peak times and between 60 and 70 percent at peak times.

105/120 = 87.5 percent.


4) Consider the following snapshot of a system

Answer the following questions using the banker’s algorithm:

a. What is the content of the matrix Need?

b. Is the system in a safe state?

c. If a request from process P1 arrives for (0,4,2,0), can the request be granted
immediately?

Answer:

5) Consider the following snapshot of a system.

Using the banker’s algorithm, determine whether or not each of the following states
is unsafe. If the state is safe, illustrate the order in which the threads may complete.
Otherwise, illustrate why the state is unsafe.

a. Available = (0, 3, 0, 1)

b. Available = (1, 0, 0, 2)
Answer:

a. Not safe. Processes P2 , P1 , and P3 are able to finish, but no remaining


processes can finish.

Safe. Processes P1 , P2 , and P3 are able to finish. Following this, processes


P0 and P4 are also able to finish.

6) Consider the following snapshot of a system

Answer the following questions using the banker’s algorithm:

a. Illustrate that the system is in a safe state by demonstrating an order in which the
processes may complete.

b. If a request from process P1 arrives for (1, 1, 0, 0), can the request be granted
immediately?

c. If a request from process P4 arrives for (0, 0, 2, 0), can the request be granted
immediately?
Answer:
7) Consider a logical address space of 64 pages of 1,024 words each, mapped
onto a physical memory of 32 frames.

a. How many bits are there in the logical address?

b. How many bits are there in the physical address?

8) Given six memory partitions of 300 KB, 600 KB, 350 KB, 200 KB, 750 KB,
and 125 KB (in order).

• How would the first-fit, best-fit, and worst-fit algorithms place processes of
size 115 KB, 500 KB, 358 KB, 200 KB, and 375 KB (in order)?

• Rank the algorithms in terms of how efficiently they use memory


Answer:

In terms of efficient use of memory: Best-fit is the best (it still have a free memory
space of 777KB and all process is completely assigned) followed by First-fit (which
have free space of 777KB but available in smaller partition) and then worst-fit (which
have free space of 1152KB but a process cannot be assigned). See the detail in the
explanation section.

Explanation:

We have six free memory partition: 300KB (F1), 600KB (F2), 350KB (F3), 200KB
(F4), 750KB (F5) and 125KB (F6) (in order).

Using First-fit

First-fit means you assign the first available memory that can fit a process to it.

 115KB will fit into the first partition. So, F1 will have a remaining free space of 185KB
(300 - 115).
 500KB will fit into the second partition. So, F2 will have a remaining free space of
100KB (600 - 500)
 358KB will fit into the fifth partition. So, F5 will have a remaining free space of 392KB
(750 - 358)
 200KB will fit into the third partition. So, F3 will have a remaining free space of
150KB (350 -200)
 375KB will fit into the remaining partition of F5. So, F5 will a remaining free space of
17KB (392 - 375)

Using Best-fit

Best-fit means you assign the best memory available that can fit a process to the
process.

 115KB will best fit into the last partition (F6). So, F6 will now have a free remaining
space of 10KB (125 - 115)
 500KB will best fit into second partition. So, F2 will now have a free remaining space
of 100KB (600 - 500)
 358KB will best fit into the fifth partition. So, F5 will now have a free remaining space
of 392KB (750 - 358)
 200KB will best fit into the fourth partition and it will occupy the entire space with no
remaining space (200 - 200 = 0)
 375KB will best fit into the remaining space of the fifth partition. So, F5 will now have
a free space of 17KB (392 - 375)

Using Worst-fit

Worst-fit means that you assign the largest available memory space to a process.

 115KB will be fitted into the fifth partition. So, F5 will now have a free remaining
space of 635KB (750 - 115)
 500KB will be fitted also into the remaining space of the fifth partition. So, F5 will now
have a free remaining space of 135KB (635 - 500)
 358KB will be fitted into the second partition. So, F2 will now have a free remaining
space of 242KB (600 - 358)
 200KB will be fitted into the third partition. So, F3 will now have a free remaining
space of 150KB (350 - 200)
 375KB will not be assigned to any available memory space because none of the
available space can contain the 375KB process.

Based on the efficient use of memory, the algorithms are ranked as:

1. Best fit.
2. First fit.
3. Worst fit.

Given the following data:

 M1 = 300 KB.

 M2 = 600 KB.

 M3 = 350 KB.

 M4 = 200 KB.

 M5 = 750 KB.
 M6 125 KB.

 P1 = 115 KB.

 P2 = 500 KB.

 P3 = 358 KB.

 P4 = 200 KB.

 P5 = 375 KB.

What is a first-fit algorithm?

A first-fit algorithm can be defined as the simplest technique of


allocating memory block to processes by assigning the first available memory.

For P1 with a memory size of 115 KB, it would fit into the first memory partition.

For P2 with a memory size of 600 KB, it would fit into the second memory partition.

For P3 with a memory size of 358 KB, it would fit into the fifth memory partition.

For P4 with a memory size of 200 KB, it would fit into the third memory partition.

For P5 with a memory size of 375 KB, it would fit into the remaining fifth
memory partition.
What is a best-fit algorithm?

A best-fit algorithm can be defined as the technique of allocating memory block to


processes by assigning the smallest partition size that can store the process.

For P1 with a memory size of 115 KB, it would best fit into the sixth
memory partition.

For P2 with a memory size of 600 KB, it would best fit into the second
memory partition.

For P3 with a memory size of 358 KB, it would best fit into the fifth
memory partition.

For P4 with a memory size of 200 KB, it would best fit into the fourth
memory partition.

For P5 with a memory size of 375 KB, it would best fit into the remaining fifth
memory partition.

What is a worst-fit algorithm?

A worst-fit algorithm can be defined as the technique of allocating memory block


to processes by assigning the largest partition size that can store the process.

For P1 with a memory size of 115 KB, it would fit into the fifth memory partition.
For P2 with a memory size of 500 KB, it would fit into the remaining fifth
memory partition.

For P3 with a memory size of 358 KB, it would fit into the second memory partition.

For P4 with a memory size of 200 KB, it would fit into the third memory partition.

For P5 with a memory size of 375 KB, it would best fit into any of
the memory partition that is available.

9) Assuming a 1-KB page size, what are the page numbers and offsets for the
following address references (provided as decimal numbers):

a. 3085

b. 42095

c. 215201

d. 650000

e. 2000001

Answer:

Page size =2n =1024 B= 210 B

# of bits in offset part (n) =10

Solution steps:
1. Convert logical address: Decimal to Binary

2. Split binary address to 2 parts (page # , Offset), offset : n digits

3. Convert offset & page# : Binary to Decimal

8.20 Assuming a 1-KB page size, what are the page numbers and offsets for the
following address references (provided as decimal numbers):

10) Consider a paging system with the page table stored in memory.

a. If a memory reference takes 50 nanoseconds, how long does a paged memory


reference take?

b. If we add TLBs, and if 75 percent of all page-table references are found in the
TLBs, what is the effective memory reference time? (Assume that finding a page-
table entry in the TLBs takes 2 nanoseconds, if the entry is present.)

Answer:
11) Consider the following segment table

What are the physical addresses for the following logical addresses?

a. 0,430

b. 1,10

c. 2,500

d. 3,400

e. 4,112

Answer:

a. 219+430 = 649
b. 2300 + 10 = 2310
c. illegal reference, trap to operating system
d. 1327+ 400= 1727
e. illegal reference, trap to operating system

12) An operating system supports a paged virtual memory. The central


processor has a cycle time of 1 microsecond. It costs an additional 1
microsecond to access a page other than the current one. Pages have 1,000
words, and the paging device is a drum that rotates at 3,000 revolutions per
minute and transfers 1 million words per second.

The following statistical measurements were obtained from the system:

• One percent of all instructions executed accessed a page other than the current
page.
• Of the instructions that accessed another page, 80 percent accessed a page
already in memory.

• When a new page was required, the replaced page was modified 50 percent of the
time.

Calculate the effective instruction time on this system, assuming that the system is
running one process only and that the processor is idle during drum transfers.

Answer:

Effective access time

= 0.99 × (1 sec + 0.008 × (2 sec) + 0.002 × (10,000 sec + 1,000 sec) + 0.001 ×
(10,000 sec + 1,000 sec)

= (0.99 + 0.016 + 22.0 + 11.0) sec

= 34.0 sec

13) Consider the following page reference string: 1, 2, 3, 4, 2, 1, 5, 6, 2, 1, 2, 3,


7, 6, 3, 2, 1, 2, 3, 6.

How many page faults would occur for the following replacement algorithms,
assuming one, two, three, four, five, six, and seven frames? Remember that all
frames are initially empty, so your first unique pages will cost one fault each.

• LRU replacement

• FIFO replacement

• Optimal replacement

Answer: PDF available

14) Consider the following page reference string: 7, 2, 3, 1, 2, 5, 3, 4, 6, 7, 7, 1,


0, 5, 4, 6, 2, 3, 0 , 1.

Assuming demand paging with three frames, how many page faults would occur for
the following replacement algorithms?
• LRU replacement

• FIFO replacement

• Optimal replacement

Answer:

Assuming demand paging with three frames, how many page faults would occur for
the following replacement algorithms?

Answer:

• 18

• 17

• 13

15) In a 1,024-KB segment, memory is allocated using the buddy system. Draw
a tree illustrating how the following memory requests are allocated:

• Request 5-KB

• Request 135 KB.

• Request 14 KB.

• Request 3 KB

• Request 12 KB.

Next, modify the tree for the following releases of memory. Perform coalescing
whenever possible:

• Release 3 KB.

• Release 5 KB.

• Release 14 KB.

• Release 12 KB.
Answer:

The following allocation is made by the Buddy system: The 240-byte request is
assigned a 256-byte segment. The 120-byte request is assigned a 128-byte
segment, the 60- byte request is assigned a 64-byte segment and the 130-byte
request is assigned a 256-byte segment.

After the allocation, the following segment sizes are available: 64-bytes, 256-bytes,
1K, 2K, 4K, 8K, 16K, 32K, 64K, 128K, 256K, and 512K.

After the releases of memory, the only segment in use would be a 256-byte segment
containing 130 bytes of data. The following segments will be free: 256 bytes, 512
bytes, 1K, 2K, 4K, 8K, 16K, 32K, 64K, 128K, 256K, and 512K.

16) Consider a file system on a disk that has both logical and physical block
sizes of 512 bytes. Assume that the information about each file is already in
memory. For each of the three allocation strategies (contiguous, linked, and
indexed), answer these questions:

a. How is the logical-to-physical address mapping accomplished in this system? (For


the indexed allocation, assume that a file is always less than 512 blocks long.)

b. If we are currently at logical block 10 (the last block accessed was block 10) and
want to access logical block 4, how many physical blocks must be read from the
disk?

Answer:

Assumptions: 1. Let L be the logical address and let P be the physical address. 2.
The assumption in part (a) is poorly given. It's more reasonable to simply assume
that the index is small enough to fit into a single block. In fact, a 512 block file will
probably require more than a single 512 byte block because block addresses
typically require 3-4 bytes each.

(a) Overview The CPU generates a logical address L (a relative offset in a file) and
the file system has to convert it to a physical address P (a disk address represented
by a block number PB and an offset in this block). For convenience of calculation, we
assume that blocks are numbered from 0. In any approach, we can determine the
logical block number LB by dividing the logical address L by the logical block size
(here 512). Similarly, the offset, which will be the same for logical and physical
addresses since the block sizes are identical, is determined by applying modulus.
The offset is the same in all approaches.

LB := L div 512
offset := L mod 512

Contiguous: Assume S is the starting address of the contiguous segment. Then a


simple approach to mapping the address is:

P=S+L

If we prefer to consider the block level,

PB = SB + LB

(b) If we are currently at logical block 10 and we want to access logical block 4 ...

Contiguous: We simply move the disk head back by 6 blocks (from physical block 10
to physical block 4) because the space allocated to the file is contiguous. Then we
read block 4, for a total of one read.
17) Consider a file system that uses Inodes to represent files. Disk blocks are 8
KB in size, and a pointer to a disk block requires 4 bytes. This file system has
12 direct disk blocks, as well as single, double, and triple indirect disk blocks.

What is the maximum size of a file that can be stored in this file system?

Answer:

Direct Block Pointer = 12

Disk Block size = 8 KB

Disk Block Address size = 4 B

Number of entries in Block = Disk Block size / Disk Block Address size

= 8KB/4B = 2048 Bytes

12 direct disk blocks * 8KB = 96KB


1 single disk block = 2048 * 8KB = 16384KB
1 double disk block = 2048^2 * 8 KB = 33554432 KB
1 triple disk block = 2048^3 * 8 KB = 68719476736 KB
= (96KB+16384KB+33554432 KB+68719476736 KB)
Total = 68.75 TB
18) Consider a file currently consisting of 100 blocks. Assume that the file-
control block (and the index block, in the case of indexed allocation) is already
in memory. Calculate how many disk I/O operations are required for
contiguous, linked, and indexed (single-level) allocation strategies, if, for one
block, the following conditions hold. In the contiguous-allocation case,
assume that there is no room to grow at the beginning but there is room to
grow at the end. Also assume that the block information to be added is stored
in memory.

a. The block is added at the beginning.

b. The block is added in the middle.

c. The block is added at the end.

d. The block is removed from the beginning.

e. The block is removed from the middle.

f. The block is removed from the end.

19) Suppose that a disk drive has 5000 cylinders, numbered 0 to 4999. The
drive is currently serving a request at cylinder 2150, and the previous request
was at cylinder 1805. The queue of pending requests, in FIFO order, is: 2069,
1212, 2296, 2800, 544, 1618, 356, 1523, 4965, 3681. Starting from the current
head position, what is the total distance (in cylinders) that the disk arm moves
to satisfy all the pending requests for each of the following disk-scheduling
algorithms?
a. FCFS

b. SCAN

c. C-SCAN

d. LOOK

e. C-LOOK

20) Consider a RAID level 5 organization comprising five disks, with the parity
for sets of four blocks on four disks stored on the fifth disk.

How many blocks are accessed in order to perform the following?

a. A write of one block of data

b. A write of seven continuous blocks of data.

You might also like