title: Program stack and heap, how do they work?
body: <p>I know that every running process has pages associated with it in virtual memory and few of them will be loaded into main memory as required. I also know that program will have a stack and also a heap to allocate dynamic memory. Here are my questions.</p>
  
  <ol>
  <li>Is stack also part of some page in main memory?</li>
  <li>What happens when the program is moved to waiting state? Where are the stack pointer, program counter and other info stored?</li>
  <li>Why stack grows down and heap grows up?</li>
  <li>Can L1, L2 cache contain only one chunk of contiguous memory, or can it have some part of stack and heap?</li>
  </ol>
  
  <p>Can you recommend any good book that covers these things?</p>