title: How to handle bus error for accessing mmap-ed memory when underlying physical memory runs out?
body: <p>we use "shm_open" to create a shared memory object, and then "mmap" to map it to a memory region.  However, in later time, when the code actually accesses the memory, in some corner cases, it will hit "bus error" as the underlying physical memory was running out. </p>
  
  <p>This seems to be a generic thing in Linux as the "mmap" only map the virtual memory address space and the system allocates the actual physical memory only when you access the pages.  </p>
  
  <p>My question is:  how should I handle such "exception" gracefully?  What are the best practices?   I don't want the program crashes when the underlying memory runs out, I wanted to return ENOMEM in such case. Is there a way to achieve that?</p>
  
  <p>Thanks.</p>