r/AskComputerScience • u/[deleted] • Oct 08 '19
How does a process know where it currently is in the code?
If I create a process and after a second suspend it. Where is the information stored about what current instruction it is at?
12
u/trevorsears Oct 08 '19
At a very very low level, it is common for a processor to have a PC (program counter) or IP (instruction pointer) register in which the address of the current instruction is stored.
https://en.wikipedia.org/wiki/Program_counter
Obviously if the process has been suspended the current instruction is no longer one belonging to said suspended process, but this seemed relevant :)
3
9
u/zacker150 Oct 08 '19
In an operating system, processes are represented by a data structure called a process control block (PCB). This data structure contains, among other things, called the program counter or instruction pointer which points to the current instruction. When the operating system switches from one process to another, it updates the data in the PCB of the outgoing process and loads the information from the PCB into the CPU registers.
0
16
u/NeoMarxismIsEvil Oct 08 '19
Not the best Wikipedia article but https://en.wikipedia.org/wiki/Context_switch#Steps
(What you’re looking for is the details of context switching.)