Here are some questions I probably didn’t use when I wrote the final version of exam 2 # Write a critical section solution using semaphores # Write a critical section solution using test-and-set # What is the difference between deadlock prevention and deadlock avoidance? # Consider the following system state: p0 p1 p2 p3 p4 allocation -----------0014 0012 1000 0632 1354 max -----0656 0012 1750 0652 2356 available -----------1520 show whether or not the system is safe (i.e. give the sequence of processes) # Name 3 places where adress binding might occur. # Consider a logical address space of 16 pages of 512 words each, mapped onto a physical memory of 64 frames. how many bits are there in the logical address? how many bits are there in the physical address? # What is the difference between external and internal fragmentation? Here are some review questions I found. I didn’t write them. I scanned them in. Sometimes The scanner didn’t figure it out. (Sorry) No, you aren’t necessarily responsible for the material covered by the review questions. No, I won’t fix what the scanner couldn’t read. And no, I didn’t look at the review questions before I wrote the exam. Review Questions 6.1 What is a critical section? Answer: A section of code that only one process at a time can be executing. 62 What is the critical-section problem? Answer: To design an algorithm that allows at most one process into the critical section at a time, without deadlock. 63 why have critical sections of programs, as defined by authors? Answer To allow no more than one process in at a time. 6.4 List the constraints Dijkstra placed on solutions to the critical-section problem. Answer: a. Simultaneous execution is equivalent to sequential execution in unknown order b. Speeds of the processes are independent of each othen c. A process in noncntical section can't prevent other processes from entering the critical sectionion. d. Selection of admitting one process into critical section can't be indefinitely postponed. 6.5 what three requirements must a solution to the critical-section problem satisfy? Answer Mutual exclusion, progress, bounded waiting. 6.6 What variable is common between the two processes in algorithm I? Answer turn. Note that i and j are not variables. C 6.7 what is wrong with algorithm 1? Answer: Since algorithm I requires strict alternation of processes in the execution of the critical section it does not satisfy the progress requirement6.8 What variable(s) is/are common between the two processes in algorithm 2? Answer: A two-element boolean flag array. 6.9 What is wrong with algorithm 2? How do you prove it? -Answer' Violates the progress rc4ttircmcnt (see page 16$). 6.~o t\ ¼~t ' ariables are used in algorithm 3, ;~-hich ace common to both processes? Answer A t"~o-eicmer~t hoolea p a rrav fL?y and sir,: .11 ''"2 '2 ~C(U C- a st--p.; '.6 A "V TV'An %'4 r H3\Ccutcd as a ~' V~u p. 5; p Qs~5; te \ t -'C tcht's ~*;%>tb Ic p it a Li or thc s taternen ts thc are completed l~,''spe -he ~'.ait-( postpone) opcrats';si. '¾'sis!(%L). Answer \\'hilc scn;aphore is n'~rnps~~stivc, ~va~'; "-hen semaphore becomes positive, suband e\tt. % ),'ttn.c the v~'aketsp operation ~ -\ n>-".cr: <\dd I to the $cn~a9hoR~' b. 14 >-t,-?--po.~c we ~-ant to c'-ccutc the >tatcsncnt> Si - $2, and 53 in sequence but that 52 has to be e'ccutcd e\clu5i'.el~' tot one pr~'t?¼¼ at a time~ \Yrite the code needed using semaphores. Answer: Assume (2 = 1 initiali\. SI; cs;iit ((2); 52; .;r,\'tsil(Q); 53. ( 6.15 Describe the Dining Philosophers problem. Answer: Five philosophers around a table can either eat or think; they share five cho~ sticks; but each needs two to eat. The problem is to design an algorithm so that there is no deadlork or starvation. 7.1 List types of resources we might consider in deadlock problems on computers. Answer: CPU ~ycles, memory space, files, I/o devices, tape drives, printers. 7.2 Define deadlock Answer: A situation where every process is waiting for an event that can be triggered only by another ptocess. 73 What are the four necessary conditions needed before deadlock can occur? Answer: a. At least one resource must be held in a nonsharable mode. b. A process holding at least one resource is waiting for more resources held by other processes. C. Resources cannot be preempted. d. There must be a circular waiting. 7.4 what is a system resource-aflocation graph (SRAG) in general? Answer A graph which shows the resources and processes, and the relationships among them. 7.5 How is a request indicated in a SRAC? Answer A line directed from the process to the resource box. 7.6 How is an allocation indicated in a SRAG? Answer A line from a resource in a box to the process. 7.7 TruelFalse: In an SRAG, if there are no cycles, then no deadlock exists. Answer: True. 7.8 True/False: In an SkAC. if there are cycles, then deadlock exists. Answer False; a deadlock niat, exist. 7.9 List three overall strategies ft' handling deadlocks. Answer a. Ensure system will never enter a deadlock state. B Allow deadlocks, but devise schemes to recover from them. C. Pretend deadlocks don't happen. 7.10 Give examples of sharable resources Answer Read-onfy files, sHared programs and librartes. 7.11 Give examples of nonsharable resources. Answer Printer, magnetic tape drive, update-files. card readers. 7.12 Can we break the first condition for deadlock to prevent deadlock? Answer: Usually not possible. But if done, vou may risk privacv and intc~ritv of v(~ur data 7.13 List two wavs we can break the second condition to prevent deadlock. Answer a. Process is allocated aH resources it needs before starting. b. Process receives resources only if it has none. 7.14 List two ways we can break the third condition to prevent deadlock. Answer: a. Requesting process is preempted of its current resources. b. Requesting process preempts resources from other processes. 7.15 What do authors mean by imposing a total ordering on the resources? Answer: Each resource is assigned a unique number such that esources needed typically by processes early are given low numbers, and resources needed later are given higher numbers. 7.16 List two ways we can break the fourth condition to prevent deadlock, using resource ordering. Answer a. Let processes request only resources with higher numbers. b. If a process request a resource, it must release resources that have lower numbers. 7.17 To avoid deadlock, what information do we need on the current processes? Answer Simplest scheme: each process declares the maximum number of resources it may need. 7.18 what is a safe state? Answer A set of resource allocations such that the system can allocate res~urces to each process (up to its max) in some order, and still avoid a deadlock. 7.19 what is a claim edge? Answer A dashed line from process to resource, indicatihg potential request of resource by the process. 7.20 List the data structures needed for the banker's algorithm. Answer • available vector A z?hitl&(m) • demand matrix ATz~(n rn) • allocation matrix A l~'(flt E)fl(n,m) • need matrix \ct S p 7.21 Summarl2e the banker ~lgorLthfl\. t\nswer: a. If request for proce~~ exceeds its need, error has occurred. b. If request of process exceeds available resources, process S must wait. (. ~ system tt'mpt)rarily allocates the resources process S "'ants: if the state is unsaft:, the a location is pQ%t poned. 7.22 Summarile the Safety Algorithm. t\nswer: a. hitialize vector Work to Anailable and set vector Finish to fake. 5. Find a process such that Finish(i) = fake and Need(r) leq Work. c. If found, add Aflocation(~ to Work(i), Finish(~ to true, and go to step b. d. If not found, continue here. U Finish(i) = true for all processes then state is safe, else it is unsafe. 7.23 How can we dete?trine whether current state is "safe" in systems with only one instance of each resource type? Answer: State is unsafe if any cycle exists. 7.24 What does a wait-for graph show? Answer Shows which process is waiting for other process(es). 7.25 How do you create a wait-for graph out of a resource-auocat;on graph? Answer Delete resource nodes, and connect the remaining lines, head of one to tail of line previously at same node. 7.26 What conditions must exist before a wait-for graph is useful in detecting deadlocks? Answer A cycle. 7.27 What does a cycle in a wait-for graph indicate? Answer A deadlock. 7;28 List three options for breaking an existing deadlock. Answer: a. Violate mutual exclusion, risking data. 5- Abort a process. C. Preempt resources of some process. 7.29 What three tssues must be considered in the case of preemption? Answer a. Sekct a victim to be preempted. b. Determine how far back to rollback the victim. C. Determine means for preventing that process from bemg '~starved.' 7.30 [.ist somc items tj~yol~cd u~ dtt(~rmintflg the cost c)f a mutmack. Answer 3. Prioritv b. r~e left to complete process C. ~ime already. e 'pended on process d. Number and tvpe of resources needed to remove d~adlcwk e. Number of process involved in the rollback 7.31 V~Vhat s starvation? Answer System is not deadlocked, but at least one process is indefinitely posyoned. 8.1 what is binding? Answer: Setting the actual addresses. used by each norrelocatable address of a program. 8.2 what are overlays? Answer: Segments or sets of routines, A, which are loaded into the same area of memory as other routines;- B; A and B are not in memory concurrently. but ore erases the other when loaded in. 81 What is the disadvantage of u5ing overlays? Answer: Programmer must carefully design the program and data structures so that the ovenays won't interfere with each othen 8.4 What is dynamic loading? Answer Loading a routine only when it is called and not y- memory; the routine will not be loa~cd into memon' until first time it is called. 8.5 What is the advantage of dynamic loading? Answer Routines that are never used are never loaded; thus more free memory. 8.6 What is a relocation register? Answer A base register used to give the lowest physical address for a process. 8.7 List two ways of fixing partitions into place. Answer a. Using upper/lower bounds registers for current executing process. b. Using a base register and a limit register. 8.8 List two ways to classify lobs by memory requirements. Answer a. User submits memory requirements along with job. b- System determines memory requiremer's 8.9 List eight ways of scheduling jobs. Answer a. Each queue separately. b. All abs in one ~ueuc, C. Keep memory regions from bQing idle. d. Place small CC in big r&gion, if that's the only one available. e. ~Vait for smail region to open up for a small lob. f. Allow swapping. g. High-priority jobs first. h. All(fl~' swapping b~ck into different re~ion than sw?pped out. 8.10 \Vhat is swapping? Answer Copying a process from memory to disk to allow space for other processes. 6' chapterS Memory Management .4--> 8.11 List ways of reducing the context switch tirne. Answer: a. Minimize the amount of memory of a process to b! swapped. b. Increase the speed of the disk used for swapped~ut processes. C. Overlap swapping and program execution. 8.12 List three ways of treating jobs which request too much memory, once started in a given partition. Answer a. Abort job with mn-time message. b. Return control to job; if it can't adjust to smaller memory, abort C. Swap lob out. 8.13 what is the system manager's main problem in using fixed partitions? Answer Deteaniniag the optimum number of partitions and their size. 8.14 List the common allocation methods. Which is the poorest? What was the rationale for even considering it? Answer a. First-fit. b. Best-fit. 4 c. Worst-fit - poorest. Assumes that most jobs are about same size-~ 8.15 What is internal fragmentation? Answer Wasted space within a partition. 8.16 what is external fragmentation? Answer Wasted space due to empty partitions being too small for current processes. 8.~7 What are variable partitions? Answei. Partitions that can be rnovcu in location and can te changed in number. 8.18 What is compaction? Whv use it? Answer: N¶ovement of processes to clim£nate small partitions. It allows smaller partitions to form fewer larger ones, to allc~'- larger pr(Kesses to run. 8.19 \~;hat s paging? .ns'wer: ?'pIitt~g prok-ra rr~ U p -i~ e ~ g.r~~tip mi ti~cd-equa}->ig.cd partitions, allo".ing the parts to be non-cofltiguoii~. 8.20 VYhat is a frame? Answer: Fi\.ed-si2e block of physical nemorv, each block of same size as page. 8-21 \Yhat is contair~.'d in the pa~e tabe? Answer: Base address or ea~;h Ira rnt~, ai~d &t~rresponding page number .22 lit'~~~ are the pat,'e Pu mber nod I et i~ ~i fl -tm~.-r> 'H a ned? Answer: [.ogical address i> ¾.plIt into t~y*' parts: right-hand bits give the offset nuinbcrs, and left-hand bits givt' the page number. Review Questions C 67 8.23 Describe the pag&t~frame translation. Answer: Logical address is split into page offset and page number. Scan page table for page number; corresponding entry is the frame number. which is combined with page offset to give physical adires5. 824 How many frames are needed for each page? Answer: One. 8.25 How much fragmentation occurs with paging? Which type? Answer: On the ~verage, on~half of last page in each lob; this is internal fragmentation. 8.26 In what order are the frames assigned? Answer: In the order of fi~ free-frame list. 827 List three ways of implementing the page table. Answea. Dedicated registers. b. In main memory. C. Associative registers (cache). 8.28 What is an associative register? Answer: A register in which pg search is needed to find a key; all parts are given a key at once; the part holding the key Is the only part to respond. 8.29 List advantages of paging. Answer a. Sharing common code. b. Reducing fragmentation. 8.30 Wbat are page protection bits? Answer Flag bits associated with each page to flag read/write or read-only. 8.31 What is reentrant code? Answer Code that can be used bv several users simultaneously. It has no code that users cnn alter during execution, 8.32 How was memory mapping used in extending the usefulness of minicomputers? Answer: Allowed increased memory space without changLng the instniction set. 8.33 What I does the operating systen~ use to keep track of fran~e alicscations? Answer; Frame table 8.34 What is segmentation? Answer Breaking program up into its logical segments, and allocating space for these into memor;, . xrm3ents mav be of var not serments >.eparatelv. The Sc able length. and need be I l&~'ated contigtlou>-l\,'. 8.35 ~\'~''' Answer: th.' k'"~~~ .~j'tress stoace? l~hv~ic I acid ross space? a. Collect ion ot cymen t> or page>; en h segment has a name and length, and is nurnbored, Each page is numbered, and has same length as any other, but is not named.