3
votes

In Operating Systems, what is the difference between "swapping" and "context switching"? The only difference I found in my textbook is that, in swapping there is a medium-term scheduler. Shed some light on it.

5
It is probably different depending on the speaker, but "swapping" refers to the memory of a process being taken out of main memory and placed on disk. It is a mechanism to provide a larger virtual memory on machines with small amounts of physical memory.William Pursell
Obviously, swapping with respect to memory is something totally different than context switching. However, colloquially you can say that the OS "swapped" vs. "context switched between" threads and they mean the same thing.Dan

5 Answers

1
votes
  • Swapping deals with memory ,how much memory is being swapped.
  • Context Switch deals with the Process ,either its state is pause or what so ever.

Practically they might be the same.

1
votes

Swapping is the term in OS generally used when we talk about exchange between main memory and disk. For example: A process currently running on a cpu needs some more pages stored in the disk. So, the swapper will swap out the pages of the other process(waiting,terminated..) pages from main memory into the disk while swapping in the required pages.

Context switch on the other hand switches the process from running state to ready state, while allocation of cpu to a process present in ready queue is done with the help of dispatcher.

Note: This is a simple example of context switch. The more is the complexity of an OS the more work is done during context switch.

0
votes

Swapping is saving the current computational state (when preempted or for some other reason) of a process from physical memory to secondary storage, normally HDD. and/or loading the current computational state of a process from HDD to physical memory.

When the OS allocates CPU from one process to another, it is required for computation to be meaningful that before the CPU switches from the currently running process to the other process the current computational state of the currently running process must be saved into a semi-permanent storage i.e. HDD so that the process when gets the CPU next time it can resume its execution from where it left. This operation requires some time say, t units. After the process state is saved, the state of the process which is to be allocate the CPU must be brought from HDD into physical memory. This also requires some time, p units. These t + p = z(say) is the context switch. Thus, context switch is acually the time require for swap-in and swap-out operation.

0
votes

Swapping : process memory being swapped to primary to secondary memory and vice versa. Context switch: process status is transferred to process control block PCB and the status of another program is loaded from PCB .

0
votes

swapping-waiting queue during the waiting stage of a process the process is removed from the RAM at some later time the process reintroduce into the main memory and its execution restarted from where it was stop this situation is Known as swapping