GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • OS Tutorial
  • Interview Questions
  • Quizzes
  • Notes
  • System Call
  • Paging
  • Virtual Memory
  • Deadlock Handling
  • DBMS
  • Computer Network
  • Digital Electronics
  • TOC
  • Operating System5 min read
  • Types7 min read

This view

  • Original page
  • New address

GeezerVison is showing www.geeksforgeeks.org — Difference between Swapping and Context Switching - GeeksforGeeks

geeksforgeeks
search icon
  • Courses
  • Tutorials
  • Interview Prep
  • OS Tutorial
  • Interview Questions
  • Quizzes
  • Notes
  • System Call
  • Paging
  • Virtual Memory
  • Deadlock Handling
  • DBMS
  • Computer Network
  • Digital Electronics
  • TOC

Difference between Swapping and Context Switching

Last Updated : 22 Nov, 2021

Programs are sets of instructions designed to accomplish specific tasks. Similarly, a process refers to a runtime instance of a computer program. During the execution of a program, several threads may be running in parallel. Single-threaded processes refer to the thread itself as the process.

1. Context switching :
An operating system uses this technique to switch a process between states to execute its functions through CPUs. It is a process of saving the context(state) of the old process(suspend) and loading it into the new process(resume). It occurs whenever the CPU switches between one process and another. Basically, the state of CPU's registers and program counter at any time represent a context. Here, the saved state of the currently executing process means to copy all live registers to PCB(Process Control Block). Moreover, after that, restore the state of the process to run or execute next, which means copying live registers' values from PCB to registers.
 



2. Swapping : 
This is the process by which a process is temporarily swapped (moved) from the main memory (RAM) to the secondary memory (Disk). The main memory is fast but has less space than secondary storage, so the inactive processes are moved to secondary memory, and the system swaps the memory from secondary to the main memory later. During swapping, most of the time is spent transferring information, and the amount of memory swapped is directly proportional to the total time. Swapping has been divided into two more concepts: Swap-in and Swap-out.

Swap-in is the process of removing a program from a hard disk and moving it back to the main memory or RAM.
Swap-out removes a program from RAM or main memory and moves or stores it to the hard disk or secondary storage.
 



Difference between Swapping and Context Switching :

Context switching

Swapping

It is a procedure for storing the state of an old process and loading it into a new process.Essentially, it is a method of replicating the entire process.
A context switch occurs when the kernel switches contexts when it transfers control of the CPU from one process to another already ready to run state.Swapping happens when the entire process is moved to the disk.
A context switch determines whether a process is in the pause mode.When it comes to Swapping, It deals with memory, how much memory is being swapped.
The context switch toggles the process from running to ready states, while the dispatcher is responsible for allocating CPU resources to processes present in the ready queue.It is an OS term that we use for referring to the exchange of data between the disk and the main memory.
Active processes do context switching. Inactive processes do swapping.
It offers a higher degree of multi-tasking.It provides a more significant degree of multiprogramming.
It helps to get better utilization of the operating system.It helps to get better utilization of memory.


 

Comment

Explore

    Basics
    • Operating System5 min read
    • Types7 min read
    • Kernel3 min read
    • System Call2 min read
    • Boot Process3 min read
    Process Management
    • Process Management3 min read
    • CPU Scheduling7 min read
    • Process Synchronization3 min read
    • Synchronization Problem Solutions4 min read
    • IPC Problems2 min read
    • Deadlock2 min read
    • Handling Deadlocks2 min read
    • Multithreading4 min read
    Memory Management
    • Memory & Memory Units2 min read
    • Memory Management4 min read
    • Buddy System5 min read
    • Overlays4 min read
    • Virtual Memory7 min read
    • Page Replacement Algorithms5 min read
    • OS based Virtualization5 min read
    I/O Management
    • File Systems4 min read
    • Directory Management3 min read
    • Secondary Memory7 min read
    • Disk Scheduling9 min read
    • Spooling vs Buffering1 min read
    Important Links
    • Notes15+ min read
    • Interview Questions15+ min read
    Courses
    • Placement 360 Course2 min read
    • GATE CS-IT & DA Courses2 min read
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.