You are on page 1of 25
INTERNATIONAL UNIVERSITY - VIETNAM NATIONAL UNIVERSITY - HOCHIMINE CITY ‘MID-TERM EXAMINATION Date: 2016-11-09 ‘Duration: 120 minutes exon nome J Hu Mick Pleinaon ws TILTI VIB 08 Subject: Operating Systems Dean of School of Computer Science | Lecturer Asgoe. Prof. Tran Manh Ha, ‘Assoe, Prof. Tran Manh Ha GENERAL INSTRUCTIONS ‘© This is open book examination + Mobile phone and laptop are disallowed «Students write answers on this paper GRADING SUMMARY ‘Problem | Max: points | Ack points: ‘| 2 [ac 20 Yo 3 20 le ‘| [tu 5 Fa Ve Total 100 4 6 Do not forget to enter student's name and identification Problem 1: Multiple choice question (20 points) (Choose an answer by marking an appropriate box. You carn 2 points for each correct answer and “1 point foreach incorrect answer. The minimum murmber of points is 0 true o “ false Deadlock detection Grst chocks for e possible deadlock and then grants resources to request ‘The participation of processes or threads in mutual exclusion esnnot guarantee the existence of deadlock ‘A deadtock eaused by two processes waiting for each other on the blocking receive function involves consumable resources Forcing active provesses to return their resouroes increases the possiblity of causing ‘dondlocle ‘A race condition exists if concurrent threads or processes execute ‘without sharing data items dependently ‘The execution of the semaphore operations, such as seminit(), semvait(), sem.post(), does not permit interleaving ‘When one process alters local data items in memory, other processes can soe the changes ‘A deadlock prevention approach requires processes to release resources before re ‘questing further resources [A process cannot be ia a ready state if all ports of the process are not yet loaded into the main memory A child process becomes an orphan process before its parent process invokes the ‘walt system call to read is exit status Problem 2: Tiroad synchronization using semaphore (20 points) A.web crawler docs throe tasks in eoneurroney? the roteioval tack lo to collect and etore raw date from web pages into « bounded array of n blobs (assuming that one page for a blob), the analysis ‘task isto obtain the raw data from the blob array, extract and store key words from the raw data Into a bounded array of m strings (assuming that one key word fora string), the reasoning task is to get the key words from the string arcay for lasifcation. The retrieval ‘ask contains & threads to boost data collection, while the other tasks use one thread, with the following conditions: '* Only one thread uses the arrays at one time (i<., access the arrays, obtain and remove data stems). © The retrieval threads and the analysis thread cannot add data items if the arrays are ful ‘© The analysis throad and the reasoning thread cannot get data items ifthe arrays are empty. 4 The sizes of the arrays are 100, Provide poudo code for the web crawler usin sunapluores. The yeudo code mus contain semaphores for shared resources and functions dawnload rou) forgetting raw data from web pages, insert.rae() for storing eaw data into the blob aay, abt ro) forgetting raw data fom the bib array, x tracthud{) for extracting key words fom raw data, inserthud{) fr storing key words into the string auray, and obtain ud) getting key words fom the string ares, and classify Ju) for dividing key ‘work into categories. The function start. threads creates sultiple threads for simplification J+ vod crave “4 nde 0, ete sued lullern, Det, 220, 2s se ofbutter ™) ob int sizeothublera = = 400, sine ct hu Wie Wo; void retriovan jot h¢ while U) Shcaked wy) mVrit (ed) coward ingercl — caw 0; cemsignal (el) } sonsugnal (at); + void analysia( 14 wile U) seniveu' £ (4), cemait (si), obhuin - (uw oO; sonnel @, soon Sigal (a), ! wehad lewvel 0; suki (22), Sen War (2); Inger} = devel oO} saSignal (2) sinbignl (02); i y J void reasoning( while U) | sue. Wait (nd); senvlait (62, obtain — ne 3; eesignal Oy ( Sem Si 2) ont ld 0; | wnt aan Bartha) #61485 ‘seare_threals } seasoning Problem 3: Resource allocation (20 points) di: tag cc nance mT aoc tl mam Bit To paces neta bt Process Ps ultimately needs resource Ry, Rs and Re V Process P, ultimately needs resource Fey and Re mea Give an allocation order for the allocation graph and specify a circular wait Z assume one allocation on Ry is allocated fe 3 Be is allocated te Pe Ry is allocated & ty is alle cated to & Re is dlecated +o Fe ig allecated te Ry ws allocated fy 6B Ya dy is allocated Pe bg is allocated & % Bo iz allocated 4o Fe - needs thot will result in deadlock. Draw a resoure dor which will eeultin dead lock A, 2 vi 4, : 6, + §. 9 AD hie a the back-end page ~ the sesourte allecation yor oe mm Bs fey we fe 4S Rio ( l l (24 From the phe. eso a se walk lows! ‘ Se ooh 5 hye Ps ets > 05 > Re Phy 7hy may Pre ledhie-er meneevery Mt and fh p22 DE? er F Thebes , dhe civil ar wait causes a deadlock Le thas sate. fli the alow allocation eater, Problem 4: Deadlock avoidance (20 points) ‘A system uses the Banker's algorithm to avoid deadlocks. Suppose there are four processes and four resource types in the system. The maximum resource requirement matrix (C) and the current resource allocstion matrix (A) are given, as follows a42a 4002 aa12),_[o210 61id 3110 2527 2102 whore Ciy (1S i <4 and 1 j <4) denotes the maximum requirement of process i for resource 35 “Ayj denotes the number of units of resource j that are currently allocated to proatss i, The total ‘amount of each resource type in the aystem is given by the vector (16, 5, 2, 8|. Assume the systeun is currently in safe state, illustrate whether the granting of a request by process 4 for 1 unit of resource 2 would be granted by filing the necessary blank tables (C, 4, C— A, Rand V} TRE [RST RA RE [RE [RAT RA TE RET RSS Pi | 4 1 et | (Pe Pa Pa ¥ PL 1 i CPE PS Te] CV pepe ap es HEL SLE FTOLOlS| (a) Til state RELA TRS RT] REPRE LS Te dbl ST ZTE) AQ ATT f wP.cuns & complton A Coe ee) COV ese V crP2.cuns fo completion RI] Re [RS | y Pa ETE peEN Cvperpeperpas db x 725 2t..runs PP comp lef on. cer 6 Ti Si2zTs) Tet stare] “ Ro | RS | RA RET RS Merb wofleton Te RIP ROT RS Re RL{ R2| R8| RA i} soe: Sabie shade hence the ceguest of PY for Luni of cgewr2 Z can be qrented. Problem 5: Process tree (20 points) ‘The following C program contains the function eallséomato(), potato) wit the system eal fork). Asoue all te eallssuecond during the program's executional ervr banding code is omitzd for simplification. Draw a process toe to identify the anmber of processes ereated and indicate the output of this program, include inetd “untetd be static void tonato() { prints (*\n"); static void potato() { orn): toaato(); int aainGint arge, chart argv(l) { forkO; #: it fork) (AZ potato(); y else { tomato 5 onato() 5 return 0; ? Loc $4. Vv tod 6) #2 Arclag2 pete) eck () #3 frmatel) | toinated) Jrmato() tomato l) etetol) toma O forlil) #3 phenatol) trovedol) Jematol) tomate) “make Y ool) | frmmadel)| — From the process free wt have ideakbed 6 processes u Horner fhe dpe the ed 4s Fl poe is J2* peach ison anew hi ond: ut of pregeim * Do not forget to enter student's name and identification INTERNATIONAL UNIVERSITY - VIETNAM NATIONAL UNIVERSITY - HOCHIMINH CITY MID-TERM EXAMINATION Date: 2016-11-09 Duration: 120 minutes Student Name: PO Quast Twhh seodene mm ITITIUIHO90 Subject: Operating Systems Dean of School of Computer Selence | Lecturer & Engineering whi hab Assoc, Prof. Tran Manh Hs Asso, Prof. Tran Man Ha GENERAL INSTRUCTIONS This is open book examination ‘ Mobile phone and laptop are disallowed ‘+ Students write answers on this paper GRADING SUMMARY (Problem [Max points [Act points ) 1 20 » 2 20 3 20 4 20 5 20 Total 100 l Do not forget to enter student's name and identification

You might also like