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

1. Where the History file can be located? 2. How will you harden the server? 3. Diff between Raid 1 and Raid 5? 4. What is the largest disk size can be used in LVM? 5. How will you remove a PV from lvm without any data loss? 6. What is the diff between ext3 and ext2 File system? 7. How we can use resize2fs, what is the purpose? 8. What is the purpose of LVM? Why it is used? 9. If the FS is in read-only mode, so we cannot create any file. How will you fix it? 10. How to create swap partition after OS installation? 11. What is the diff between ssh and telnet? 12. How to find out the dependency required for a package?

3 Answers   IBM,


What is the use of proc structure?

2 Answers   NetApp,


what is stored in /proc ? what is significance of /proc in linux ?

3 Answers   NetApp,


What are system calls used for process management in linux?

0 Answers  


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

4 Answers   Wipro,






what is cups and how to configure?

7 Answers   IBM,


if one of the critical section code (linked list) is under ISR & another one in kernel thread ? How you will synchronize for this critical section code ?

4 Answers   NetApp,


what are the backup utilites on red hat linux 4.0?

4 Answers   Wipro,


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?

2 Answers   Wipro,


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,


how to create a ftp user on redhat linux 4.0?

6 Answers   Accenture,


diff b/w spinlock, seamaphores and mutex and where to use it.

2 Answers   Intel,


Categories