Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Open Source > Linux
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 23rd, 2006, 11:52 AM
Registered User
 
Join Date: Nov 2006
Location: London, London, United Kingdom.
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.
Reply With Quote
  #2 (permalink)  
Old December 15th, 2006, 10:45 AM
Friend of Wrox
Points: 8,019, Level: 38
Points: 8,019, Level: 38 Points: 8,019, Level: 38 Points: 8,019, Level: 38
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2005
Location: Mauchline, East Ayrshire, Scotland
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
Reply With Quote
  #3 (permalink)  
Old December 15th, 2006, 10:48 AM
Friend of Wrox
Points: 8,019, Level: 38
Points: 8,019, Level: 38 Points: 8,019, Level: 38 Points: 8,019, Level: 38
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2005
Location: Mauchline, East Ayrshire, Scotland
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
Reply With Quote
  #4 (permalink)  
Old December 15th, 2006, 11:29 AM
Registered User
 
Join Date: Nov 2006
Location: London, London, United Kingdom.
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.
Reply With Quote
  #5 (permalink)  
Old December 15th, 2006, 12:12 PM
Friend of Wrox
Points: 8,019, Level: 38
Points: 8,019, Level: 38 Points: 8,019, Level: 38 Points: 8,019, Level: 38
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2005
Location: Mauchline, East Ayrshire, Scotland
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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 02:20 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.