Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Open Source > Linux
|
Linux General discussion of programming the various flavors of Linux operating systems.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Linux section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 23rd, 2006, 11:52 AM
Registered User
 
Join Date: Nov 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Segmentation Fault

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.
 
Old December 15th, 2006, 10:45 AM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default

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
 
Old December 15th, 2006, 10:48 AM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default

does that help any Bij? are you still having problems?

www.crmpicco.co.uk
www.ie7.com
 
Old December 15th, 2006, 11:29 AM
Registered User
 
Join Date: Nov 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.
 
Old December 15th, 2006, 12:12 PM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default

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





Similar Threads
Thread Thread Starter Forum Replies Last Post
Having problem inside functions (seg-fault). mgm BOOK: Professional Assembly Language 0 August 4th, 2006 12:34 PM
Wrox example code fault ) The Gorgon BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 1 August 9th, 2004 01:12 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.