Important Announcement
PubHTML5 Scheduled Server Maintenance on (GMT) Sunday, June 26th, 2:00 am - 8:00 am.
PubHTML5 site will be inoperative during the times indicated!

Home Explore TM298-Final-By ISA-1st Edition

TM298-Final-By ISA-1st Edition

Published by falkupisi, 2022-12-26 08:30:12

Description: TM298-Final-By ISA-1st Edition

Search

Read the Text Version

‫تجميعات اَّلمتحان النهائي‬ ‫‪Fatimah‬‬ ‫‪TM298 - Final‬‬ ‫‪R.J‬‬ ‫بسم الله الرحمن الرحيم‬ ‫‪TM298‬‬ ‫ِحلف الطلاب العصاميين يقدم لكم النسخة الأولى من تجميعات الامتحانات النهائية محلول ًة بالكامل‪.‬‬ ‫الشكر ُمسدى لكل من ص َحح وتع َّقب وراجع النسخ‪ ،‬و َمن جمع الملفات على مر السنين‪.‬‬ ‫نرجو ألا تكون هذه التجميعات محل اعتمادكم في المذاكرة‪ ،‬فشرائح ال ُمقرر أولى وأكثر أهمية‪.‬‬ ‫يغلب على النماذج تكرار الأفكار الأسئلة‪ ،‬لذا ننصح بالرجوع إليها والاهتمام بها‬ ‫فَلَ ْي َس يَ ْجنِي ِث َما َر ا ْلفَ ْو ِز يَا ِنعَةً ِم ْن َجنَّ ِة ا ْل ِع ْل ِم إِّ ََّل َصا ِد ُق ا ْل ِه َم ِم‬ ‫حرر في‪:‬‬ ‫‪15/5/1444 – 9/12/2022‬‬

PART 1 Multiple Choice Questions (10 marks) Answer the following MCQ by selecting the best answer for each question. Write your answer letter in the answer sheet [1 mark for each point]. 1. Which of the following is a property of peer-to-peer systems? A) Clients and servers are not distinguished from one another. B) Separate machines act as either the client of the server but not both. C) They do not offer any advantages over traditional client-server systems. D) They suffer from the server acting as the bottleneck in performance. 2. A is an example of a systems program. A) Command interpreter B) Web browser C) Text formatter D) Database system 3. A process control block A) includes information on the process's state B) stores the address of the next instruction to be processed by a different process C) determines which process is to be executed next D) is an example of a process queue 4. Which of the following would be an acceptable signal-handling scheme for a multithreaded program? A) Deliver the signal to the thread to which the signal applies. B) Deliver the signal to every thread in the process. C) Deliver the signal to only certain threads in the process. D) All of the above

5. The____ scheduling algorithm is designed especially for time-sharing systems. A) SJF B) FCFS C) RR D) Multilevel queue 6. An instruction that executes atomically _. A) must consist of only one machine instruction B) Executes as a single, uninterruptible unit C) cannot be used to solve the critical section problem D) All of the above 7. One necessary condition for deadlock is___, which states that at least one resource must be held in a non-sharable mode. A) hold and wait B) mutual exclusion C) circular wait D) no preemption 8. Mandatory Access Controls (MAC) impose A) Global security access for all users B) Global security access for all groups C) Access to root D) None of above 9. The mapping of a logical address to a physical address is done in hardware by the A) memory-management-unit (MMU) B) Memory address register C) Relocation register D) Dynamic loading register.

10. The vfork() system callin UNIX __. A) Allows the child process to use the address space of the parent B) Uses copy-on-write with the fork () call C) Is not intended to be used when the child process calls exec () immediately after creation D) Duplicates all pages that are modified by the child process. PART 2 Short problems/questions, each question worth 6 marks (30 marks) 1. What is a bootstrap program, and where is it stored? A bootstrap program is an initial program that the computer runs when it is powered up or rebooted. It initializes all aspects of the system, from CPU registers to device controllers to memory contents. Typically, it is stored in read-only memory (ROM) or electrically erasable Programmable read-only memory (EEPROM), known by the general term firmware, within the computer hardware (Chapter 2) 2. What role do device controllers and device drivers play in a computer system? ) ‫ المقرر لم يكن كافي لشرح هذا الجزء‬, Google ‫( هذه الإجابة من‬ A general-purpose computer system consists of CPUs and multiple device controllers that are connected through a common bus. Each device controller is in charge of a specific type of device. The device controller is responsible for moving the data between the peripheral devices that it controls and its local buffer storage. Typically, operating systems have a device driver for each device controller. This device driver understands the device controller and presents a uniform interface for the device to the rest of the operating system. 3. There are two different ways that commands can be processed by a command interpreter. One way is to allow the command interpreter to contain the code needed to execute the command. The other way is to implement the commands through system programs. Compare and contrast the two approaches. In the first approach, upon the user issuing a command, the interpreter jumps to the appropriate section of code, executes the command, and returns control back to the user. In the second approach, the interpreter loads the appropriate program into memory along with the appropriate arguments. The advantage of the first method is speed and overall simplicity. The disadvantage to this technique is that new commands require rewriting the interpreter program which, after a number of modifications, may get complicated, messy, or too large. The advantage of the second method is that new commands can be added without altering the command interpreter. The disadvantage is reduced speed and the clumsiness of passing parameters from the interpreter to the system program.

4. Describe the relationship between an API, the system-call interface, and the operating system. The system-call interface of a programming language serves as a link to system calls made available by the operating system. This interface intercepts function calls in the API and invokes the necessary system call within the operating system. Thus, most of the details of the operating the system interface is hidden from the programmer by the API and is managed by the run-time support library. 5. Ordinarily the exec () system call follows the fork (). Explain what would happen if a programmer were to inadvertently place the call to exec () before the call to fork(). Because exec () overwrites the process, we would never reach the call to fork()and hence, no new processes would be created. Rather, the program specified in the parameter to exec () would be run instead. (Chapter 3) PART 3 Problem Solving Questions, each question worth 5 marks (10 marks) Q1. 1) Describe the algorithm FCFS for scheduling [1.5 mark] First Come First Serve (FCFS) is an operating system scheduling algorithm that automatically executes queued requests and processes in order of their arrival. It is the easiest and simplest CPU scheduling algorithm. In this type of algorithm, processes which request the CPU first get the CPU allocation first. This is managed with a FIFO queue. The full form of FCFS is First Come First Serve. 2) Suppose that the processes arrive in the order: of ������1, ������2, ������3, and the burst time illustrate in the following table. Using FCFS Process Burst Time ������������ 3 ������������ 6 ������������ 3 a) Draw the Gantt chart [1 mark] b) Calculate the waiting time for ������1, ������2, ������3 [1.5 mark] c) Calculate the average waiting time. [1 mark]

a) Gantt chart: ������������ ������������ ������������ 12 03 9 b) The waiting time for ������1 = 0 , ������2 = 3 , ������3 = 9 c) The average waiting time = 0+3+9 = 4 3 Q2. Write a script to determine whether a given file exists or not, the file name is supplied as a command line argument, and also check for a sufficient number of command line arguments. The Script: #!/bin/bash if [ $# -ne 1 ] then echo \"Usage - $0 file-name\" exit 1 fi if [ -f $1 ] then echo \"$1 file exist\" else echo \"The $1 file does not exist\" fi The Online IDE: https://www.onlinegdb.com/online_bash_shell

PART 1 Multiple Choice Questions (10 marks) Answer the following MCQ by selecting the best answer for each question. Write your answer letter in the answer sheet [1 mark for each point]. 1. Which of the following is a property of peer-to-peer systems? A) Clients and servers are not distinguished from one another. B) Separate machines act as either the client of the server but not both. C) They do not offer any advantages over traditional client-server systems. D) They suffer from the server acting as the bottleneck in performance. 2. A is an example of a systems program. A) Command interpreter B) Web browser C) Text formatter D) Database system 3. A process control block A) includes information on the process's state B) stores the address of the next instruction to be processed by a different process C) determines which process is to be executed next D) is an example of a process queue. 4. Which of the following would be an acceptable signal-handling scheme for a multithreaded program? A) Deliver the signal to the thread to which the signal applies. B) Deliver the signal to every thread in the process. C) Deliver the signal to only certain threads in the process. D) All of the above

5. The____ scheduling algorithm is designed especially for time-sharing systems. A) SJF B) FCFS C) RR D) Multilevel queue 6. An instruction that executes atomically _. A) must consist of only one machine instruction B) Executes as a single, uninterruptible unit C) cannot be used to solve the critical section problem D) All of the above 7. One necessary condition for deadlock is___, which states that at least one resource must be held in a non-sharable mode. A) hold and wait B) mutual exclusion C) circular wait D) no preemption 8. Mandatory Access Controls (MAC) impose A) Global security access for all users B) Global security access for all groups C) Access to root D) None of above 9. The mapping of a logical address to a physical address is done in hardware by the A) memory-management-unit (MMU) B) Memory address register C) Relocation register D) Dynamic loading register.

10. The vfork() system callin UNIX __. A) Allows the child process to use the address space of the parent B) Uses copy-on-write with the fork () call C) Is not intended to be used when the child process calls exec () immediately after creation D) Duplicates all pages that are modified by the child process. PART 2 Short problems/questions (30 marks) Q1. Describe three general methods used to pass parameters to the operating system during system calls, [3 marks] 1. Pass parameters in registers. 2. Registers pass starting addresses of blocks of parameters. 3. Parameters can be placed, or pushed, onto the stack by the program, and popped off the stack by the operating system. Q2. Explain the main differences between a short-term and long-term scheduler. [5 marks] ) ‫ المنهج لم يكن كافي لشرح هذا الجزء‬, Google ‫( هذه الإجابة من‬ The short-term scheduler is also referred to as a CPU Scheduler. The short-term scheduler's main job is to choose a process from the Ready Queue that is ready to run and assign the processor to it. In comparison to the long-term scheduler, short-term Scheduler execution is frequent. It has less control over the Multiprogramming Degree. In the Time-Sharing System, the short-term scheduler is the minimum available. Long term scheduler is also referred the job scheduler. Various processes are waiting for execution on a computer. These processes are waiting in the job queue. The long-term schedulers choose a job from the job queue or system memory and bring that job to the ready queue to execute in the main memory. Generally, the long-term scheduler chooses a balanced mix of processor-bound and input/output-bound processes from the secondary memory. Moreover, the multiprogramming degree is defined as the maximum number of processes in the ready state. It also helps to manage the multiprogramming degree. Main differences between the long-term scheduler and short-term scheduler: 1. A long-term scheduler is an operating system scheduler that chooses processes from the job queue and loads them to execution in the main memory. On the other hand, a short-term scheduler is an operating system scheduler that chooses the process from the several processes that the processor runs.

2. The long-term scheduler chooses the processes or jobs from the job pool. In contrast, the short-term scheduler chooses the processes from the ready queue. 3. The long-term scheduler controls the multiprogramming degree. In contrast, the short-term scheduler has less control over multiprogramming. 4. The long-term scheduler assigns the job to the ready queue for further action by the short- term scheduler, which is referred to as a job scheduler. In contrast, the short-term scheduler assigns the task to the CPU for its process; therefore, it is also called a CPU Scheduler. 5. The short-term scheduler chooses processes from the ready queue more frequently than the long-term scheduler chooses processes from the job pool. 6. The long-term scheduler is slower than the short-term scheduler. Q3. List the four major categories of the benefits of multithreaded programming. Briefly explain each. [5 marks] 1. Responsiveness – may allow continued execution if part of process is blocked, especially important for user interfaces 2. Resource Sharing – threads share resources of process, easier than shared memory or message passing 3. Economy – cheaper than process creation, thread switching lower overhead than context switching 4. Scalability – process can take advantage of multicore architectures (Chapter 4) Q5. What three conditions must be satisfied in order to solve the critical section problem? [3 marks] 1. Mutual Exclusion - If process Pi is executing in its critical section, then no other processes can be executing in their critical sections. 2. Progress - If no process is executing in its critical section and there exist some processes that wish to enter their critical section, then the selection of the processes that will enter the critical section next cannot be postponed indefinitely. 3. Bounded Waiting - A bound must exist on the number of times that other processes are allowed to enter their critical sections after a process has made a request to enter its critical section and before that request is granted - Assume that each process executes at a nonzero speed - No assumption concerning the relative speed of the n processes ( Chapter 6 )

Q6. What are the three general ways that a deadlock can be handled? [3 marks] 1. Ensure that the system will never enter a deadlock state: - Deadlock prevention - Deadlock avoidance 2. Allow the system to enter a deadlock state and then recover 3. Ignore the problem and pretend that deadlocks never occur in the system. ( Chapter 8) Q7. When does external fragmentation occur? [3 marks] When there’s a sufficient quantity of area within the memory to satisfy the memory request of a method. Q8. Explain the sequence of events that happens when a page fault occurs. [5 marks] 1. Operating system looks at another table to decide: – Invalid reference  abort – Just not in memory 2. Find free frame 3. Swap page into frame via scheduled disk operation. 4. Reset tables to indicate page now in memory Set validation bit = v 5. Restart the instruction that caused the page fault (Chapter 10)

PART 3 Problem Solving Questions, each question worth 5 marks (10 marks) Q1. Consider a logical address space of 64 pages of 1024 words each, mapped onto a physical memory of 32 frames. a. How many bits are there in the logical address? b. How many bits are there in the physical address? Q2. Suppose that the following processes arrive for execution at the times indicated. Each process will run for the amount of time listed. In answering the questions, use non-preemptive scheduling, and base all decisions on the information you have at the time the decision must be made. Process Arrival Time Burst Time ������������ 0.0 8 ������������ 0.4 4 ������������ 1.0 1 a.What is the average turnaround time for these processes with the FCFS scheduling algorithm? b. What is the average turnaround time for these processes with the SJF scheduling algorithm? c. The SJF algorithm is supposed to improve performance, but notice that we choose to run process P1 at time 0 because we did not know that two shorter processes would arrive soon. Compute what the average turnaround time will be if the CPU is left idle for the first 1 unit and then SJF scheduling is used. Remember that processes ������1 and ������2 are waiting during this idle time, so their waiting time may increase. This algorithm could be known as future-knowledge scheduling.

Q1 – Answer a) Logical address =16 bits (1024 × 64 = 65,536 → 216) b) Physical address =15 ������������������������ (1024 × 32 = 32,768 → 215) Q2 – Answer a) Gantt chart: ������������ ������������ ������������ 8 12 13 0 Process Turnaround Time = Finishing time – arrival time ������������ 8 - 0.0 = 8 ������������ ������������ 12 – 0.4 = 11.6 13 – 1.0 = 12 Average turnaround time 8 + 11.6+12 = 31.6 = 10.53 33 a) Gantt chart: ������������ ������������ ������������ 89 13 0 Process Turnaround Time = Finishing time – arrival time ������������ 8 - 0.0 = 8 ������������ ������������ 13 – 0.4 = 12.6 9 – 1.0 = 8 Average turnaround time 8 + 12.6+8 = 28.6 = 9.53 33

PART 1 Multiple Choice Questions (10 marks) Answer the following MCQ by selecting the best answer for each question. Write your answer letter in the answer sheet [1 mark for each point]. 1. ___ is the number of processes that are completed per time unit. A) CPU utilization B) Response time C) Turnaround time D) Throughput 2. ____ scheduling is approximated by predicting the next CPU burst with an exponential average of the measured lengths of previous CPU bursts. A) Multilevel queue B) RR CG) FCFS D) SJF 3. A semaphore __. A) is necessarily an integer variable B) is accessed through only one standard operation C) can be modified simultaneously by multiple threads D) cannot be used to control access to a thread's critical sections 4. A solution to the critical section problem does not have to satisfy which of the following requirements? A) mutual exclusion B) progress C) atomicity D) bounded waiting

5. One necessary condition for deadlock is___, which states that at least one resource must be held in a non-sharable mode. A) hold and wait B) mutual exclusion C) circular wait D) no preemption 6. One necessary condition for deadlock is ____ , which states that a process must be holding one resource and waiting to acquire additional resources. A) hold and wait B) mutual exclusion C) circular wait D) None of the above 7. The absolute code can be generated for A) compile-time binding B) load-time binding C) execution-time binding D) interrupt binding 8. is the method of binding instructions and data to memory performed by most general-purpose operating systems. A) Interrupt binding B) Compile-time binding C) Execution time binding D) Load-time binding

9. An address generated by a CPU is referred to as a__. A) physical address B) logical address C) post-relocation register address D) Memory-Management Unit (MMU) generated address 10. The mapping of a logical address to a physical address is done in hardware by the A) memory-management-unit (MMU) B) memory address register C) relocation register D) dynamic loading register. PART 2 Short problems/questions (30 marks) 1. What must three conditions be satisfied to solve the critical section problem? a. Mutual Exclusion - If process Pi is executing in its critical section, then no other processes can be executing in their critical sections. b. Progress - If no process is executing in its critical section and there exist some processes that wish to enter their critical section, then the selection of the processes that will enter the critical section next cannot be postponed indefinitely. c. Bounded Waiting - A bound must exist on the number of times that other processes are allowed to enter their critical sections after a process has made a request to enter its critical section and before that request is granted - Assume that each process executes at a nonzero speed - No assumption concerning the relative speed of the n processes ( Chapter 6 ) 2. Explain two general approaches to handling critical sections in operating systems. 1. Preemptive – allows preemption of the process when running in kernel mode 2. Non-preemptive – runs until exits kernel mode, blocks, or voluntarily yields CPU  Essentially free of race conditions in kernel mode

3. Describe the four conditions that must hold simultaneously in a system if a deadlock Is to Occur. 1. Mutual exclusion: only one process at a time can use a resource 2. Hold and wait: a process holding at least one resource is waiting to acquire additional resources held by other processes 3. No preemption: a resource can be released only voluntarily by the process holding it, after that process has completed its task 4. Circular wait: there exists a set {P0, P1, …, Pn} of waiting processes such that P0 is waiting for a resource that is held by P1, P1 is waiting for a resource that is held by P2, …, Pn–1 is waiting for a resource that is held by Pn, and Pn is waiting for a resource that is held by P0. 4. When does external fragmentation occur? When there’s a sufficient quantity of area within the memory to satisfy the memory request of a method. 5. Distinguish between internal and external fragmentation. External Fragmentation – total memory space exists to satisfy a request, but it is not contiguous. Internal Fragmentation – allocated memory may be slightly larger than requested memory; this size difference is memory internal to a partition, but not being used. PART 3 Problem Solving Questions, each question worth 5 marks (10 marks) Q1. Suppose that the processes arrive in the order: ������2, ������3, ������1 the burst time illustrate in a) Draw the Gantt chart [0.5 mark] b) Calculate the waiting time for������2, ������3, ������1 [0.5 mark] c) Calculate the average waiting time for������2, ������3, ������1 [0.5 mark] a) Which will be the best in waiting time the order of ������2, ������3, ������1 or ������1, ������2, ������3 and explain your answer. [3.5 mark] Process Burst Time ������������ 3 ������������ 3 ������������ 3

Q1 – Answer a) Gantt chart: ������������ ������������ ������������ 6 9 03 3 b) Waiting time for P2 = 0; P3 = 3; P1 = 6 c) Average waiting time: 0+3+6 = 3 3 d) Both of them have the same waiting time, because all processes have same burst time which is 3.

Q2. Write a script to print a given number in reverse order, for, eg. If a number is 123, it must print as 321. The Script: #!/bin/bash if [ $# -ne 1 ] then echo \"Usage: $0 number\" echo \" I will find reverse of given number\" echo \" For eg. $0 123, I will print 321\" exit 1 fi n=$1 reverse=0 sd=0 while [ $n -gt 0 ] do sd=`expr $n % 10` reverse=`expr $reverse \\* 10 + $sd` n=`expr $n / 10` done echo \"The Reverse number is $reverse\" The Output: The Online IDE: https://www.onlinegdb.com/online_bash_shell

PART I/Short essay questions Solve only any ten (10) out of the following twelve (12) questions, eachquestion is worth 2 marks. 1) What is critical section in the context of process synchronization? It is the segment of code that a Process is about changing shared variables, updating table, and writing file. 2) List the different types of semaphores implementation and explain one of them. Counting semaphore – integer value can range over an unrestricted domain Binary semaphore – integer value can range only between 0 and 1 3) Many systems provide hardware support for implementing the critical sectioncode, list three of them. 1. Memory barriers 2. Hardware instructions 3. Atomic variables 4) What is Deadlock in the context of process execution? Deadlock – two or more processes are waiting indefinitely for an event that can be caused by only one of the waiting processes. 5) Explain “No preemption” in the context of the OS scheduling algorithm? A resource can be released only voluntarily by the process holding it after that process has completed its task. 6) Who deadlock prevention can be implemented? Invalidate one of the four necessary conditions for deadlock: - Mutual exclusion - Hold and wait - No preemption - Circular wait 7) Address binding of instructions and data to memory addresses can happen atthree different stages, list all of them and explain only one Compile time: If memory location knew a priori, absolute code can be generated; must recompile code if starting location changes. Load time: Must generate relocatable code if memory location is not known at compile time. Execution time: Binding is delayed until run time if the process can be moved during its execution from one memory segment to another.

8) The concept of a logical address space that is bound to a separate physical address space is central to proper memory management, what is the differentbetween them? Logical address – generated by the CPU; also referred to as virtual address Physical address – address seen by the memory unit. 9) List the different memory fragmentation types and explain one of them. External Fragmentation – total memory space exists to satisfy a request, but it is not contiguous. Internal Fragmentation – allocated memory may be slightly larger than requested memory; this size difference is memory internal to a partition, but not being used. 10) List at least three of the Security Violation Categories and explain one of them ( ‫)الإجابة من نموذج تم حله مسب ًقأ – غير موجودة بالمقرر‬ - Breach of confidentiality Unauthorized reading of data - Breach of integrity Unauthorized modification of data - Breach of availability Unauthorized destruction of data - Theft of service Unauthorized use of resources - Denial of service (DOS) Prevention of legitimate use 11) Trojan Horse is one of the program threats, explain it. (‫)الإجابة من نموذج تم حله مسب ًقأ – غير موجودة بالمقرر‬ Code segment that misuses its environment Exploits mechanisms for allowing programs written by users to be executed by other users Spyware, pop-up browser windows, covert channels 12)What is the Fundamental idea behind virtualizations? ) ‫( الإجابة من نموذج تم حله مسب ًقأ – غير موجودة بالمقرر‬ Abstract hardware of a single computer into several different execution environments.

PART 2 Short problems/questions Q1. Assume having three processes T1, T2, and T3 and the following resources [10marks] - One instance of R1 - Two instances of R2 - One instance of R3 - Three instances ofR4 And below is the relation between the resources and the processes: - T1 holds one instance of R2 and is waiting for an instance of R1 - T2 holds one instance of R1, one instance of R2, and is waiting for an instance of R3 - T3 holds one instance of R3 T1 R2 R1 T2 R4 R3 T3 - The graph contains no cycle, and hence no deadlock.

Q2. We consider a system with ten magnetic tape drives and three processes: P0, P1, and P2. Process P0 requires eight tape drives, process P1 may need as many as three tape drives, and process P2 may need up to nine tape drives. Suppose that, at time t0, process P0 is holding four tape drives, process P1 is holding two tape drives, and processP2 is holding two tape drives. (Thus, there are two free tape drives.) [10 marks] Process Number Maximum Needs Current Needs P0 8 4 P1 3 2 P2 9 2 The table provides the state of the system at t0, you are asked to check if the system can bein safe state or not, by justifying your answer. At time t0, the system is in a safe state. The sequence < P1, P0, P2 > satisfies the safety conditions. Process P1 can immediately be allocated all its tape drives and then return them (the system will then have four available tape drive); then process P0 can get all its tape drives and return them (the system will then have eight available tape drives); and finally process P2 can get all its tape drives and return them (the system will then have all ten tape drives available). Q3. Assuming that the memory page size is 2,048 bytes and we have a process size of 72,766 bytes that will be loaded into this memory, you are asked to calculate the internalmemory fragmentation in bytes [5 marks]. Needs 35 pages (722,0,74686 ≈ 35.530) + 1,086 bytes to satisfy process size (35×2,048 = 71,680 then 72,766 − 71,680 = 1,086) Internal fragmentation of (one extra page) = 2,048 − 1,086 = 962 bytes.

Q4. Write a shell script “sum.sh” that takes an unspecified number of command line arguments of integers and finds their sum. First check if there is any argument supplied on the command line, if not show an appropriate message [5 marks]. The Script: #!/bin/bash if [ $# -le 0 ]; then echo \"Please provide numbers to find their sum\" exit 0 fi sum=0 for i in $@; do sum=$((sum + i)) done echo \"Sum of $@ is: $sum\" exit 1 The Output Sample:

PART I Solve only any ten (10) out of the following twelve (12) questions, each question is worth 2 marks. 1) Explain briefly Mutual Exclusion in the context of process synchronization? If process Pi is executing in its critical section, then no other processes can be executing in their critical sections 2) Introduce briefly the role of semaphores in the context of process synchronization? Synchronization tool that provides more sophisticated ways (than Mutex locks) for process to synchronize their activities 3) List the different types of semaphores implementation and explain one of them. Counting semaphore – integer value can range over an unrestricted domain Binary semaphore – integer value can range only between 0 and 1 4) What does it mean “Hold and wait” in the context of process execution? A process holding at least one resource is waiting to acquire additional resources held by other processes 5) How can we censure that a process can access only access those addresses in its address space? We can provide this protection by using a pair of base and limit registers define the logical address space of a process. 6) Explain when address binding can take place at compile time. If memory location known a priori, absolute code can be generated. 7) Dynamic program loading is applied in special situation, what is? (‫) الإجابة من نموذج تم حله مسب ًقأ – غير موجودة بالمقرر‬ The entire program does need to be in memory to execute Routine is not loaded until it is called 8) In case a Resource-Allocation graph contains a cycle, what does this mean? If only one instance per resource type, then deadlock. If several instances per resource type, possibility of deadlock

9) What for device drivers are used? (‫)الإجابة من نموذج تم حله مسب ًقأ – غير موجودة بالمقرر‬ Device drivers encapsulate device details Present uniform device-access interface to I/O subsystem 10) A virtual environment is usually composed of the three parts, list all of them and explain only one. Host – underlying hardware system Virtual machine manager (VMM) or hypervisor – creates and runs virtual machines by providing interface that is identical to the host (Except in the case of paravirtualization) Guest – process provided with virtual copy of the host Usually, an operating system 11) Port scanning is one of the System and Network Threats, explain it )‫)الإجابة من نموذج تم حله مسبقًأ – غير موجودة بالمقرر‬ Automated attempt to connect to a range of ports on one or a range of IP addresses Detection of answering service protocol Detection of OS and version running on system 12) Denial of Service is one of the System and Network Threats, explain it. )‫)الإجابة من نموذج تم حله مسبقًأ – غير موجودة بالمقرر‬ Overload the targeted computer preventing it from doing any useful work Distributed Denial-of-Service (DDoS) come from multiple sites at once

PART II You are asked to solve all questions. Q1) Assume having three processes P1, P2 and P3 and the following resources [10 marks]: - Two instances of R1 - Two instances of R2 And below is the relation between the resources and the processes: - P1 holds one instance of R2 and is waiting for an instance of R1 - P2 holds one instance of R1 and is waiting for an instance of R2 - P3 does not need any resources You are asked to sketch the resource graph allocational and to state whether it containsdeadlock or not, by justifying your response. P1 R2 R1 P2 P3 The rule: If graph contains a cycle and there are several instances per resource type, there is a possibility of deadlock Here, the graph contains a cycle (P1 → R1 → P2 → R2 → P1), and no deadlock.

Q2. We consider a system with ten (10) magnetic tape drives and three processes: P0, P1, andP2. Process P0 requires eight tape drives, process P1 may need as many as three tape drives, and process P2 may need up to nine tape drives. Suppose that, at time t0, process P0 is holding four tape drives, process P1 is holding two tape drives, and process P2 is holding two tape drives. [10 marks]. Process Number Maximum Needs Current Needs P0 8 4 P1 3 2 P2 9 2 The table provides the state of the system at t0, assuming that at t1, p2 acquired one more tape, revise the safety of system, and provide justification for your answer. Process Number Maximum Needs Current Needs P0 8 4 P1 3 2 P2 9 3 At time t1, the system is in not in safe state. Even the sequence <P1, P0, P2> doesn’t satisfy the safety conditions. At this point, process P1 can immediately be allocated all its tape drives and then return them (the system will then have three available tape drive); then process P0 can’t be allocated all its tape drives because there is only three available tape and P0 needs four. This will be resulting in a deadlock. Q3. Assuming that the memory page size is 2,048 bytes and we have a process size of 73,820bytes that will be loaded into this memory. Calculate the internal memory fragmentation in bytes [5 marks]. Needs 36 pages (723,,084280 ≈ 36.0449) + 92 bytes to satisfy process size (36×2,048 = 73,728 then 73,820 - 73,728 = 92) Internal fragmentation of (one extra page) = 2,048 − 92 = 1,956 bytes.

Q4. Write a shell script “average.sh” that takes an unspecified number of command line arguments of integers and finds their average. First check if there are more than two arguments supplied on the command line, if not show an appropriate message [5 marks]. The Script: #!/bin/bash if [ $# -le 2 ]; then echo \"Please provide at least three numbers to find their average\" exit 0 fi sum=0 for i in $@; do sum=$((sum + i)) done avg=$(( $sum / $# )) echo \"Average of $@ is: $avg\" exit 1 The Output Samples :

PART 1 Solve only any ten (10) out of the following twelve (12) questions, each question isworth 2 marks. 1) Explain briefly Mutual Exclusion in the context of process synchronization?  If process Pi is executing in its critical section, then no other processes can be executing in their critical sections  It is a program object that prevents simultaneous access to a shared resource. This concept is used in concurrent programming with a critical section, a piece of code in which processes or threads access a shared resource. 2) How does Linux deal internal with process and threads?  Linux refers to them as tasks rather than threads  Thread creation is done through clone() system call  clone() allows a child task to share the address space of the parent task (process)  Flags control behavior 3) Introduce briefly the role of semaphores in the context of process synchronization?  Synchronization tool that provides more sophisticated ways (than Mutex locks) for process to synchronize their activities  Semaphore S – integer variable  Can only be accessed via two indivisible (atomic) operations  Must guarantee that no two processes can execute the wait() and signal() on the same semaphore at the same time  Thus, the implementation becomes the critical section problem where the wait and signal code are placed in the critical section

4) What can you tell about the Unix management of the process creation? The basic principle of UNIX process management is to separate two operations: the creation of a process and the running of a new program.  fork() system call creates new process  exec() system call used after a fork() to replace the process’ memory space with a new program  Parent process calls wait() for the child to terminate 5) List the different types of semaphores implementation and explain one ofthem. Counting semaphore – integer value can range over an unrestricted domain Binary semaphore – integer value can range only between 0 and 1 6) What can you tell about Linux kernel license distribution?  Free Software Foundation (FSF), which has “copyleft” GNU Public License (GPL)  Free software and open-source software are two different ideas championed by different groups of people 7) What does it mean “Hold and wait” in the context of process execution?  a process holding at least one resource is waiting to acquire additional resources held by other processes  It is one of 4 conditions of deadlock 8) There are three challenges in Designing of Distributed Systems, list all of themand explain briefly one of them. Collection of separate, possibly heterogeneous, systems networked together. 1. Heterogeneity The Internet enables users to access services and run applications over a heterogeneous collection of computers and networks. 2. Scalability the capability of a system to adapt to increased service load. Systems have bounded resources and can become completely saturated under increased load. 3. Concurrency

Both services and applications provide resources that can be shared by clients in a distributed system. There is therefore a possibility that several clients will attempt to access a shared resource at the same time. 9) A thread in a windows system can be one of eight states, list all of them. (‫ – غير موجودة بالمقرر‬Google ‫(الإجابة من‬ 1. Ready 2. Running 3. Waiting 4. Delayed 5. Blocked 6. Transition 7. Terminated 8. Initialized 10) What is meant by TCP is connection-oriented protocol?  It requires a logical connection to be established between the two processes before data is exchanged.  Examples of services the use connection-oriented transport services are telnet , ftp . 11) What is meant by UDP is unreliable protocol?  UDP does not provide error correction and is therefore an unreliable protocol.  In other words, delivery of packets is not guaranteed. UDP datagrams are transmitted without provision for an acknowledgment. Because there is no virtual connection between sender and receiver, UDP is also said to be connectionless. 12) In case a Resource-Allocation graph contains a cycle, what does this mean? If graph contains a cycle ->  if only one instance per resource type, then deadlock  if several instances per resource type, possibility of deadlock

PART ll There are five (5) questions, each is six (6) marks worth, you are asked to solve allquestions (total of 30 marks). Q1) Draw the different thread states (six states) of JAVA thread include the transition from one state to another: Q2) Draw a diagram that shows the different OSI model layers and the corresponding TCP/IP protocol stack layer.

Q3) assume having four processes P1, P2, P3 and P4 and the following resources: - One instance of R1 - One instances of R2 - One instance of R3 And below is the relation between the resources and the processes: - P1 holds one instance of R2 and is waiting for an instance of R1 - P2 holds one instance of R3, and is waiting for an instance of R2 - P3 waiting for an instance of from R1 and R3 - P4 holds one instance of R3 You are asked to sketch the resource graph allocational and to state whether it contains deadlock or not, by justifying your response. P1 R2 R1 P2 P3 R3 P4 - The graph contains no cycle, and hence no deadlock

Q4) We consider a system with nine (9) hard drives and four processes: P0, P1, P2 and P3. Process P0 requires seven hard drives, process P1 may need as many as three tape drives, and process P2 may need up to seven tape drives. P3 may need two hard drives. At time t0, process P0 is holding four hard drives, process P1 is holding one tape drive, process P2 is holding two tape drives and process P3 is holding only one hard drive (thus, only one free hard drive.) Process Number Maximum Needs Current Needs P0 P1 7 4 P2 3 1 P3 7 2 2 1 The table provides the state of the system at t0, you are asked to check if the systemcan be in safe state or not, by justifying your answer. At time t0, the system is in a safe state. The sequence <P3, P1, P0, P2> satisfies the safety conditions. Process P3 can immediately be allocated all its hard drives and then return them (the system will then have two available hard drive); then process P1 can get all its hard drives and return them (the system will then have three available hard drives); then process P0 can get all its hard drives and return them (the system will then have seven available hard drives); and finally process P2 can get all its hard drives and return them (the system will then have all nine hard drives available).

Q5( Write a shell script “sum.sh” that takes an unspecified number of command line arguments of integers and finds their summation. First check if there are more than two arguments supplied on the command line, if not show an appropriate message. The Script: #!/bin/bash if [ $# -le 2 ]; then echo \"Please provide at least three numbers to find their sum\" exit 0 fi sum=0 for i in $@; do sum=$((sum + i)) done echo \"Sum of $@ is: $sum\" exit 1 The Output Samples: The Online IDE: https://www.onlinegdb.com/online_bash_shell

PART 1 [6 marks] Choose the correct answer for each of the following: 1. The two separate modes of operating in a system are a) Physical mode and logical mode d) Kernel mode and privileged mode b) Supervisor mode and system mode e) None of the above c) User mode and kernel mode f) All of the above 2. In Linux, to add execute permission to the file \"FinalExam\" use the command a) $chmod +x FinalExam d( $chmod a+w FinalExam b) $chmod o+r FinalExam e) None of the above c) $chmod a-x FinalExam f) All of the above 3. What is the correct order of operations for protecting a critical section using mutex locks? a) signal() followed by wait() d) acquire() followed by release() b) wait() followed by signal() e) None of the above c) release() followed by acquire() f) All of the above 4. _____is the number of processes that are completed per time unit. a) Turnaround time d) Response time b) CPU utilization e) None of the above c) Throughput f) All of the above

PART 2 [44 marks] Answer the following questions: a) Discuss three sets of operating system services. (6 marks) 1. User interface - Almost all operating systems have a user interface (UI).  Varies between Command-Line (CLI), Graphics User Interface (GUI), touch-screen, Batch 2. Program execution - The system must be able to load a program into memory and to run that program, end execution, either normally or abnormally (indicating error) 3. I/O operations - A running program may require I/O, which may involve a file or an I/O device 4. File-system manipulation - The file system is of particular interest. Programs need to read and write files and directories, create and delete them, search them, list file Information, permission management. 5. Communications – Processes may exchange information, on the same computer or between computers over a network  Communications may be via shared memory or through message passing (packets moved by the OS) 6. Error detection – OS needs to be constantly aware of possible errors  May occur in the CPU and memory hardware, in I/O devices, in user program  For each type of error, OS should take the appropriate action to ensure correct and consistent computing  Debugging facilities can greatly enhance the user’s and programmer’s abilities to efficiently use the system 7. Resource allocation - When multiple users or multiple jobs running concurrently, resources must be allocated to each of them  Many types of resources - CPU cycles, main memory, file storage, I/O devices. 8. Logging - To keep track of which users use how much and what kinds of computer resources 9. Protection and security - The owners of information stored in a multiuser or networked computer system may want to control use of that information, concurrent processes should not interfere with each other

 Protection involves ensuring that all access to system resources is controlled  Security of the system from outsiders requires user authentication, extends to defending external I/O devices from invalid access attempts b) Deadlock can arise if four conditions hold simultaneously. Explain them, (8 marks)  Mutual exclusion: only one process at a time can use a resource  Hold and wait: a process holding at least one resource is waiting to acquire additional resources held by other processes  No preemption: a resource can be released only voluntarily by the process holding it, after that process has completed its task  Circular wait: there exists a set {P0, P1, …, Pn} of waiting processes such that P0 is waiting for a resource that is held by P1, P1 is waiting for a resource that is held by P2, …, Pn–1 is waiting for a resource that is held by Pn, and Pn is waiting for a resource that is held by P0. Question 2: (10 marks) As a process executes, it changes its state. Draw a diagram that shows the process states and how it is transmitted among them.

Question 3: (10 marks) Based on Chapter 9, consider the following memory partitions of 300 KB, 200 KB, 600 KB, 200 and 400 KB (in order), and processes of 90 KB, 250 KB, 600 KB, and 250 KB (in order) Memory Partition Process a) How would each of the first-fit, best-fit and worst-fit algorithms place 300 the above processes in the given memory partitions. Use the below 200 representation of the memory partitions and fill it for every algorithm. 600 200 b) Which algorithm makes the most efficient use of memory? (1 marks) 400 a) First-fit: Memory Partition Process 300 90 200 600 250 200 400 250 Process 600 KB has no partitions so it will wait Best-fit: Memory Partition Process 300 250 200 90 600 600 200 400 250 Worst-fit: Process 250 Memory Partition 300 90 200 600 250 200 400 Process 600 KB has no partitions so it will wait b) Best fit is the best

Question 4: Calculate the effective access time in milliseconds for a demanding page system, where Memory access time is 190 nanoseconds, the average page-fault service time is 10 milliseconds and the page fault is 2/1000. (Show full steps of calculations) Average page-fault service time = 10 ms x 1000 000 = 107 nanoseconds Effective Access Time (EAT) = (1 – p) x memory access + p (page fault overhead + swap page out + swap page in) Effective access time = (1-0.002) x 190 + 0.002 x 107 = 189.62 + 20 000 = 20,189.62 nanoseconds = 0.02018962 milliseconds = 0.02 milliseconds

PART 1 [6 marks] Choose the correct answer for each of the following: 1. _____is copying information into faster storage system. a) Partitioning c) Caching b) Scheduling d) Booting 2. ______is any mechanism for controlling access of processes or users to resources defined by the OS. a) Swapping c) Security b) Fragmentation d) Protection 3. The _____ occurs in first-come-first-served scheduling when a process with a long CPU burst occupies the CPU a) Convoy effect c) Starvation b) Aging d) Turnaround Time 4. A ____ is generated by the CPU. a) Physical addressA c) Memory-Management Unit (MMU) generated address b) Soft Address d) Logical address

5. Given the following piece of shell script, one of the following statements is incorrect regarding the code read selection if [ $selection -eq 1 ]; then echo \"Host machine name is $HOSTNAME\" elif [ $selection -eq 2 ]; then echo \"SO\" elif [ $selection -eq 3 ]; then pwd else echo \"Invalid selection.\" fi a) The else part is executed only if none of the previous conditions is true b) Pwd command will display current working directly. c) The nested if should be ended by \"done\". d) $0 stores the name of the bash script. 6. In Linux, to add execute permission to the file \"TMA\" use the command a) $chmod o+r TMA c) Schmod a-x TMA b) $chmod +x TMA d) $chmod a+w TMA

PART 2 [18 marks] Answer the following questions: Question 1: [5 marks] Describe the three general methods for passing parameters to the operating system and write disadvantages and advantages of each one (if any).  Simplest: pass the parameters in registers - In some cases, may be more parameters than registers  Parameters stored in a block, or table, in memory, and address of block passed as a parameter in a register - This approach taken by Linux and Solaris  Parameters placed, or pushed, onto the stack by the program and popped off the stack by the operating system  Block and stack methods do not limit the number or length of parameters being passed Question 2: [5 marks] Describe the five states that a process go through while execution.  New: The process is being created  Running: Instructions are being executed  Waiting: The process is waiting for some event to occur  Ready: The process is waiting to be assigned to a processor

 Terminated: The process has finished execution Question 3: [4 marks] Explain the three forms of Synchronization Hardware by giving brief definition for each. 1. Memory barriers: is an instruction that forces any change in memory to be propagated (made visible) to all other processors. 2. Hardware instructions: Special hardware instructions that allow us to either test-and-modify the content of a word, or two swap the contents of two words atomically (uninterruptibly.). Test-and-Set instruction. Compare-and-Swap instruction. 3. Atomic variables: provides atomic (uninterruptible) updates on basic data types such as integers and Booleans. Question 4: [4 marks] Describe four challenges of designing operating systems for mobile devices compared with designing operating systems for traditional PCs (‫ – غير موجودة بالمقرر‬Google ‫(الإجابة من‬  Less storage capacity: means the operating system must manage memory carefully.  Less processing power plus fewer processors: mean the operating system must carefully apportion  The operating system must also manage power consumption carefully.  Inability for user to upgrade hardware or components in order to speed up the device.

PART 3 [26 marks] Answer the following questions: Question 1: [6 marks] Draw a multithreaded process with three threads and show the shared and unshared components between the threads and the parent process. Question 2: [8 marks] Assume having three processes P1, P2 and P3 and the following resources: - Two instances of R1 - Three instances of R2 - One instances of R3 And below is the relation between the resources and the processes: - P1 holds one instance of R1 and R4 and waiting for an instance of R3. - P2 holds one instance of R2 and R3 and waiting for an instance of R1 - P3 holds one instance of R1 and waiting for an instance of R3. Draw a resource graph allocation and find whether it contains deadlock or not and justify your answer.

R1 R2 P2 P3 P1 R4 R3 The rule: If graph contains a cycle and there are several instances per resource type, there is a possibility of deadlock Here, the graph contains many cycles (P1 → R3 → P2 → R1 → P1) (P2 → R1 → P3 → R3 → P2) , There is a deadlock. Question 3: [6 marks] Limit 200 Consider the following segment table: 90 Segment Base 150 0 220 300 1 600 2 900 3 1100 What are the physical addresses for the following logical addresses? (Show the calculations)

a) 0,66 b) 2,160 c) 3,240 a) 66 < 200  66 + 220 = 286 b) 160 not < 150 illegal reference, trap to operating system c) 240 < 300  240 + 1100 = 1340 Question 4: [6 marks] Calculate the effective access time in milliseconds for a demanding page system, where Memory access time is 180 nanoseconds, the average page-fault service time is 7 milliseconds and the page fault is 1/1000. (Show full steps of calculations) Average page-fault service time = 7 ms x 1000 000 = 7000000 nanoseconds Effective Access Time (EAT) = (1 – p) x memory access + p (page fault overhead + swap page out + swap page in) Effective access time = (1-0.001) x 180 + 0.001 x 7000000 = 179.82 + 7000 = 7179.82 nanoseconds = 0.00717982 milliseconds (convert from ns to ms= ns * 10-6) =0.007 milliseconds

Part 1: Choose the correct answer for each of the following: [6 marks] 1. The ____ of a process contains temporary data such as function parameters, return addresses, and local variables. a) Program counter c) Data section b) Text section d) Stack 2. In Linux, the following command will: $touch FinalExam a) Edit file FinalExam c) Create file FinalExam b) Display contents of file FinalExam d) Create directory FinalExam 3. What is the correct order of operations for protecting a critical section using a binary semaphore? a) wait() followed by signal() c) release() followed by acquire() b) signal() followed by wait() d) acquire() followed by release() 4. A significant problem with priority scheduling algorithms is ____. a) Complexity b) Starvation c) Determining the length of the next cpu burst d) Determining the length of the time quantum

Part 2: Answer the following questions: [44 marks] Question 1: [15 marks] a The operating system is responsible for activities in connection with process management. Write four of these activities. (8 marks)  Creating and deleting both user and system processes  Suspending and resuming processes  Providing mechanisms for process synchronization  Providing mechanisms for process communication  Providing mechanisms for deadlock handling b Explain the difference between Data Parallelism and Task Parallelism, then draw diagrams that illustrates them. (7 marks)  Data parallelism – distributes subsets of the same data across multiple cores, same operation on each  Task parallelism – distributing threads across cores, each thread performing unique operation


Like this book? You can publish your book online for free in a few minutes!
Create your own flipbook