what is segmentation fault?
Answers were Sorted based on User's Feedback
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
How to create secured appeche web sever ?
why the kernel panic error was appering?
1.Diff between Active and passive FTP? 2.What is anacron? 3.Diff between yum update and yum install while doing for kernel? 4.root_squash and no_root_squash does what? 5.What are the commands will you execute to find a new hardware? 6.How will you find out a lun allocated from SAN? 7.What is the main diff in CaT5 and CAT6 cable, except the 1/100 and 1/1000? 8.What is stale NFS and How will you fix it? 9.What is kernel panic error? 10.How will you recover password and shadow file, in case both got deleted. Explain the steps? 11.Explain boot process 12.What is network bonding. Explain the steps? 13.What are the exit codes returned by FSCK? 14.What is LDOM? 15.Diff between block and character device?
how to configure sendmail server on red hat linux version 4 and what and all we Require?
what are the different ways the Linux can swich from User Space to Kernel Space & vice-versa ?
what is segmentation fault?
what is sudo on linux?
linux system its not booting up its showing groub error what i need to do?
What are the signals we have in Linux
What is the Diffrent between Redhat linux And suse linux
what is bus trap.
what are different ways the context switch happens from user to kernel space or vice-versa ?