Sie sind auf Seite 1von 8

CSE 410 Exam 2

1. Which type of process is generally favored by a multilevel feedback queuing scheduler – a processor-
bound process an an I/O-bound process? Briefly explain why.
a. I/O – will only be in que when it needs an action
2. Consider the following set of processes:
Process Name Arrival Time Service Time
1 0 3
2 1 5
3 9 2
4 9 5
5 12 5

a. Consider FCFS, RR and SPN, SRT, HRRN ( [Time Waiting + Service] / Service), Feedback
(each time a process is preempted, it is demoted to next lower-priority que) scheduling
algorithms. Assume a quantum of 1.
Fill out the process number in each time unit
Time 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
FCFS 1 1 1 2 2 2 2 2 3 3 4 4 4 4 4 5 5 5 5 5
RR 1 2 1 2 3 1 2 3 2 4 2 4 5 4 5 4 5 4 5 5
SPN 1 1 1 3 3 2 2 2 2 2 4 4 4 4 4 5 5 5 5 5
SRT 1 1 1 3 3 2 2 2 2 2 4 4 4 4 4 5 5 5 5 5
HRRN 1 1 2 2 2 2 2 3 3 4 4 4 4 4 5 5 5 5 5 5
Feedback 1 1 2 3 1 2 3 2 2 4 2 4 5 4 5 4 5 4 5 5

b. Compute finish time, turnaround time for each process.


Process 1 2 3 4 5
FCFS Finish Time 3 8 10 15 20
Turnaround 3 7 7 6 8
RR Finish Time 6 11 8 18 20
Turnaround 6 10 5 9 8
SPN Finish Time 3 10 5 15 20
Turnaround 3 9 2 6 8
SRT Finish Time 3 10 5 15 20
Turnaround 3 9 2 6 8
HRRN Finish Time 3 8 10 15 20
Turnaround 3 7 7 6 8
Feedback Finish Time 5 11 7 18 20
Turnaround 5 10 4 9 8

3. List four design issues for which the concept of concurrency is relevant.
a. Communication among processes
b. Sharing resources
c. Synchronization of multiple processes
d. Allocation of processor time
4. Define critical resource and critical section.
a. Critical resource – non-sharable resources
b. Critical Section – A section of code within a process that requires access to shared resources and
which may not be executed while another process is in a corresponding section of code
5. Define deadlock and starvation.
a. Deadlock – A situation when two or more processes are unable to proceed because each is
waiting for one of the others to do something
b. Starvation – A situation in which a runnable process is overlooked indefinitely by the scheduler;
although it is able to proceed, it is never chosen
6. List three degree of awareness between processes.
a. Unaware  mutual exclusion, deadlock, starvation
b. Indirectly aware  waiting is mutually exclusive, critical section maintains data integrity
c. Directly aware  messages are passed, possible deadlock (wait for message), possible starvation
7. Define mutual exclusion and list the requirements for mutual exclusion.
a. Only 1 process at a time is allowed in the critical section for a resource
b. A process that halts in its non-critical section must do so without interfering with other processes
c. No deadlock or starvation
d. A process must not be delayed access to a critical section when there is no other process using it
e. No assumptions are made about relative process speeds or number of processes
f. A process remains inside its critical section for only a finite time only
8. What is the difference between strong and weak semaphores>
a. Strong: process that is blocked longest is released first (FCFS)
b. Weak: order of programs released is not specified
9. Compare semaphore and monitor.
a. Semaphore – a variable that has an integer value for three operations:
i. Wait & signal handled by program
ii. Three operations: initialized, wait, signal
iii. Resource access is correct only if programmed correctly
b. Monitors – software module
i. Synconization is confined in monitor
ii. Easy to verify correctness of sync and detect bugs
iii. Correct for access to all programs if monitor is programmed correctly
10. What is the distinction between blocking and nonblocking with respect to messages?
a. Blocking: process must wait for send or receive message
b. Non-blocking: process doesn’t have to wait for message passing
11. Consider the following five processes. Assume that a-f and temp1-temp5 are all shared variables
a. P1: temp1 = a+b;
b. P2: temp2 = c+d
c. P3: temp3 = e/f;
d. P4: temp4 = temp1 * temp2;
e. P5: temp5 = temp4 – temp3;
f. Draw the process flow graph for these five processes, such that concurrency is maximized
P1 (temp1) P2(temp2)
P4 (temp4) p3 (temp3)
P5 (temp5)
g. Assume that all five processes are executing concurrently. Using semaphores, synchronize these
processes (as necessary) according to your process flow graph. In other words, add semWait()
and semSignal() statements (as needed) around temp1-temp5, in order to ensure correct
execution of the concurrent processes. For each semaphore used, state the value for initialization
P1 P2 P3 P4 P5
sSig(A) sSig(A) sWait(A) sWait(A) sWait(A)
sSig(B) sSig(B) sWait(B)
sSig(C)

12. Give examples of reusable and consumable resources.


a. Reusable – nor deleted after a process has used it
b. Consumable – created and destroyed by the process
13. What are the three conditions that must be present for deadlock to be possible? What are the four
conditions that create deadlock?
a. Mutual Exclusion
b. Hold-and-wait
c. No preemption
d. Circular wait
14. How can the hold-and-wait condition be prevented?
a. A process requests all resources at one time
b. Blocking process until all requests can be granted
i. Problem: inefficient, process may not know all resources needed
15. List two ways in which the no-preemption condition can be prevented?
a. If a process holding certain resources is denied for a further request, that process must release its
original resources
b. If a process request s resource held by another process, OS may preempt the second process and
require it to release its resource
i. Only works when resource state can be saved and restored later
16. How can the circular wait condition be prevented?
a. Define a linear ordering of resource types
b. If a process has been allocated resources of type R, then it may subsequently request only those
resources of type following R in ordering
i. May be inefficient, slowing down processes and denying resources access unnecessarily
17. Current system state:
Claim Allocation Need Available
A B C A B C A B C A B C
P0 7 5 3 0 1 0 7 4 3 3 3 2
P1 3 2 2 2 0 0 1 2 2
P2 9 0 2 3 0 2 6 0 0
P3 2 2 2 2 1 1 0 1 1
P4 4 3 3 0 0 2 4 3 1

a. Is the current system state safe? If yes, what is the order for all processes to finish?
i. Safe: C(P1, P3) C(P0, P2, P4)
b. Assume the following request is issued by P1: (1, 0, 2)
Is the proposed system state safe? If yes, what is the order for all process to finish?
i. P1 Allocation: 3, 0, 2
ii. Available: 2, 3, 0
iii. Safe; C(P1, P3) C(P0, P2, P4)
c. Assume the following request is issued by P4: (3, 3, 0)
Should the request of P4 be granted or not?
i. Request is greater than available  must wait
d. Assume the following request is issued by P0: (0, 2, 0)
Is the proposed system state safe?
i. P0 Allocation: 0, 3, 0
ii. Available: 2, 1, 0
iii. Unsafe  deadlock
18. Consider the following snapshot of a system. There are no outstanding unsatisfied requests for
resources.
Process Current Allocation Maximum demand Still Needs Available
r1 r2 r3 r4 r1 r2 r3 r4 r r r r r r r r4
1 2 3 4 1 2 3
p1 0 0 1 2 0 0 1 2 0 0 0 0 2 1 0 0
p2 2 0 0 0 2 7 5 0 0 7 5 0
p3 0 0 3 4 6 6 5 6 6 6 2 2
p4 2 3 5 4 4 3 5 6 2 0 0 2
p5 0 3 3 2 0 6 5 2 0 3 2 0
a. Compute what each process still might request and display in the columns labeled “still needs”
b. Is this system currently in a safe or unsafe state? Why? Is this system currently deadlocked?
i. P1, p4, p5, p2, p3 Safe
ii. If processes are not run in this order, system will deadlock
c. If a request from P3 arrives for (0,1,0,0) can that request be safely granted immediately? In what
state (deadlock, safe, unsafe) would immediately granting that whole request leave the system?
Which processes, if any, are or may become deadlocked if this whole request is granted
immediately?
i. It could be run immediately
ii. Unsafe state
iii. P2 and p3 will be deadlocked
19. Apply the deadlock detection algorithm as below to the following data and show the results.
2 0 0 1 0 0 1 0
Request= 1 0 1 0 Allocation= 2 0 0 1 Available= 2 1 0 0
2 1 0 0 0 1 2 0

a. Deadlock Detection Algorithm:


i. Mark each process that has a row in the Allocation matrix of all zeros
1. none
ii. Initialize a temporary vector W to equal the Available vector.
iii. Find an index I such that process I is currently unmarked and ith row of Q is less than or
equal to W. That is Qik ≤Wk, for 1≤k≤m. If no such row is found, terminate the algorithm.
iv. If such a row is found, mark process I and add the corresponding row of the allocation
matrix to W. That is, set Wk = Wk + Aik, for 1≤k≤m. Return to step 3.
1. p2: W = [2, 1, 0, 0] + [0, 1, 2, 0] = [2, 2, 2, 0]
2. p1: W = [2, 2, 2, 0] + [2, 0, 0, 1] = [4, 2, 2, 1]
3. p0: W = [4, 2, 2, 1] + [0, 0, 1, 0] = [4, 2, 3, 1]
4. safe – no deadlock
20. Consider a system with a total of 150 unites of memory, allocated to three processes as shown:
Process Max Hold Need Available
1 70 45 25 150-45-40-15
2 60 40 20 50
3 60 15 45
4 60 25/35 35/25 25/15

Apply the banker’s algorithm to determine whether it would be safe to grant each of the following
requests. If yes, indicate a sequence of terminations that could be guaranteed possible. If no, show the
reduction of the resulting allocation table.
a. A fourth process arrives, with a maximum memory need of 60 and an initial need of 25 units.
i. Safe – start with either p1 or p2, then any combination
b. A fourth process arrives, with a maximum memory need of 60 and an initial need of 35 units.
i. All processes deadlocked
21. Consider a system consisting of four processes and a single resource. The current state of the claim and
allocation matrixes is:
C= (3, 2, 9, 7) A= (1, 1, 3, 2) N= (2, 1, 6, 5)
Available (1) = 3  unsafe (p2, p1) Available (3) = 7  safe

a. What is the minimum number of units of the resource needed to be available for this state to be
safe?
i. Min available = 3
ii. C(p0, p1) p3, p2
22. What is the difference among deadlock prevention, avoidance, and detection?
a. Prevention: adopting a policy to eliminate one of the conditions
i. Hold and wait – request all resources at one time (else block)
ii. No preemption – old processes release held resources
iii. Circular wait – only grant resources if preceding resources available
b. Avoidance: making appropriate dynamic choices based on the current state of resource allocation
i. Don’t start process / grant incremental resource request that might lead to deadlock
(Banker’s Algorithm)
c. Detection: detect deadlock and take action to recover
i. Deadlock detection algorithm (Safety algorithm)
1. abort all deadlocked processes (common)
2. back up deadlocked processes to previous check point
3. successively abort deadlocked processes until deadlock no longer exists (may not
solve)
4. Successively preempt resources until deadlock no longer exists (Dining
Philosopher’s)
23. In a fixed-partitioning scheme, what are the advantages of using unequal-size partitions? What is the
different between internal and external fragmentation?
a. Processes are assigned to minimize memory waste – large and small processes can be
accommodated with less internal fragmentation
b. Internal fragmentation: associated with fixed size partition unused memory from small processes
in large spaces
c. External fragmentation associated with dynamic partitioning unused memory between processes.
24. Suppose a fixed partitioning memory system with partitions of 100K, 500K, 200K, 300K, and 600K (in
memory order) exists. All five partitions are currently available.
a. Using the best fit algorithm, show the state of memory after processes of 212K, 417K, 112K, and
350K 9in request order) arrive.
[ 100K | 500K: p1(417K)  p3(350K) | 200K: p2(112K) | 300K: p0(212) | 600K ]
b. Using the best available algorithm, show the state of memory after processes of 212L, 417K,
112K, and 350K (in request order) arrive.
[ 100K | 500K: p1(417K) | 200K: p2(112K) | 300K: p0(212) | 600K: p3(350K) ]
c. At the end of part (a), how much internal fragmentation exists in this system?
i. (500-417) + (200-112) + (300-212) = 83 + 88 + 88 = 259
d. At the end of part (b), how much internal fragmentation exists in this system?
i. (500-417) + (200-112) + (300-212) + (600-350)= 83 + 88 + 88 + 250 = 259
25. A memory manager for a segmented system has a free list with blocks of size 600 bytes, 400 bytes, 1000
bytes, 2200 bytes, 1600 bytes, and 1050 bytes.
a. What block will be selected to serve a request for 1603 bytes under a best-fit policy?
i. 2200 bytes
b. What block will be selected to serve a request for 949 bytes under a best-fit policy?
i. 1000 bytes
c. Assume the free list is ordered as listed in the problem statement. What block will be selected by
serve a request for 1603 bytes under a first-fit policy?
i. 2200 bytes
d. Assume the free list is ordered as listed in the problem statement. What block will be selected to
serve a request for 1049 bytes under a first-fit policy?
i. 2200 bytes
26. A dynamic partitioning scheme is being used, and the following is the memory configuration at a given
point in time:
20* 20 40* 60 20* 10 60* 40 20* 30 40* 40
The shaded areas are allocated blocks; the white areas are free blocks. The next three memory requests are
for 40M, 20M, and 10M. Indicate the starting address for each of the three blocks using the indicated
placement algorithms:
a. First fit
i. P0: 40M at 80
ii. P1: 20M at 20
iii. P2: 10M at 120
b. Best-fit
i. P0: 40M at 230
ii. P1: 20M at 20
iii. P2: 10M at 160
c. Next fit, Assume the most recently added block is at the beginning of memory
i. P0: 40M at 80
ii. P1: 20M at 120
iii. P2: 10M at 160
27. What are the distinctions among logical, relative, and physical addresses? What is the difference
between a page and a frame? What is the difference between a page and a segment?
a. Logical – reference to a memory location independent of current assignment (need translation),
relative – location relative to some known point, physical – absolute address or actual location in
main memory
b. Pages – chunks of processes, frame – chunks of memory
c. Pages – same-sized and user as no control, segments – variable size and can be manipulated by
user
28. A 1Mbyte block of memory is allocated using the buddy system.
a. Show the results of the following sequence in a figure:
Init 1Mbyte
Request A for 70 KB A 128 256 KB 502 KB
Request B for 35 KB A B 64 256KB 502 KB
Request C for 80 KB A B 64 C 128 502 KB
Return A 128 B 64 C 128 502 KB
Request D for 60KB 128 B D C 128 502 KB
6 502 KB
Return B 128 D C 128
4
Return D 256 KB C 128 502 KB
Return C 1 MB

b. Show the binary tree representation following Return B:


(1MB)
(512 KB) (512 KB)
(256 KB) (256KB)
(128 KB) (128 KB) (C) (128KB)
(64KB) (D)
29. Consider a simple paging system with the following parameters: 232 bytes of physical memory; page size
of 210 bytes; 216 pages of logical address space.
a. How many bits are in a logical address?
i. 216 * 210 = 226  26 bits
b. How many bytes in a frame?
i. 210 bytes
c. How many bits in the physical address specify the frame?
i. 232 / 210 = 222  22 bits
d. How many entries in the page tables?
i. 216 entries
e. How many bits in each page table entry? Assume each page table entry includes a valid/invalid
bit.
i. 22 (frame) + 1 (invalid) = 23 bits
30. Consider the following segment table:
a. In what physical addresses do the following virtual addresses translate?
i. (0, 630) invalid – outside range (600)
ii. (1, 110) 2410 = 2300 + 110
iii. (2, 50) 140 = 90 + 50
iv. (3, 400) 1727 = 1327 + 400
v. (4, 112) 2064 = 1952 + 112
31. Explain thrashing. Why is the principle of locality crucial to the use of virtual memory? What is the
purpose of a translation lookaside buffer (TLB)?
a. Thrashing – swapping out a process just before the piece is needed, processor spends more time
swapping processes than executing
b. Possible to make intelligent guesses about which pieces will be needed in future make VM
efficient
c. TLB – cache for page table entries that have been most recently used
32. What elements are typically found in a page table entry? Brief define each element. Compare a
traditional page table with an inverted page table
a. Present bit, modify bit, other control bits, frame number
b. Traditional – 1 entry per page of virtual address space, inverted – 1 entry per page frame in real
memory
33. Consider a paged virtual memory system with 32-bit virtual addresses and 1 KB pages. Each page table
entry requires 32 bits. It is desired to limit the page table size to one page.
a. How many levels of page tables are required?
i. 3 levels
b. What is the number of entries of the page table at each level? Hint: One page table size is
smaller.
i. 28 * 28 * 26
c. The smaller page size could be used at the top level or the bottom level of the page table
hierarchy. Which strategy consumes the least number of pages?
i. Top level
34. Briefly define alternative fetch policies. What is accomplished by page buffering?
a. Demand paging – only pages into main memory when a reference is made to a location on the
page (multiple page fault at start of process)
b. Prepaging – brings more contiguous pages than needed (more efficient)
c. Page buffering – replaced page is added to free/modified page list page remains in memory. List
acts as cache of page modified pages are written out in clusters
35. Is it ever possible that FIFO will outperform LRU? If so, give a scenario. If not argue why. (Assume that
the number of pages allocated is the same)
a. When the item removed is referenced next but not in front of queue
36. Consider the following page reference string: 12342156212376321236. How many page faults occur for
the following page replacement algorithms, in a static allocation of 4 frames and assuming that the
allocation is initially empty? Assume pure demand fetch. Show the execution of identify page faults.
a. LRU (leave recently used) – replace oldest page
b. FIFO (First-in-first-out)
c. OPT (optimal) – replace page with longest wait time (time before referenced next)
d. Clock – replace non-modified entry, if all are modified, reset counter
FIFO OPT LRU Clock
1 1 1 1 1*
2 1 2 1 2 1 2 1* 2*
3 1 2 3 1 2 3 1 2 3 1* 2* 3*
4 1 2 3 4 1 2 3 4 1 2 3 4 1* 2* 3* 4*
2 1 2 3 4 1 2 3 4 1 3 4 2 1* 2* 3* 4*
1 1 2 3 4 1 2 3 4 3 4 2 1 1* 2* 3* 4*
5 2 3 4 5 1 2 3 5 4 2 1 5 5* 2 3 4
x x x x
6 3 4 5 6 1 2 3 6 2 1 5 6 5* 6* 3 4
x x x x
2 4 5 6 2 1 2 3 6 1 5 6 2 5* 6* 2* 4
x x
1 5 6 2 1 1 2 3 6 5 6 2 1 5* 6* 2* 1*x
x
2 5 6 2 1 1 2 3 6 5 6 1 2 5* 6* 2* 1*
3 6 2 1 3 1 2 3 6 6 1 2 3 3* 6 2 1
x x x
7 2 1 3 7 7 2 3 6 1 2 3 7 3* 7* 2 1
x x x x
6 1 3 7 6 7 2 3 6 2 3 7 6 3* 7* 6* 1
x x x
3 1 3 7 6 7 2 3 6 2 7 6 3 3* 7* 6* 1
2 3 7 6 2 7 2 3 6 7 6 3 2 3* 7* 6* 2*x
x
1 7 6 2 1 1 2 3 6 6 3 2 1 1* 7 6 2
x x x x
2 7 6 2 1 1 2 3 6 6 3 1 2 1* 7 6 2
3 6 2 1 3 1 2 3 6 6 1 2 3 1* 3* 6 2
x
6 6 2 1 3 1 2 3 6 1 2 3 6 1* 3* 6 2

37. What is the difference between a resident set and a working set? What is the difference between demand
cleaning and precleaning?
a. Resident set – portion of process within main memory
working set – set of pages that have been reference in the last virtual time unit
Resident set is larger, working set is a subset of resident set. Working set has been referenced
Working set is not a fixed number.
b. Demand cleaning – page is rewritten out when it is replaced
Precleaning – pages are written out in batches
38. Assume that one page reference needs one time unit. For a sequence of page references for a process as
below, complete the following table with working set for different window size.
Sequence of Window size
page references 3 4 5 6
24 24 24 24 24
15 24, 15 24, 15 24, 15 24, 15
18 24, 15, 18 24, 15, 18 24, 15, 18 24, 15, 18
23 15, 18, 23 24, 15, 18, 23 24, 15, 18, 23 24, 15, 18, 23
24 18, 23, 24 15, 18, 23, 24 24, 15, 18, 23 24, 15, 18, 23
17 23, 24, 17 18, 23, 24, 17 15, 18, 23, 24, 17 24, 15, 18, 23, 17
18 24, 17, 18 23, 24, 17, 18 18, 23, 24, 17 15, 18, 23, 24, 17
24 17, 18, 24 24, 17, 18 23, 24, 17, 18 18, 23, 24, 17
18 18, 24 17, 18, 24 24, 17, 18 23, 24, 17, 18
17 24, 18, 17 18, 24, 17 17, 18, 24 24, 17, 18
17 18, 17 24, 18, 17 18, 24, 17 17, 18, 24
15 17, 15 18, 17, 15 24, 18, 17, 15 18, 24, 17, 15

39.

Das könnte Ihnen auch gefallen