Ghulam Ishaq Khan Institute of Engineering Sciences and Technology - GIK Institute - GIKI CS311 (Fall 2023) Name & sign: Reg# Operating Systems (CS311) Final Examination (Fall 2023) Instructions: Calculators and cell phones are not allowed Paper written with led pencil will be marked zero Be specific. Do not write extra stuff Do not write anything on the question paper. Return by placing it inside your answer sheet. 5. Attempt all questions 1. 2. 3. 4. Read the instructions carefully! Instructor: Nazia Shahzadi Max Marks: 80 Time: 180 minutes Vetted by Name: Designation: Dean/HoD Signature: Signature: Section I Question No 1. Answer the Following: [Marks=2*5] a. When a thread is formed, what resources are utilized? In what ways are they different from the ones employed during the process creation phase? b. Suppose a parallel program is designed to run on five processors. The original computation workload is distributed as follows: 20% is assigned to processor 1, 25% is assigned to processor 2, 15% is assigned to processor 3, 20% is assigned to processor 4, and 20% is assigned to processor 5. Additionally, the parallel representation incurs a total overhead of 10% extra computations, distributed equally among all five processors. Neglecting all other overheads, calculate the speedup and efficiency. c. Consider a Linux application with two threads T1 and T2 that both share and access a common variable x. Thread T1 uses a Pthread mutex lock to protect its access to x. Now, if the thread T2 tries to write to x without locking, then the Linux kernel generates a trap. Share your reasoning - whether it's a 'True' and why, or 'False' and why. d. Suppose the number of threads in a process is N. Are the parameters sent to a program function by one thread visible to the other threads? Justify your response by providing an example. e. List three examples of deadlocks that are not related to a computer-system environment. NOTE: You are required to discuss real-time environments. Section II Question No.2 Given the following piece of code: main(int argc, char ** argv) { int child = fork(); int c = 5; if(child == 0) { c += 5; } else { [Marks=08] child = fork(); c += 10; if(child) c += 5; } } How many different copies of the variable “c” are there? What are their values? Demonstrate with a dry run. Question No.3 [Marks=07] Evaluate how effectively Peterson's solution resolves the issue of bounded waiting. For this solution, provide an exhaustive implementation code. Question No. 4 [Marks=10] Given the following binary semaphores and tasks: Specify the possible output messages that can be printed as the result of concurrent implementation of tasks A, B, and C. Question No. 5 [Marks=10] For each of the Resource Allocation Graphs (RAG) shown below, determine whether there is a deadlock or not. Justify your responses with explanations. (a) (b) (c) Question No. 6 (d) [Marks=10] Consider the following snapshot of a system: Answer the following questions using the banker’s algorithm: a) What is the content of the Need matrix? b) Is the system in a safe state? c) If a request from thread T1 arrives for (0,4,2,0), can the request be granted immediately? Question No. 6 [Marks=05] Deliberate the version of the dining-philosophers problem in which five chopsticks are placed at the center of the table and any two of them can be used by a philosopher. Assume that requests for chopsticks are made one at a time. Provide a simple programming rule for determining whether a particular request can be satisfied without causing deadlock given the current allocation of chopsticks to be philosophers. Question No. 7 [Marks=15] Think that there is a roller coaster ride at an amusement park. The operator runs the ride only when exactly N riders are on it. Multiple riders arrive at the ride and queue up at the entrance of the ride. The ride operator waits for N riders to accumulate, and may even take a nap as he waits. Once N riders have arrived, the riders call out to the operator indicating they are ready to go on the ride. The operator then opens the gate to the ride and signals exactly N riders to enter the ride. He then waits until these N riders enter the ride, and then proceeds to start the ride. We model the operator and riders as threads in a program. You must write pseudocode for the operator and rider threads to enable the behavior described above. Shown below is the skeleton code for the operator and rider threads. Complete the code to achieve the behavior described above. You can assume that the functions to open, start, and enter ride are implemented elsewhere, and these functions do what the names say they do. You must write the synchronization logic around these functions to invoke these functions at the appropriate times. You must use only locks and condition variables for synchronization in your solution. Question No. 8 [Marks=05] Suppose there is a computer system that runs 5,000 jobs per month and has no deadlockprevention or deadlock-avoidance scheme. Deadlocks occur about twice per month, and the operator must terminate and rerun about ten jobs per deadlock. Each job is worth about two dollars (in CPU time), and the jobs terminated tend to be about half done when they are aborted. A systems programmer has estimated that a deadlock-avoidance algorithm (like the banker’s algorithm) could be installed in the system with an increase of about 10 percent in the average execution time per job. Since the machine currently has 30 percent idle time, all 5,000 jobs per month could still be run, although turnaround time would increase by about 20 percent on average. a) What are the arguments for installing the deadlock-avoidance algorithm? b) What are the arguments against installing the deadlock-avoidance algorithm? Best of Luck