1) What is the stack this image refers to?
stack is designed to highlight local variables and function frames (which include functions such as functional parameters, where to return after the function, etc.).
2) What is a memory mapping segment that relates to file associations?
the memory mapping segment contains linked libraries. Also, mmap calls are highlighted here. In general, a memory mapped file is simply a memory area supported by the file.
3) What the heap does in the process. Is the heap handled only in the process or is the heap something supported by the kernel of the operating system, and then the malloc memory space is allocated (using the heap) when the user application is calling this?
heap depends on the process and is controlled by the process itself, however, it must first request memory from the OS (and if necessary). You are right, this is usually when malloc calls are allocated. However, in most malloc implementations, mmap used to request blocks of memory, so there is really less difference between the heap and the memory mapping segment. Indeed, the heap can be considered part of a memory mapped segment.
4) Does this mean that at one time in memory is only one program, occupying only 4 GB of RAM?
No, this means that the amount of address memory available for the program is limited to 4 GB of RAM, what is actually contained in the memory at any given time depends on how the OS allocates physical memory and goes beyond the scope of this question.
5) Does this relate to the randomization of the stack in the process, or does it relate to what remains after calculating the space of all processes?
I have never seen anything that suggests that 4 GB of space βimpedesβ the effectiveness of the memory allocation strategies used by the OS. In addition, as @Jason notes, the locations of the stack, memory mapping segment, and heaps are randomized "to prevent predictable security exploits, or at least make them much harder than if every process controlled by the OS had every part of the executable file same place in virtual memory. " To be specific, the OS randomizes virtual addresses for the stack, memory mapped heap, and heap. In this note, all that the process sees is a virtual address , which is then mapped to a physical address in memory, depending on where the particular page is located. More information on mapping between virtual and physical addresses can be found here .
This paging article is a good starting point to learn how the OS manages memory between processes, and is a good reading resource for answering questions 4 and 5. In short, memory is allocated on process pages, and these pages either exist in main memory, or "unloaded" to disk. When a memory address is requested by a process, it moves the page from disk to main memory, replacing another page if necessary. There are various page replacement strategies that are used, and I refer you to the article to learn more about the advantages and disadvantages of each of them.