Segmentation Fault
Wikipedia Page : http://en.wikipedia.org/wiki/Segmentation_fault
A segmentation fault occurs when your program tries to access memory locations that haven't been allocated for the program's use. Here are some common errors that will cause this problem:
scanf("%d", number);
In this case, number is integer. scanf() expects you to pass it the address of the variable you want to read an integer into. But, the writer has fogotten to use the `&' before number to give scanf the address of the variable. If the value of number happened to be 3, scanf() would try to access memory location 3, which is not accessible by normal users. The correct way to access the address of number would be to place a `&' (ampersand) before number:
scanf("%d", &number);
Another common segmentation fault occurs when you try to access an array index which is out of range. Let's say you set up an array of integers:
int integers[80];
If, in your program, you try to use an index (the number within the brackets) over 79, you will ``step out of your memory bounds'', which causes a segmentation fault. To correct this, rethink your array bounds or the code that is using the array.
Bus Error
Wikipedia Page : http://en.wikipedia.org/wiki/Bus_error
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
A SIGBUS is often caused by accessing data at an address that is not aligned to
a multiple of the width of the data. A 4 byte int must be aligned on a multiple
of 4. An 8 byte long must be aligned on a multiple of 8.
(processor) bus error - A fatal failure in the execution of a machine language
instruction resulting from the processor detecting an anomalous condition on its
bus. Such conditions include invalid address alignment (accessing a multi-byte
number at an odd address), accessing a physical address that does not correspond
to any device, or some other device-specific hardware error. A bus error
triggers a processor-level exception which Unix translates into a "SIGBUS"
signal which, if not caught, will terminate the current process.
From Cisco documentation
The system encounters a bus error when the processor tries to access a memory
location that either does not exist (a software error) or does not respond
properly (a hardware problem).
What is the difference between a Bus Error and a Segmentation Error?
Full Article:
Both are addressing errors, such as trying to address memory outside of your
legal address space. A segmentation error is detected by the kernel, while a
bus error is detected by the hardware.
These errors will occur when the program tries to access a memory location
outside its address space. That is, accessing uninitilized pointers, or even
mangled pointers (ones which have no reference or have been deleted).
The Bus error means that the kernel did not detecet the problem on its own;
the memory system realized the error.
Blog Archive
-
▼
2007
(55)
-
▼
Apr
(48)
- Socket Programming
- Pthreads
- Virtual Memory Management
- How a system call is implemented?
- Inter-process communication
- How malloc has been implemented (brk system call)?
- Linux Modules - How are they linked dynamically?
- Proc File System
- fork, vfork, copy-on-write and clone
- CPU Scheduling -- Different types of CPU schedulin...
- Signals (System V and POSIX)
- How mapping from virtual address address to physic...
- setuid program (real and effective user ids)
- Exceptions, traps, interrupts and signals
- Processor execution levels
- Process Address Space
- Unix/Linux File System Layout
- Salient points about Unix/Linux
- Big Endian versus Little Endian
- Semaphore, Mutex, Conditional variable, Spin lock
- Segmentation Fault and Bus Error
- wait() system call
- Bottom half
- Linux time keeping - Timer interrupt, jiffies, xtime
- Position Independent Code (PIC)
- kmalloc/kfree and vmalloc/vfree
- Static versus shared objects
- How many processes will be created-- fork?
- Can we get return value from exec system call?
- How does profiling code works? -- processor debug ...
- ptrace - how does it work?
- Record locking
- GNU Linux pthreads
- How do you use RSA for both authentication and sec...
- Unix/Linx bootupand login
- What are various problems unique to distributed da...
- cooperative,preemption,non preemption
- Puzzles
- Write system call that prints stack trace at that ...
- DMA (Direct Memory Access)
- Real Time Systems
- Comparison of IOS and General Purpose OS like Linux
- Operating Systems I/O Structure
- Linux - Process Scheduling
- Deadlock avoidance and prevention
- Porting from 32 bit OS to 64 bit OS
- Sign extension
- How to make an application daemon
-
▼
Apr
(48)
No comments:
Post a Comment