In one of my programs, I would hit "SIGBUS" when trying to access a mmap-ed memory location that failed to get the memory page (as the underlying physical memory ran out) and the program crashed due to SIGBUS.
I plan to register a SIGBUG signal handler to avoid crash. However, I don't want to exit() the program from the SIGBUS handler. I am trying to see if there is anyway to gracefully report ENOMEM and continue the program with other work.
Can I do the following? The code looks like this:
mem_p->head = MY_HEAD_MAGIC; /* this line could trigger SIGBUS */
if (sigbus_happened) {
sigbus_happened = FALSE;
do_something_else();
return ENOMEM;
}
and the signal handler:
void signal_handler (int sig)
{
if (sig == SIGBUS)
sigbus_happened = TRUE;
}
Would the above work and no crash?
Thanks.