what is segmentation fault?

Answers were Sorted based on User's Feedback



what is segmentation fault?..

Answer / kamal

access to the memory which is not valid, will cause
segmentation fault.
Let us take example, in dynamic memory allocation like
malloc, we allocate memory and then we free it using:

free(fp);

if we write free() one more time say ,

free(fp);
free(fp);

it will cause segmentation fault. because the pointer was
already freed and now its not valid, but we are trying to
free an invalid location.

Is This Answer Correct ?    74 Yes 5 No

what is segmentation fault?..

Answer / mohan

In C There are different types of error like

1.compile time error
2.Linker error
3.Run time error
4.Logical error

The sigmentation fault comes under Run tile error.
Let see a simple example
#include<stdio.h.
int main()
{
int i;
scanf("%d",i);
printf("%d",i);
return(0);
}

if you compile this program ,compiler can't report any
error.If you run this program in Linux Platform you got
sigmentation fault error.

This is because ,in scanf() function call instead passing
the address of the variable ,value of variable is going to
scanf() .so you got this error.

In Linux sigmentation fault is run time error reported by
memory management.

most of the time this error occurs at illegal memory access.

Is This Answer Correct ?    34 Yes 7 No

what is segmentation fault?..

Answer / hitesh

This refers to a program crash when an application tries to
access resources on a computer that it does not have
permission to access. For the sake of the security of the
computer, the operating system will crash the offending
computer and create a segmentation fault

Is This Answer Correct ?    30 Yes 10 No

what is segmentation fault?..

Answer / dheeraj gahtori

Segmentation fault occurs when we address to an invalid
memory location. for example if we address a file address
which has already been freed , will give us segmentation fault.

Is This Answer Correct ?    25 Yes 7 No

what is segmentation fault?..

Answer / amro

it might be casing of buffer overflow which consumed the
memory buffer and case segmentation fault

Is This Answer Correct ?    26 Yes 12 No

what is segmentation fault?..

Answer / sunil kumar sharma

The physical memory in a computer is managed by the
operating system.It has different segments for different
purposes like for storing data,variables,text,garbage
values etc.When we try to access the memory location
outside of any allocated space segmentation fault does
occurs.

Like in Unix environment pointers must be handled carefully.
char *p;
We can't use this pointer variable without initializing it.
If we do so, we will get a segmentation fault error.

Is This Answer Correct ?    11 Yes 4 No

what is segmentation fault?..

Answer / vijaya aliveni.m

The physical memory in a computer is managed by the
operating system.It has different segments for different
purposes.
Here is an example of ANSI C code that should create a
segmentation fault on platforms with memory protection:

int main(void)
{
char *s = "hello world";
*s = 'H';
}

In the above ex. string "s" will hold the "hello world".
But in bellow we are trying to replace the letter "H" in the
place of "h".
But in that, pointer is only readonly we are not able to
change the charters.
So , while executing it will show the segmentation fault.

Is This Answer Correct ?    8 Yes 3 No

what is segmentation fault?..

Answer / vinaymb

Consider an example

#include "stdio.h"
main ()
{
char *ptr = "BANGLAORE";
*ptr = "b";
}

This Program will compile without any error. But on running
this program you will get the Segmentation error. Because
the ptr will hold the address which is read-only and we are
changing the value at the read-only which will result in
segmentation fault.

Is This Answer Correct ?    5 Yes 1 No

what is segmentation fault?..

Answer / siva

segmentation fault occurs when voilating the rules and
regulations of the Operating System.
eg:
1. divide a number by zero
2. when accessing a memory non exist.

Is This Answer Correct ?    22 Yes 19 No

what is segmentation fault?..

Answer / jailani

in many situation segmentation faults can occur. the main
situations are
1. when you are trying to access the null pointer
2.access to memory that already freed
3.dereferencing null pointer and uninitialized pointer
4.and also some compiler give segmentation fault when stack
overflow will occur

the concept behind the segmentation fault is that every
program has some space on memory for it execution like
storing variables in stack and heap. when you are try to
access the out of memory that has allocated.

Is This Answer Correct ?    3 Yes 0 No

Post New Answer

More Linux System Calls Interview Questions

what are different ways the context switch happens from user to kernel space or vice-versa ?

0 Answers   Alcatel,


I would like to know whether Simado and Setu products are they EPBX or not ?

0 Answers   IBM,


what is nis server

13 Answers  


linux system its not booting up its showing groub error what i need to do?

4 Answers   Wipro,


What is atomic function / atomic variable ?

1 Answers   Broadcom,






what is bus trap.

1 Answers   NetApp,


Explain process management system calls in linux?

0 Answers  


What does exec family return?

1 Answers  


What will happen when we invoke a system call and say with an example of invoking a system call ?read? for a device?

3 Answers   NetApp,


What are the signals we have in Linux

3 Answers   HCL, NetApp,


what is the difference between user APIs and kernel system calls ?

1 Answers   NetApp,


how to configure http server on red hat linux4.0?

5 Answers   IBM,


Categories