You are on page 1of 8

SCHOOL OF DEPARTMENT OF

POSTGRADUATE COMPUTER SCIENCE


STUDIES,GOMBE STATE
UNIVERSITY

REG NO: PG19/MSC/CSC/1007


COURSE TITLE: OPERATING SYSTEM
COURSE CODE: COSC801
QUESTION 1A
Name any three main components of most major operating systems (such as UNIX
or Windows-XX) and briefly describe their role.
ANSWER
Operating System is the spine of the computer , Some of its functions are but
not limited to , providing user interface for the user to interact with computer
resources , manage the resources and provide communication between various
components to the computer hardware and software,
Three components of the Computer OS are as follows:
1. File Management - The most common use of OS by the user is to create and
modify files , OS is responsible for creating , locating and manipulating files
and folders , OS is also the one responsible for identifying where on
Secondary storage the files and folders are stored
2. Process Management. - OS is responsible for determining which process
should be executed when , Process can be thought of a running program in
memory , memory is limited and hence not all the programs can be run
simultaneously , OS determines which one to run and which one to halt.
3. Network Management - OS is responsible for managing the networks which
ranges from performance enhancements to security.
QUESTION 1B
Consider a system with a mixture of I/O bound processes and CPU bound processes
(a) Explain how this mixture of processes maximizes system utilization.
(b) Explain why this combination is more important in batch systems than it is
on most computers sitting around in our department
ANSWER
 We want to keep all parts of the system busy by overlapping I/O operations
with CPU operations. Overall, if we have some processes using the CPU
while others are waiting  on I/O, then the system will be more utilized.
 In general, our systems are underutilized (there are a lot of wasted cycles both
on I/O devices as well as CPU), and user interaction is more important. Batch
systems were expensive systems that were busy all the time.
QUESTION 1C
Define a counting semaphore, its initialization, and the two operations used to
operate on it.

ANSWER
Counting semaphores can be used to control access to a given resource
consisting of a finite number of instances. Each process that wishes to use a resource
performs a wait () operation on the semaphore. When the count for the semaphore
goes to 0, all resources are being used. And the process that wish to use a resource
will block until the count becomes greater than 0.
OPERATIONS:
 Wait(); decrements the value and either causes the process to wait until the
resource is available or allocates the process the resource.
 Signal(); increments the counter, releasing a waiting process (if any).

QUESTION 2
Given the five processes below with their indicated number of run time units, answer
the questions that follow. Assume processes arrived in numerical order at time 0.
Process ID CPU requirements
P1 7
P2 1
P3 2
P4 5
P5 3

(a) Show the scheduling order for these processes under first-come-first-served,
shortest-job
First, and round-robin scheduling (quantum = 1).
(b) Briefly explain why these two values are meaningful criteria for evaluating
scheduling Algorithms.
SOLUTION 2A
FCFS: the processes arrive in the order P1, P2, P3, P4 and P5 are served in FCFS
order then we get the result shown in the following Gantt chart.
Gantt chart:
P1 P2 P3 P4 P5
0 7 8 10 15 18
Using Gantt chart order of these process
P1, p2, p3, p4, p5. 12345
SJF:
P2 P3 P5 P4 P1
0 1 3 6 11 18
P2, P3, P5, P4, P1 23541
RR: Given that time quantum = 1
P1 P2 P3 P4 P5 P1 P3 P4 P5 P1 P4 P5 P1 P4 P1 P4 P1 P1
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18

SOLUTION 2B
wait time & turnaround time together give a criterion to measure the effectiveness of
a scheduling algorithm,specifically with respect to properties perceived by the
processes themselves.

QUESTION 3
Which of the following require assistance from hardware to implement correctly
and/or safely? For those that do, circle them, and name the necessary hardware
support. For those that don’t briefly explain why (one or two sentences at most).
ANSWER

System call: requires hardware support, in particular to set the CPU’s protection
bit to run in protected kernel model.
Process creation: requires HW support. Must do a system call, so need a protection
Bit. Also, need to manipulate address spaces (i.e., create new page tables for the new
process).
Thread creation: [ok if you argued that kernel threads require system calls, and
hence need a protection bit, but user-level threads do not need assistance from HW]
Process context switch: requires HW support. Need a timer interrupt to prevent
starvation, and also need to manipulate address spaces (usually by changing a
register to point to the page directory for the new process, e.g., cr3 on x86) Thread
context switch: [ok if you argued that kernel threads require system calls, but user-
level threads do not need HW assistance]
Lock acquisition : requires HW support. Need support for atomic instructions (e.g.,
test and set), or support for disabling/enabling interrupts.
Lock release: [even if you require HW support to grab a lock, in many cases you
don’t need it to release the lock. See, for example, how test-and-set based locks
works – you don’t use the test-and-set to release the lock.]

QUESTION 4A
Name three ways in which the processor can transition from user mode to kernel
mode? Can the user execute arbitrary code after transition?

ANSWER
1) There are several reasons for transmission of the processor from user mode to
kernel mode. Some of them are as follows:
a) The user process can execute a trap instruction (e.g. system call). A trap is
known as a synchronous software interrupt.
b) The user process can cause an exception (divide by zero, access bad
address, bad instruction, page fault, etc).
c) The processor can transition into kernel mode when receiving an interrupt.
No, the user cannot execute arbitrary code because entry to kernel mode is through a
restricted set of routines that ensure only the kernel is running, not the user process.

QUESTION 4B(i)
What needs to be saved and restored on a context switch between two threads in the
same process? What if two are in different processes?
ANSWER
Need to save the registers, stack pointer, and program counter into the thread control
block (TCB) of the thread that is no longer running. Need to reload the registers,
stack pointer, and program counter from the TCB of the new thread.
When the threads are from different processes, need to not only save and
restore what was given above, but also need to load the pointer for the top-level page
table of the new address space. (Note that this top-level page table pointer from the
old process does not need to be saved since it does not change and is already
contained in the process control block (PCB))
QUESTION 4B(ii)
Why is switching threads less costly than switching processes?
ANSWER
Less state needs to be saved and restored. Furthermore, switching between threads
benefits from caching; whereas, switching between processes invalidates the cache
and TLB.

QUESTION 4B(ii)
Suppose a thread is running in a critical section of code, meaning that it has acquired
all the locks through proper arbitration. Can it get context switched? Why or why
not?
ANSWER
Yes, a process holding a lock can get context switched. Locks (especially user-level
locks) are independent of the scheduler. (Note that threads running in the kernel with
interrupts disabled would not get context-switched).
QUESTION 4C(i)
Name the four conditions required for deadlock and give a brief (one sentence)
description of each.
ANSWER
Mutual exclusion: a resource can be possessed by only one thread.
Hold and wait: A thread can hold a resource such as a lock while waiting for
another.
No preemption: The resource cannot be taken away from the thread.
Circular wait: Two or more threads form a circular chain where each thread waits
for a resource that the next thread in the chain holds
QUESTION 4C(ii)
Does a cyclic dependency always lead to deadlock? Why or why not?
ANSWER
No. If multiple equivalent resources exist, then a cycle could exist that is not a
deadlock. The reason is that some thread that is not part of the cycle could release a
resource needed by a thread in the cycle, thereby breaking the cycle.
QUESTION 4C(iii)
What is the difference between deadlock prevention and deadlock avoidance? What
category does Bankers algorithm falls in and why?
Deadlock prevention prevents deadlock by preventing one of the four
conditions required for deadlock to occur.
Deadlock avoidance ensures the system is always in a safe state by not
granting requests that may move the system to an unsafe state. A is considered safe
if it is possible for all processes to finish executing (i.e. a sequence exists such that
each process can be given all its required resources, run to completion, and return
resources allocated, thus allowing another process to do the same, etc until all
process complete). Deadlock avoidance requires the system to keep track of the
resources such that it knows the allocated, available, and remaining resource needs.
The Bankers algorithm is a deadlock avoidance scheme since it defines an
algorithm and structure to ensure the system remains in a safe state before granting
any new resource requests.
QUESTION 4D
What are exceptions? Name two different types of exceptions and give an example
of each type.
ANSWER
Exceptions are events that stop normal execution, switch the execution mode
into kernel mode, and begin execution at special locations within the kernel.
Examples include system calls, divide by zero errors, illegal instructions, and page
faults.
QUESTION 4E
Why would two processes want to use shared memory for communication instead
of using message passing?
ANSWER
Performance. Communicating via shared memory is often faster and more efficient
since there is no kernel intervention and no copying.
QUESTION 4F
What is internal fragmentation? External fragmentation? Give a brief example of
each.

ANSWER
Internal fragmentation: allocated space that is unused. For example, a process
may have allocated a 1KB page, but uses only 10 bytes.
External fragmentation: unallocated “free” space that lies between allocated space
such that contiguous regions of free space is insufficient to satisfy subsequent space
allocation requests even though sufficient free space exists in aggregate.

You might also like