Infinite for loop is taking too much CPU usage %

Hi All,
I wrote one simple for loop shell script which prints number..but this loop is infinite...but its taking lot of CPU (15.7) %. if i am using sleep cmd then cpu usage become 0.4 %. Is there anyway to reduce this CPU usage without using sleep cmd?

i dont want 2 use sleep cmd because it will make a delay of minimum one second delay only.. Is there anyway 2 make a delay in nano or micro seconds in shell script.

Thanks,
chidhu

Why are you counting forever? What are you trying to do? Or - what is the information your script is supposed to give you? Unbounded loops are a big problem.

Do you know about the nice command?

You can use nanosleep() to get sleep times less than one second.

But I'll also question why you're doing this. There doesn't seem to be any point to just counting for the sake of counting.

Thanks very much for your replies. that for loop is processing the CDR for one by one. the CDR file is having a size in MB. once it exceeds 100000 its taking 15 % of CPU time. So we doubt that its not releasing some resources. and I assume that sleep will release the resource and make CPU idle for sometime. Thats why I asked for any command which will make a sleep of less than a second.

Please tell me how to avoid such a high CPU utiltization.

Thanks,
chidhu

I would guess that finding usleep for Sun Os is not going to help. Try nice instead - make the priority less so the process only consumes resources when no other process wants them.

I am assuming that your script does not do a lot of process creation - which may be a bad assumption.

Could you post your code?

I should have added that you'd need to compile your own C program to run that.

A high CPU utilization starts when the load is getting close to 100%. The run queue is also a metric to watch in such a situation. I would expect an infinite loop to generate that 100% load on a single CPU machine, 50% on a dual one, 25% on a four way system and so on.
As you still have 85% of CPU available for other tasks, what is the problem you are trying to fix ?

Hi All,
Initially I had a doubt that my program is taking this much CPU util because of the for loop more than 100000 times, from the reply I have got that it has to take that much CPU time. So I will try to analyse the code in different aspect.

Thanks to all for your comments.