|
Subject:
|
Segmentation Fault
|
|
Posted By:
|
diamondField
|
Post Date:
|
11/23/2006 10:52:09 AM
|
On our Linux RedHat 7.2, I am getting "segmentation fault" when using 'top' command. This used to be working fine few weeks back.
What's causing this fault and why ? How to get it rectified ?
Any help will be appreciated.
Thanks, Bij.
|
|
Reply By:
|
crmpicco
|
Reply Date:
|
12/15/2006 9:45:59 AM
|
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.
www.crmpicco.co.uk www.ie7.com
|
|
Reply By:
|
crmpicco
|
Reply Date:
|
12/15/2006 9:48:15 AM
|
does that help any Bij? are you still having problems?
www.crmpicco.co.uk www.ie7.com
|
|
Reply By:
|
diamondField
|
Reply Date:
|
12/15/2006 10:29:57 AM
|
Thanks Craig for the reply. I understood why it happens, but can't see why "top" command is failing. Does it mean that I have some or one program in the memory running which is not allocated properly ?
Can i possibly identify such a process from ps -eafx and kill it ?
How to get the "top" command working again ?
Thanks, Bij.
|
|
Reply By:
|
crmpicco
|
Reply Date:
|
12/15/2006 11:12:01 AM
|
to be honest Bij, being unable to use top sounds similar to a virus preventing you from using 'task manager' in MS Win. try killing as much as you can with ps -eafx.
i take it google has brought no response so far?
www.crmpicco.co.uk www.ie7.com
|