How Is Context Switching Done In Hardware?
Speaking very generally, the most common approach is to push the process state onto its own stack, and then switch stacks by updating the stack pointer to the value saved for the next process to be executed. After the process state is restored from this stack, everything &mdash; including the stack pointer itself &mdash; is restored to the values they had the last time this process was running.

The operating system maintains a table of data in which each entry represents a process in the system. In addition to storing the stack pointer for each process, it has flags indicating whether the process is active or suspended, what the process's priority is relative to other processes, and what sort of events can "wake up" a suspended process.