Search code examples
operating-systemschedulingcontext-switchcontext-switching

Does OS save memory values in context switch?


I have a question about which datas will be saved in context switching. I have searched but all links just talked about registers.

My question is does os also save the memory values of a process ?

Assume a process has defined an array starting from adress 0x80000 of Ram. When context switch occurs, what will happen to this array? Maybe the new process override 0x80000 adress in memory and when the old process continue it's working it losts the array!

Anyone can explain?


Solution

  • In general, an operating system does not save memory in a context switch. It just changes register values. The old process's memory just stays there until the system needs it. If that happens, the memory will be paged out.

    In the olde days of swapping, yes, the memory was frequently saved when a new process came in.