Running multiple processes on a single CPU
cpu, cpu-registers, operating-system, process
Solution
Concurrency in a single processor is only interrupting a proccess for some time, and letting another execute. Of course, each process have a different registers, including the one point to the stack position its current using - this information is called a context.
Whenever a proccess is entering the suspend mode, its context is saved in memory/stack. The processor then recovers (or creates) the context for the new proccess. When the first proccess is going to execute again, its context is recovered.
This context switch is done by either software (operational system) or hardware.
Problem
I wondered how can a single CPU, which I presume has one cpu stack and one registry set (there's only one instance for each register), run multiple processes concurrently? Does it change the stack and the registers every time it changes the process that it's currently running? For example process X has the value `0x03` in `EAX` but process Y has the value `0x02` on that register. So how does the CPU handles switching the values of the `EAX` register when it switches from executing instructions for the X process to executing instructions for the Y process? (Because each process works with the `EAX` it expected - the one that it stored in there before) I couldn't find information about this, though I'll accept answers linking to sources with related information. Sorry if the question is unclear, I tried to clarify it as much as possible, so please ask if anything is still unclear. Note: I don't mean threads, because as far as I think I understand, those use the same registers and the compiler builds the correct code so that they'll all work well together. (correct me if I'm wrong please!)