LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-17-2002, 02:57 AM   #1
jpflathead
LQ Newbie
 
Registered: Oct 2002
Location: Nijmegen, The Netherlands
Distribution: suse and redhat
Posts: 8

Rep: Reputation: 0
Unhappy program takes all cpu time


Hi there,
I am quite new to c programming. I wrote a program to measure some values with a a/d converter connected to the parport. The program is timer interrupt driven and runs OK for a few hours (6-26). After that it takes 98% of CPU time and does not react to input.
How can I see where it is so busy with? there are some while loops in the program but all of them have a timer-time-out built in.
The idea was that it runs as a daemon and interfacing should go through a web-page.
Program is developed on suse 7.0 and run on redhat with the same kernel (a smoothwall 0.9.9-18). The runtime machine has no X.
Any help would be appreciated. And I have no experience with gdb (but it is never too late to start ;-) )

-jpf-
 
Old 10-17-2002, 07:37 AM   #2
Mik
Senior Member
 
Registered: Dec 2001
Location: The Netherlands
Distribution: Ubuntu
Posts: 1,316

Rep: Reputation: 47
Unless you can run the application in a debug mode which generates a lot of extra output. Your best option would probably be to start debugging it with gdb.
Once it starts taking up 98% of the processor load if it's still possible to start up gdb then you can attach gdb to the running process by doing something like: gdb program pid

If it takes up too much load you might want to try getting the file to generate a core file which you can later debug, possibly even on a different computer if needed. You can make the program stop and generate a core file by giving the command: kill -ABRT pid

Debugging will work best if you have built a debug version of the program so make sure you compile with the -g switch.

Another thing you might want to look at is memory usage of the application. You could write a script which logs the output of ps aux every x minutes to see if there are possible memory leaks. This can really slow down a process. Something like this will show the 10 processes which use the most memory:

ps aux | awk '{print $6,$0}' | sort -gr | head -n 10

Last edited by Mik; 10-17-2002 at 08:10 AM.
 
Old 10-17-2002, 03:36 PM   #3
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Haven't used it myself (yet), but "gprof" might help.
From "man gprof":
Quote:
"Gprof" calculates the amount of time spent in each rou_tine.
 
Old 10-23-2002, 02:50 AM   #4
jpflathead
LQ Newbie
 
Registered: Oct 2002
Location: Nijmegen, The Netherlands
Distribution: suse and redhat
Posts: 8

Original Poster
Rep: Reputation: 0
The Linux that is running doesnt understand kill -ABRT but does understand kill -6. I think it is kill -INT or so. I changed a routine where an array pointer got out of bounds, but it is still running wild, only after a shorter period of time.

I started dbg and it reads symbols from libc.so.6 and .4 and then comes with: no such file or dir in ../sysdeps/generic/strcpy.c .

Is this an error generated by gdb or an error from my program?

-jpf-

btw where must Gprof be run?

-leuk nederlands onderonsje ;-)

Last edited by jpflathead; 10-23-2002 at 02:53 AM.
 
Old 10-29-2002, 04:02 AM   #5
Mik
Senior Member
 
Registered: Dec 2001
Location: The Netherlands
Distribution: Ubuntu
Posts: 1,316

Rep: Reputation: 47
It's an error from gdb. It's looking for the source code files. Having the source code files makes it easier to debug so you can see where it went wrong? You should make sure you debug in the right directory so it can find the source files.

There are several steps to running gprof. The man page explains it all in detail.
 
Old 10-31-2002, 06:52 AM   #6
jpflathead
LQ Newbie
 
Registered: Oct 2002
Location: Nijmegen, The Netherlands
Distribution: suse and redhat
Posts: 8

Original Poster
Rep: Reputation: 0
Unhappy

I found it. I was waiting for a time-out but the time-out timer didn't run anymore.

But now I have a new problem -> new posting

jpf

Last edited by jpflathead; 10-31-2002 at 06:53 AM.
 
  


Reply



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



Similar Threads
Thread Thread Starter Forum Replies Last Post
logrotate takes up 100% CPU indefinitely BroX Slackware 2 05-24-2005 03:32 AM
FC 2 GNOME takes 99.9% of cpu. bruse Fedora 6 04-26-2005 07:24 PM
events/0 takes over my cpu tomhemba Fedora 4 08-01-2004 04:05 AM
kernel takes a lot of CPU stephnane AIX 3 04-29-2004 08:41 AM
magicdev takes up too much cpu time mattkat Linux - Software 1 12-19-2003 02:38 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:02 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration