Sei sulla pagina 1di 6

Assignment 2

Instructions: Please answer the following questions in complete sentences. (100 marks total) 1. Define short-term scheduler and long-term scheduler, and explain the main differences between them. (6 marks) Short-term/CPU scheduler determines which process, present in the ready queue, should be executed next. As it is invoked very often so it must be very fast. This scheduler sequentially looks into the pipeline and instantly takes up to execution what so ever the process has to be executed next in the line. Hence it has to be very fast and vigilant since it has to take up process from the waiting list instantly and provoke them for execution. The Long-term scheduler however works in a slightly different manner. Long-term scheduler is also called job scheduler and it decides which process should be fetched into the ready queue. It controls the degree of multiprogramming and can be very slow. This basically smartly caters for which process is at priority and should be executed, hence a search is to be continued which takes up more time than usual processing of Short-term scheduler. 2. Explain the concept of a context switch. (6 marks) Context switch can be defined as a process in which we save the state of a process and load the saved state of another process. The current state of a process right after execution or during the process of execution is to be saved in the process of context switch, meanwhile the already/previously saved state of another process is loaded in the same line of processing. This whole concept is basically taken into consideration for the implementation of multitasking. During switching time no work is done by the system and it depends on hardware support. The system only focuses on saving the state of one process and loading the saved state of another process, which now demands execution. A processs context is saved in the Program Control Block. The program block as we know is supposed to cater for the entire program flow hence this process and its controls reside within the program control block.

3. Explain the terms at most once and exactly once, and indicate how these terms relate to remote procedure calls. (6 marks) At most once is a term used when a server processes a clients certain message only once and not several times by checking timestamp of message. As in literal meaning the term indicates the same, irrespective of the timestamp of the message, the server proceeds with the message call once and only once. It does not cater for multiple procedure calls no matter what the circumstances are. As per the concept of remote procedure calls the application of the concept is just the same. The remote server processes the remote clients message only one time. On the contrary the exactly once term refers to the ensuring of message execution. Exactly once is term for ensuring that the message is executed once and only once. In the remote procedure calls the process is just the same, the exactly once process ensures the execution of messaging process has been done once and only once. 4. Identify and briefly explain each of the four major categories of benefits of multithreaded programming. (6 marks) Responsiveness: Multithreading increases responsiveness i.e. a program with multithreading will remain in the running state even if one of its part is blocked or is executing an extensive task. Resource sharing: The threads give the benefit of sharing code and data which allows an app to have a number of different active threads in the same address space. Economy: Memory and resource allocation is a costly task for a process being created. But threads share resources of the processes to which they belong, thus they are more cost-effective. Utilization of multiprocessor architectures: such architectures are utilized where threads can run, on different processors, in parallel.

5. Briefly describe the benefits and challenges for multithreaded programming that are presented by multicore systems. (8 marks) Multithreaded programming in multicore systems allows two or more process threads to execute concurrently, thus reducing overall time taken for process execution. In this form of

programming, the execution of multiple kinds of processes can be ensured. Basically schedulers are taken into consideration so as to ensure that the multiprogramming processes are working in a flow and smoothly. A major problem with this architecture is the DE multiplexing of the threads across the different processors that are available for execution. 6. Define coarse-grained multithreading and fine-grained multithreading, and explain their differences. (6 marks) In coarse-grained multithreading the processor switches to another thread if the current process causes a long inactive event, the purpose of multithreading processes is that multitasking can be ensured, however the whole purpose of multitasking renders ineffective if a process takes too much of time and switching between processes becomes difficult than the whole purpose renders inefficient. This is when the concept of coarse-grained multithreading can be taken into consideration; in this functionality the processor switches its focus to another thread if the current process causes a delay. While fine-grained multithreading, different threads get instructions issued by the process after each cycle. 7. Explain the process of starvation, and describe how aging can be used to prevent it. (6 marks) When a process is deprived of resources for a very long period of time due to allocation of resources to other processes then this problem is called starvation. In order to prevent starvation we use aging which increases a processs priority with time and highest priority process is allocated resources first. 8. How does the dispatcher determine the order of thread execution in Windows XP? (6 marks) In Windows XP, the dispatcher has priority scheme of level 32 for deciding the execution order of threads. A queue is used per scheduling priority and it is traversed from highest to lowest set of queues till a ready thread is found else idle thread will be executed. 9. Define critical section, and explain two general approaches for handling critical sections in operating systems. (8 marks) Critical section is the part of the code that cannot have more than one thread at a time accessing it. Two general approaches are usage of preemptive or non-preemptive kernels. A

preemptive kernel allows preemption while non-preemptive kernel will let the next process to run when the first process exits and is free from race conditions. 10. Describe the dining-philosophers problem, and explain how it relates to operating systems. (6 marks) The dining philosophers problem is problem that occurs when we five philosophers that think and eat. There is a table with five plates, one rice bowl in the middle and five chopsticks. No interaction is done by the philosophers. If all five of them get hungry, they will get one chopstick only leading to deadlock. In operating systems, philosophers are processes and chopsticks are resources. 11. Define the two-phase locking protocol. (6 marks) Two phase locking protocol provides serializability by making each transaction issue two phased lock and unlock requests. Locks may be obtained but not released during expanding phase and releasing is allowed in the shrinking phase. 12. Describe how an adaptive mutex functions. (6 marks) An adaptive mutex is a semaphore which is in a state of spinlock and is used to gain access to shared data. If data is being used, it is locked. If the locks thread is on another CPU then waiting thread spins while waiting for the lock to be released else it will sleep till the lock becomes available. 13. Describe a scenario in which the use of a reader-writer lock is more appropriate than using another synchronization tool, such as a semaphore. (6 marks) A semaphore allows shared data to be accessed by one process at a time. Suppose we have a process which is only reading shared data while other processes are also accessing it then as there are many readers so we should use reader-writer lock as it helps in identifying processes which are reading or writing or doing both.

14. What is the difference between deadlock prevention and deadlock avoidance? (6 marks) Deadlocks cause the system to go in a state where no processing remains possible and the whole system becomes dead and corrupted, this state can cause a lot of harm to resources, time and even data in many cases. Deadlocks need to be prevented and avoided. Deadlock prevention is the methods that ensure that deadlocks at least one necessary condition does not hold. Deadlock avoidance is the method in which operating system is informed with maximum information about each resource which will be used by a certain process. 15. Describe a wait-for graph, and explain how it detects deadlock. (6 marks) Deadlocks need to be avoided by all means, as these cause not only waste of time but also of resources, may even cause loss of data in multiple cases. Wait-for graph is deadlock detection algorithm, which uses a modified version of resource allocation graph i.e. by removing collapsing edges and resource nodes. This basically aims at the reallocation of resources, and the determination as to how the reallocation must proceed so as to ensure the avoiding of a deadlock by correctly reallocating the resources at their due places. Deadlocks cause the system to go in a state where no processing remains possible and the whole system becomes dead and corrupted, this state can cause a lot of harm to resources, time and even data in many cases. The wait-for graph should be maintained with an algorithm being invoked occasionally for the purpose of searching for loops in the graphs so that deadlocks can be detected. 16. Describe how a safe state ensures that deadlock will be avoided. (6 marks) Deadlocks need to be avoided by all means, as these cause not only waste of time but also of resources, may even cause loss of data in multiple cases. The solution to avoiding a deadlock is the implication of a safe state. Deadlock is impossible for a system if it is in a safe state because this state ensures that the processes do program execution in an orderly manner. Deadlocks cause the system to go in a state where no processing remains possible and the whole system becomes dead and corrupted, this state can cause a lot of harm to resources, time and even data in many cases. This orderly fashion enables the system to ensure program execution without going through a deadlock. But if the safe state is left then a deadlock is possible. So to ensure that the system stays in safe state is by allocating resources till the duration of safe state.

Potrebbero piacerti anche