Operating System - HP-UX
1832978 Members
2786 Online
110048 Solutions
New Discussion

Re: Difference between Segmentation fault Bus error Memory fault coredump

 
SOLVED
Go to solution
murugesan_2
Advisor

Difference between Segmentation fault Bus error Memory fault coredump

Hello all,
I compiled this program on HP-UX PA-RISC,Linux and HP-UX IPF machines.

main()
{
char *p;
*p='a';
printf("%c",*p);
}

Linux machine1 Segmentation fault
Linux Machine2 Segmentation fault
HP UX PA-RISC Machine1 Bus error(coredump)
HP UX PA-RISC Machine2 Bus error(coredump)
HP UX IPF Machine1 Memory fault(coredump)
HP UX IPF Machine2 Memory fault(coredump)

So what is the difference between

1. Segmentation fault
2. Bus error(coredump)
3. Memory fault(coredump)
4. Coredump

How can I reproduce these errors independent of platforms ( may be compilers ) or Can I get 4/3 C programs for each of the errors.

Thanks in advance.
5 REPLIES 5
Laurie Gellatly
Honored Contributor

Re: Difference between Segmentation fault Bus error Memory fault coredump

I'd certainly use a program with more predicable conditions.
At present your code fails when the end of the
string (that has not been established) is
searched for. Now depending on how the compiler
compiled the code, it may or may not find a
terminating 0 befor the OS jumps on it for
trying to reference memory out of its own area. So its possible that this code may
even work in some cases or some times.
It all depends on the initial value of 'p' and
if the compiler set it or left it as a random value.

At least setting p=0 would be reproducable.
The way the OS responds to this will also
depend on the memory model used in the OS I believe.

Not sure that helps, but any time you want
to run some code with errors in it I'm sure
there are plenty of people that can provide
samples ;{)

Why do you need to reproduce the errors anyway?


...Laurie :{)
If you're not using OverTime, you're doing overtime!
murugesan_2
Advisor

Re: Difference between Segmentation fault Bus error Memory fault coredump

As I told already, I need to know the difference between the above four ( or may be three excluding coredump ) .

As far as I know

Segmentation fault occurs when we try to access the memory area out of the process address space.
Bus error occurs when we try to access a physical device that does not exists.

coredump is the facility provided by the compiler that will give us the information on the causes and memory faults that occurs at run time.

My question is to know these things ( the above mentioned 4 cases ) practically.
Now I have a program for bus error.

#include
main()
{
FILE *fp=NULL;
fwrite("TEST",5,1,fp);
fclose(fp);
}

But this produced the expected result in IPF and PA-RISC machineS alone . In Linux I am not getting the bus error message. Instead I am getting the same "Segmentation fault" error message.

What I need is, four programs ( or three programs, if coredump has been excluded ) which when run on all the platforms produces the same results.
Dietmar Konermann
Honored Contributor
Solution

Re: Difference between Segmentation fault Bus error Memory fault coredump

Essentially there are only two cases you need to distinguish. SIGSEGV and SIGBUS.

The "Memory fault" you are seeing is also a Segmentation Fault... only ksh and posix-sh use the term for that very same thing.

ksh# sleep 100&
[1] 2901
ksh# kill -SEGV %%
[1] + Memory fault(coredump) sleep 100&

csh# sleep 100 &
[1] 2961
csh# kill -SEGV %%
[1] Segmentation fault sleep 100 (core dumped)

A bus error usually happens if you are using unaligned addresses. The NULL pointer example is a special case... one of many.

Best regards...
Dietmar.

"Logic is the beginning of wisdom; not the end." -- Spock (Star Trek VI: The Undiscovered Country)
murugesan_2
Advisor

Re: Difference between Segmentation fault Bus error Memory fault coredump

Thanks Dietmar for pointing me to the exact location to get the errors.
Muthukumar_5
Honored Contributor

Re: Difference between Segmentation fault Bus error Memory fault coredump

Coredump is containing informations that the environment where the program got crashed and by what signal it's behaviour changed.

With the signal we can identify the problem. You can simply use file core to know the type of signal you got there.

Causes for SEGV and BUS signals:

SIGSEGV
SEGV_MAPERR address not mapped to object
SEGV_ACCERR invalid permissions for mapped object
SIGBUS
BUS_ADRALN invalid address alignment
BUS_ADRERR non-existent physical address
BUS_OBJERR object specific hardware error


Segmentation fault and Memory fault (coredump) are same. All are happenening because of SIGSEGV signal.

Bus error is happenening out on getting SIGBUS signal.

Let us compare them on HP-UX platforms:

IPF: <11.23>

First program is giving only Memory fault(coredump) on IPF and BUS error on PA-RISC.

When we try it as,

FILE *fp;

and getting Bus error(coredump) on IPF and PA-RISC too.

I hope the messages of SIGSEGV and SIGBUS will give the view on this.

Memory errors are occured because unaligned memory area access or invalid address mappings too.

You can use gdb / adb to debug the core.

And more use file / what commands to analyse



Easy to suggest when don't know about the problem!