Q:

What is the difference between Segmentation fault and Bus error?

0

What is the difference between Segmentation fault and Bus error?

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Answer:

In the case of segmentation fault, SIGSEGV (11) signal is generated. Generally, a segmentation fault occurs when the program tries to access the memory to which it doesn’t have access to.

In below I have mentioned some scenarios where SIGSEGV signal is generated.

  • When trying to de-referencing a NULL pointer.
  • Trying to access memory which is already de-allocated (trying to use dangling pointers).
  • Using uninitialized pointer(wild pointer).
  • Trying to access memory that the program doesn’t own (eg. trying to access an array element out of array bounds).

In case of a BUS error, SIGBUS (10) signal is generated. The Bus error issue occurs when a program tries to access an invalid memory or unaligned memory. The bus error comes rarely as compared to the segmentation fault.

In below I have mentioned some scenarios where SIGBUS signal is generated.

  • Non-existent address.
  • Unaligned access.
  • Paging errors

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Embedded C interview questions and answers (2022)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Size of the integer depends on what?... >>
<< What are the common causes of segmentation fault i...