Advertisements
Advertisements
प्रश्न
Explain context switching at process level in multiprogramming system with example.
स्पष्ट करा
Advertisements
उत्तर
- Multiprogramming is the concept of expanding the use of C.P.U. by always having something for it to do.
- In multiprogramming, the CPU can run two or more processes at the same time. When process 1 is waiting for an external event, such as an I/O operation, C.P.U. runs process 2, and vice versa.
- Context switching refers to the amount of time it takes for C.P.U. to switch from one process to another.

- Let A and B be the two processes that are ready for execution and require C.P.U. time to complete. Allow CPU time to be allocated to process A, which contains certain instructions that are dependent on process B or on an external event such as an I/O activity. The operating system is then responsible for halting the execution of process A and allocating C.P.U. time to process B. Context switching refers to the time it takes for C.P.U. to shift its attention from process A to B.
- During context switching, the status of C.P.U. registers and flags from the previous process remain in memory.
- For e.g.,
// A. CPP # include <iostream.h> # include "B.h" void main () { int a = 10, b = 20; cout << add (a,b); } // B.h # include <iostream.h> int add (int x, int y) { return (x+y); }
Here, A and B are the two processes, and A is dependent on B. When process A is executed, the CPU executes each instruction one by one. The instruction cout <<add (a,b); stops execution since its output is dependent on process B's output.
Thus, process B must be executed. As a result, C.P.U. stores the contents of process A's registers and flags in RSA (Register Save Area). It then places process B in memory. The time necessary for this is referred to as context switching. The CPU then conducts process B, and the output is provided to process A. A resumes from the instruction from which it was interrupted.
shaalaa.com
या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
2021-2022 (March) Set 1
