Question

In: Computer Science

Context switching occurs when a task surrenders the CPU to another task or is preempted by...

Context switching occurs when a task surrenders the CPU to another task or
is preempted by another task. Use program examples (pseudo code plus Gantt
charts) to show a scenario for each of the cases.

Solutions

Expert Solution

The procedure of switching from one process to another process is called Context switching. A computer system consists of many tasks to be completed. If a task requires more time to be completed and a second task can be completed within that time then, the computer switches the ongoing process and jumps to the second task putting the first task on hold. After the completion of the second task, the first task resumes smoothly. This process is known as Context switching.

Pseudo Code for round robin algorithm :

1. CPU scheduler picks the process from the circular/ready queue , set a timer to interrupt it after 1 time slice / quantum and dispatches it .

2. If process has burst time less than 1 time slice/quantum

then Process will leave the CPU after the completion

CPU will proceed with the next process in the ready queue / circular queue .

3. else If process has burst time longer than 1 time slice/quantum

then Timer will be stopped . It cause interruption to the OS .

Executed process is then placed at the tail of the circular / ready querue by applying the context switch

CPU scheduler then proceeds by selecting the next process in the ready queue .

For example ,

Consider three processes P1, P2, P3

Burst time Waiting time Turnaround time

P1 24 6 30

P2 3 4 7

P3 3 7 10

Gantt chart for the round robin algorithm :

|-----------|-----------|----------|------------|------------|------------|------------|---------------|

| P1 |    P2 | P3 | P1    | P1   | P1 | P1 | P1   

|-----------|-----------|----------|------------|------------|------------|------------|---------------|

0 4 7 10 14   18 22 26 30


Related Solutions

1 In Linux, when a timer expires, there is a context switch so that the CPU...
1 In Linux, when a timer expires, there is a context switch so that the CPU scheduler can run. False True 2 The operating system keeps track of CPU usage for all processes. False True 3 A system call that does not invoke the CPU scheduler executes in the same context as the process that makes the call. False True 4 A ____ synchronizes access to memory from devices that want to access it. In UNIX, the system call to...
When is an external interrupt recognized by the CPU?  When more than one interrupt occurs, what approaches...
When is an external interrupt recognized by the CPU?  When more than one interrupt occurs, what approaches would you use to service them? What approaches should be taken when an interrupt occurs within an interrupt service routine Consider a hypothetical microprocessor having 64-bit instructions composed of two fields: the first 16-bits contains the op-code and the remainder the immediate operand or an operand address.  Assume memory is organized in 32-bit words, i.e. one r/w access can yield a maximum of 32 bits.  ...
uppose the following scenarios to discuss the impact effecting on the degree of multiprogrammingand context switching...
uppose the following scenarios to discuss the impact effecting on the degree of multiprogrammingand context switching time? Scenario1:all the processes in the ready queue are classified as I/O bound –process. Scenario 2:All the processes in the ready queue are classified as CPU bound –process. Scenario 3:Most of the processes in the ready queue are classified asmix of I/O bound –processes and CPU-bound processes
When is Cpk = Cpu = Cpl = Cp?
When is Cpk = Cpu = Cpl = Cp?
TASK A: In the context of the impact of a change on an organization, How would...
TASK A: In the context of the impact of a change on an organization, How would you characterize the following changes? Adding electronic scoreboards to a cricket grounds. A Telco consolidating call centres in one country. A Telco installing fibre-to-the-home to replace copper wires. A Telco launching a TV service. TASK B: Discuss the factors that may influence the decision to consider implementing an application software package, developing the solution in-house or outsourcing the development to an offshore company. TASK...
Examine the various exchange rate policies implemented by Turkey since 1980 in the context of expenditure-switching...
Examine the various exchange rate policies implemented by Turkey since 1980 in the context of expenditure-switching and expenditure- changing purposes. Give specific examples and indicate the years or periods. By using data, explain which policy was more effective for each period. Answer whether changes after the 2000s can be classified under a different category. In your response, make use of proper terminalogy, evidence, ratios, and theoratical background you learned during the course.
Examine the various exchange rate policies implemented by Turkey since 1980 in the context of expenditure-switching...
Examine the various exchange rate policies implemented by Turkey since 1980 in the context of expenditure-switching and expenditure- changing purposes. Give specific examples and indicate the years or periods. By using data, explain which policy was more effective for each period. Answer whether changes after the 2000s can be classified under a different category. In your response, make use of proper terminalogy, evidence, ratios, and theoratical background you learned during the course.
Though threads simplify sharing within a process, context-switching between threads within a process is just as...
Though threads simplify sharing within a process, context-switching between threads within a process is just as expensive as context-switching between processes.
Task 6 – CPU Architecture (20 marks) Please explain in your own words for each part...
Task 6 – CPU Architecture Please explain in your own words for each part of Question 6. Quote your references in your ―References‖ / ―Bibliography‖ (a) 1. For modern CPU architectures please explain what is true about this statement. “Why you cannot use CPU clock-speed only to compare computer performance.” Marks will be awarded for research and clear explanations into CPU concepts of threads, multi – threads, cores, relationship between cores and threads, multi- tasking and multi-processing. 2. Explain how...
Prove that if G is a context-free grammar in which every variable occurs on the left...
Prove that if G is a context-free grammar in which every variable occurs on the left side of at most one production, then G is unambiguous.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT