HCS 103 Operating Systems Assignment One Marks
HCS 103 Operating Systems Assignment One Marks
Name Q1 Q2 Q3 Q4 Q5 total
Chivanga Godspower 16 17 8 4 15 60
Mandebu Ndiyenga 17 17 8 4 17 63
Makaza Shingirai P. 16 16 4 0 14 50
Duvai Panashe 16 16 6 5 17 60
Sithole Biatitude 12 16 11 8 13 60
Chidau Allen Takudzwa 17 17 12 4 10 60
Chabaya Democracy 17 17 10 7 10 61
Mwaita Kudakwashe Dawn 17 17 12 12 17 75
Deredza Lazarous 16 15 8 15 16 70
Mhondiwa Shamaine 17 9 12 17 15 70
Masuku Buhlebenkosi 13 17 10 3 17 60
Simango Caleb 13 17 4 0 16 50
Dzapasi Marvel Tanaka 13 17 3 0 16 50
Nyakudanga Farai 8 17 8 12 17 62
Mangena Tafadzwa c. 11 13 10 3 16 53
Dlomo Sibonginkosi 12 17 10 5 16 60
Mapfinya tadiwa 13 14 9 17 17 70
Togara Patric 10 16 10 10 17 63
Virima Farai 13 17 11 2 17 60
Zhakata Laina 17 17 11 4 11 60
Dahwa Deligence
Munyoro Tapiwa
Mazonde Phyciethy
Tinashe Kota
Magujure Taurai
Question 1 assignment 1
a. Peripheral devices interface to the computer system through the device drivers these device
drivers are a group of software written by the manufacturer of the device and they need not to be
corrupted by user programs that is why they run in the kernel mode so as not to be modified by user
programs
Question 2
Question 3
•Creation and deletion of both user and system processes. The processes in the system can execute
concurrently for information sharing, computation speedup, modularity, and convenience. Concurrent
execution requires a mechanism for process creation and deletion. The required resources are given to
the process when it is created, or allocated to it while it is running. When the process terminates, the OS
needs to reclaim any reusable resources.
•Suspension and resumption of processes. In process scheduling, the OS needs to change the process's
state to waiting or ready state when it is waiting for some resources. When the required resources are
available, OS needs to change its state to running state to resume its execution.
•Provision of mechanism for process synchronization. Cooperating processes may share data.
Concurrent access to shared data may result in data inconsistency. OS has to provide mechanisms for
processes synchronization to ensure the orderly execution of cooperating processes, so that data
consistency is maintained.
•Provision of mechanism for process communication. The processes executing under the OS may be
either independent processes or cooperating processes. Cooperating processes must have the means to
communicate with each other.
b. In UNIX, there is only one system call to create a new process: fork. This call creates an exact
clone of the calling process. After the fork, the two processes, the parent and the child, have the same
memory image, the same environment strings, and the same open files. That is all there is. Usually, the
child process then executes execve or a similar system call to change its memory image and run a new
program so in this code a variable pid of int data type is declared and then pid is assigned the system call
fork() , printf will then print fork() library function code to the standard output, since this code is
privileged code nothing will be printed on the standard output.
c. In a real time system a process with high priority will preempt any other process so if a process
executing in kernel mode cannot be preempted the that software cannot be a real time software.
Question 4
Part a.
i. When a process wishes to enter its critical section, it is assigned a ticket number. The ticket number
assigned is calculated by adding one to the largest of the ticket numbers currently held by the processes
waiting to enter their critical section and the process already in its critical section. The process with the
smallest ticket number has the highest precedence for entering its critical section. In case more than one
process receives the same ticket number, the process with the smallest numerical name enters its
critical section. When a process exits its critical section, it resets its ticket number to zero.
ii. If each process is assigned a unique process number, then there is a unique, strict ordering of
processes at all times. Therefore, deadlock cannot occur.
ii. To demonstrate mutual exclusion, we first need to prove the following lemma: if Pi is in its critical
section, and Pk has calculated its number[k] and is attempting to enter its critical section, then the
following relationship holds:
Tw2 Pi begins its final execution, for j = k, of the second while loop. We therefore have Tw1 < Tw2.
Tk3 Pk sets choosing[k] to false. We have Tk1 < Tk2 < Tk3.
Since at Tw1, choosing[k] = false, we have either Tw1 < Tk1 or Tk3 < Tw1. In the first case, we have
number[i] < number[k], since Pi was assigned its number prior to Pk; this satisfies the condition of the
lemma.
In the second case, we have Tk2 < Tk3 < Tw1 < Tw2, and therefore Tk2 < Tw2.
This means that at Tw2, Pi has read the current value of number[k]. Moreover, as Tw2 is the moment at
which the final execution of the second while for j = k takes place, we have (number[i], i ) < ( number[k],
k), which completes the proof of the lemma.
It is now easy to show the mutual exclusion is enforced. Assume that Pi is in its critical section and Pk is
attempting to enter its critical section. Pk will be unable to enter its critical section, as it will find
number[i] not equal to 0 ≠and
Part b.
This code causes a deadlock, because the writer lock will spin, waiting for all readers to release the lock,
including this thread.
Part c.
Without using the memory barriers, on some processors it is possible that c receives the new value of b,
while d receives the old value of a. For example, c could equal 4 (what we expect), yet d could equal 1
(not what we expect). Using the mb() insures a and b are written in the intended order, while the rmb()
insures c and d are read in the intended order.
Question 5
Part a.
A few of the better-known microkernels include Integrity, K42, L4, PikeOS, QNX, Symbian, and MINIX3.
1. Increased attention to what really belongs in the kernel and what doesn’t. This doesn’t always work
out in practice in monolithic kernel, but it’s useful to think about.
2. Work on very fast inter-process communication (IPC). Since microkernel’s live and die by the speed of
process-to-process transitions and communications, this is an area where they focused their efforts.
3. Attention to interfaces between kernel components. Monolithic kernel can benefit from clean, well-
designed interfaces between core components even if everything runs in the same address space.
Part b.
1. The original TLB fault happens in the virtual machine (VM). Control immediately jumps to the host
operating system.
2. The host notices that the fault has occurred in the VM and delegates handling of the fault to the
virtual machine monitor (VMM).
3. The VMM notes that this as a TLB miss which must be handled by the guest OS, and vectors control to
the guest operating system’s TLB fault handling code.
4. The guest OS will begin executing believing that the original TLB fault vectored control to it
immediately. It will look up the correct translation for the process running in the VM that generated the
fault and attempt load it into the TLB.
5. The attempt to load the TLB by the guest OS will generate another fault because it is not running in
privileged mode. This second fault will again be vectored by the host OS to the VMM.
6. The VMM will inspect the TLB write and deem it to be safe if the physical address that the translation
points to is physical memory allocated to the VM. In this case, the TLB modification will complete, and
the process running inside the VM will be restarted.
Part c.
1. Virtual memory and associated page replacement algorithms exploit the temporal and spatial locality
of a program’s accesses to its data. Programs tend to access pages that were accessed recently, enabling
physical memory to be used as a cache for all of the data used by a program during its execution.
Programs also tend to access data across a given page, which helps amortize the cost of bringing pages
in from disk. Without such locality, virtual memory would be prohibitively slow.
2. The file buffer cache and associate replacement algorithms exploit the temporal and spatial locality of
a program’s accesses to file blocks. Programs tend to access recently-accessed file blocks, enabling the
file buffer cache to serve a significant fraction of requests from memory instead of disk even though the
file system is a couple of orders of magnitude larger than the file buffer cache. Programs also tend to
access file blocks logically near previously-accessed file blocks (e.g., sequentially), enabling the system to
use techniques like read-ahead to anticipate program behavior.
Students should have included two separate examples, and at least a temporal or spatial motivation for
how locality is exploited in each example.
Question 2
Question 3 and 4
Students should requested Deredza Lazarus’ answers they are the most appropriate answears.