COS3721 TL 202 2 2018 B PDF
COS3721 TL 202 2 2018 B PDF
Semesters 2
School of Computing
BARCODE
Open Rubric
Assignment 2 – Semester 2
Marking scheme
Question 1[14 marks] 1.1.a (8), [1.1.b or 1.1.c](7) and 1.2 (not marked)
2. Step 2: We search the array need for the process that needs less resources than those available.
Only process P0 needs less resources than those available and can therefore be completed.
3. Step 3: assuming process P0 is completed, the resource allocated to it are released and added
to the available resources:
4. Step 2: We search the array need again for the processes that can be completed. P3 is the only
process found.
5. Step 3: assuming P3 is completed; the resources allocated to it are released and added to Work.
6. Step 2: Search for the next process(es) that can be completed. P1, P2 and P4 can be completed.
We select P1 however, any of the three processes could equally be considered.
8. Step 2: Search for the next process that can be completed. The two remaining processes can
each be completed. We first select P2,
Finish = (t, t, t, t, f)
b. If a request from process P1 arrives for (1, 1, 0, 0), can the request be
granted immediately?
Answer:
(a) Stop if the requested resources are greater than what the process needs,
(b) Stop if the requested resources are not available ( the process must wait until the requested resources become
available)
(c) Assume the requested resources are allocated, update the state of the system accordingly and check (Banker’s
algorithm) if the updated state is safe.
2- Compare the requested resources and the resources available: (1, 1, 0, 0) ≤ (3, 3, 2, 1).
3- If the requested resources were allocated to P1, the new state would be:
AB C D AB C D AB C D AB C D
(d) Re-calculate the allocation of P1 by adding the requested resources to the already allocated resources.
(e) Re-calculate the need of P1 by subtracting the requested resources from the existing need.
1. Step 1:
Work = (2, 2, 2,1) : resource available
Finish = (f, f, f, f, f): none of the processes is completed.
2. Step 2: We search the array need for the process that needs less resources than those available.
Only process P0 needs less resources than those available and can therefore be completed.
3. Step 3: assuming process P0 is completed, the resource allocated to it are released and added
to the available resources:
4. Step 2: We search the array need for the process that needs less resources than those available.
P3 can be completed.
5. Step 3: assuming process P3 is completed, the resource allocated to it are released and added
to the available resources:
6. Step 2: We search the array need for the process that needs less resources than those available.
P1, P2, and P4 can be completed.
Note: Since any of these processes can be selected, by considering different options and doing the
calculations accordingly, each of the followings safe sequences may be reached:
<P0, P3, P1, P2, P4>, <P0, P3, P1, P4, P2>, <P0, P3, P2, P1, P4>, <P0, P3, P2, P4, P1>,
<P0, P3, P4, P1, P2>, <P0, P3, P4, P2, P1>
Conclusion: the requested resources can be safely granted immediately.
c. If a request from process P4 arrives for (0, 0, 2, 0), can the request be granted
Immediately?
Answer:
Please repeat the same steps presented in ( c ) above to check if the request from P4 can be safely granted
immediately.
1.2 What is the optimistic assumption made in the deadlock-detection algorithm? How can
this assumption be violated?
Answer:
The optimistic assumption is that there will not be any form of circular wait in terms of resources
allocated and processes making requests for them. This assumption could be violated if a circular wait
does indeed occur in practice.
2.1 Although Android does not support swapping on its boot disk, it is possible to set up a
swap space using a separate SD nonvolatile memory card. W hy would Android disallow
swapping on its boot disk yet allow it on a secondary disk?
Answer (not marked)
Primarily because Android does not wish for its boot disk to be used as swap space; the boot disk
has limited storage capacity. However, Android does support swapping, it is just that users must
provide their own separate SD card for swap space.
2.2 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:
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?
Answer:
• LRU replacement
7 2 3 1 2 5 3 4 6 7 7 1 0 5 4 6 2 3 0 1
Fault y y y y n y y y y y n y y y y y y y y y
F1 7 7 7 1 1 1 3 3 3 7 7 7 5 5 5 2 2 2 1
F2 - 2 2 2 2 2 2 4 4 4 1 1 1 4 4 4 3 3 3
F3 - - 3 3 3 5 5 5 6 6 6 0 0 0 6 6 6 0 0
• FIFO replacement
7 2 3 1 2 5 3 4 6 7 7 1 0 5 4 6 2 3 0 1
Fault y y y y n y n y y y n y y y y y y y y y
F1 7 7 7 1 1 1 6 6 6 0 0 0 6 6 6 0 0
F2 - 2 2 2 5 5 5 7 7 7 5 5 5 2 2 2 1
F3 - - 3 3 3 4 4 4 1 1 1 4 4 4 3 3 3
• Optimal replacement
7 2 3 1 2 5 3 4 6 7 7 1 0 5 4 6 2 3 0 1
Fault y y y y n y n y y y n n y n y y y y n n
F1 7 7 7 1 1 1 1 1 1 1 1 1 1
F2 - 2 2 2 5 5 5 5 5 4 6 2 3
F3 - - 3 3 3 4 6 7 0 0 0 0 0
3.2 When a page fault occurs, the process requesting the page must block while waiting for
the page to be brought from disk into physical memory. Assume that there exists a
process with five user-level threads and that the mapping of user threads to kernel
threads is one to one. If one user thread incurs a page fault while accessing its stack,
would the other user threads belonging to the same process also be affected by the page
fault—that is, would they also have to wait for the faulting page to be brought into
memory? Explain.
Answer:
Yes, because there is only one kernel thread for all user threads, that kernel thread blocks while waiting for the page
fault to be resolved. Since there are no other kernel threads for available user threads, all other user threads in the
process are thus affected by the page fault.
4.1 Why is it important to balance file-system I/O among the disks and controllers on a
system in a multitasking environment?
Answer:
A system can perform only at the speed of its slowest bottleneck. Disks or disk controllers
are frequently the bottleneck in modern systems as their individual performance cannot
keep up with that of the CPU and system bus. By balancing I/O among disks and
controllers, neither an individual disk nor a controller is overwhelmed, so that bottleneck is
avoided.
4.2 What are the tradeoffs involved in rereading code pages from the file system versus
using swap space to store them?
Answer:
If code pages are stored in swap space, they can be transferred more quickly to main
memory (because swap space allocation is tuned for faster performance than general file
system allocation). Using swap space can require startup time if the pages are copied
there at process invocation rather than just being paged out to swap space on demand.
Also, more swap space must be allocated if it is used for both code and data pages.
5.1 The open-file table is used to maintain information about files that are currently open.
Should the operating system maintain a separate table for each user or maintain just one
table that contains references to files that are currently being accessed by all users? If
the same file is being accessed by two different programs or users, should there be
separate entries in the open-file table? Explain.
Answer:
By keeping a central open-file table, the operating system can performthe following
operation thatwould be infeasible otherwise. Consider a file that is currently being accessed
by one ormore processes. If the file is deleted, then it should not be removed fromthe disk
until all processes accessing the file have closed it. This check can be performed only if
there is centralized accounting of number of processes accessing the file. On the other
hand, if two processes are accessing the file, then two separate states need to be
maintained to keep track of the current location of which parts of the file are being accessed
by the two processes. This requires the operating system to maintain separate entries for
the two processes.
COS3721/202/2/2018
5.2 Provide examples of applications that typically access files according to the following
methods:
• Sequential
• Random
Answer:
• Applications that access files sequentially include word processors, music players, video players,
and web servers.
• Applications that access files randomly include databases, video and audio editors.
6.1 What hardware features does a computer system need for efficient capability
manipulation? Can these features be used for memory protection?
Answer:
Capabilities associated with domains provide substantial flexibility and faster access to objects.
When a domain presents a capability, the system just needs to check the authenticity of the
capability and that could be performed efficiently. Capabilities could also be passed around from
one domain to another domain with great ease, allowing a system with a great amount of
flexibility. However, the flexibility comes at the cost of a lack of control: revoking capabilities and
restricting the flow of capabilities is a difficult task.
Please note that your exam will be similar to most of the previous years’
examinations in terms of the structure, format, and level of complexity. You
will not be allowed to use the prescribed textbook and a calculator. We tried to
cover the syllabus as much as we could.
A student who covered the syllabus during the semester, studied all the
important concepts and algorithms in the textbook, and did all the
assignments should normally be able to pass the coming exam. The theory,
design concepts, algorithms and applications are kept to the a similar level of
complexity as in the previous exam papers, assignments and exercises in the
textbook.
10 SOURCES CONSULTED
SILBERSCHATZ A., GALVIN P. & GAGNE G. Operating Systems Concepts, 9th Edition, John
Wiley & Sons Inc., 2014.ISBN 978-11180-9375-7.
©UNISA 2018