The more your program does, and the more efficiently it does it, the higher the percentage of cpu utilitization will be.
That's not a bad thing. Sometimes just a few lines of code will generate 100's of lines of assembly or machine code.
If your program is starting to have longer run-times, and still has high cpu utilitization, then you have a worry to be checked out.
Adak
Nearly a Posting Virtuoso
1,479 posts since Jun 2008
Reputation Points: 425
Solved Threads: 185
Firstly if cpu utilisation is only getting to 70% there is nothing to worry about. All programs are getting all the cpu time they require with time (30% of the available time) left over.
A single run of your program however only opens a single file and reads it, if you are talking about multiple files then you must be running the program multiple times. It is the operating systems responsibility to share processor time between process that need it even if some of those processes are demanding 100% of the cpu time the operating system will on the whole not them them have it.
If you are still worried then are are things you can do but they will slow down the operation of the program.
You could run the program at a lower priority. The priority is an attribute that the operating system uses when scheduling tasks, lower priority programs get less processor time. You can change the priority either programatically by making approriate function calls or by using a utility like nice (try "man nice") to run the program with a reduced priority.
You could interrupt the read loop in the program with a yield or a small sleep.
However I would recomend that you do neither of these until you get to the point where you computer is getting problems because it is running out of processing resource which is isn't currently, it still has 30% of that resource left.
Banfa
Practically a Master Poster
600 posts since Mar 2010
Reputation Points: 486
Solved Threads: 92
The "bzero" in the loop is redundant and can be deleted.
It is also overflowing the allocated buffer size of "ffull".
UncleLeroy
Junior Poster in Training
63 posts since Mar 2010
Reputation Points: 68
Solved Threads: 6
EDIT : oops, i didnt realize this this thread was 5 days old.
nothing wrong with 70%.... heavy reads in a while loop,that would be expected. if other programs need (or are already using) cpu resources while this program is running, they will share the available resources.
and yes, get rid of the bzero. it's unnecessary. the fgets will null terminate the buffer after each read.
.
jephthah
Posting Maven
2,587 posts since Feb 2008
Reputation Points: 2,143
Solved Threads: 179