In the right pane, use the same procedure as above to kill the two running programs after a few iterations.
Do programs running concurrently occupy the same memory locations (addresses)?
No
The illusion of dedicated memory resources
Many running program share the physical memory space.
Each runnning program is presented with the illusion that they have access to their own private memory. This is called virtual address space, which is mapped to physical memory space by the OS.
Making memory references within one running program (within one’s own virtual address space) does not affect the private virtual address space of others.
Without the setarch command, the location of variable p will be randomize within the virtual address space of a process. This is a security mechanism to prevent others from guessing and applying direct manipulation techniques to the physical memory location that acually contains p.
Concurrency
As shown in CPU Virtualization and Memory Virtualization examples, the OS wants to manage many running programs at the same time.
This is called concurrency, and it leads to a number of interesting challenges in designing and implementing various management mechanisms within the OS.
This can be observed through the following hands-on exercise.
Type exit to close one of the two terminal panes.
Run the following commands in the remaining terminal:
1
2
3
./threads 50
./threads 100
./threads 200
threads.c creates two functions running at the same time, within the same memory space of the main program.
A single global variable named counter is being increased by both functions, thus the final value of counter should be twice that of the command line argument.