Infinite for loop is taking too much CPU usage %


 
Thread Tools Search this Thread
Operating Systems Solaris Infinite for loop is taking too much CPU usage %
# 1  
Old 06-22-2009
MySQL 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
# 2  
Old 06-22-2009
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?
# 3  
Old 06-22-2009
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.
# 4  
Old 06-22-2009
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
# 5  
Old 06-23-2009
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?
# 6  
Old 06-23-2009
Quote:
Originally Posted by achenle
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.
I should have added that you'd need to compile your own C program to run that.
# 7  
Old 06-23-2009
Quote:
Originally Posted by pa.chidhambaram
Please tell me how to avoid such a high CPU utiltization.
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 ?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to stop infinite loop

Im unable to stop the below infinite loop (bash script). Can someone tell me why this isnt responding to signals eg: ctrl+c (SIGINT) or ctrl+z c=0 test_loop() { c=$(($c+1)) echo "count value is : $c " sleep 1 test_loop } Im using: SunOS 5.10 PS: If run this as... (13 Replies)
Discussion started by: Arun_Linux
13 Replies

2. Shell Programming and Scripting

My for loop decides to become an infinite loop?

Hi, I was debating if I should put this in the dummies or scripts section, I apologize in advance if I chose poorly. Fairly new to Unix and BASH scripting but I thought I made it fairly well given my limited understanding. However, the output indicates that it's looping and I'm ending up with a... (5 Replies)
Discussion started by: gotreef
5 Replies

3. UNIX for Advanced & Expert Users

Procmail and infinite loop

I wanted to copy (not forward but copy) all incoming email to another address of mine. It worked, but now I encountered an infinite loop problem: When the second address doesn't like the content and bounces the message back, the bounce message will be sent back and forth. So, what I have in... (1 Reply)
Discussion started by: distill
1 Replies

4. Shell Programming and Scripting

Infinite while loop

what is the difference between while:,while true and while false? (6 Replies)
Discussion started by: proactiveaditya
6 Replies

5. AIX

How to monitor the IBM AIX server for I/O usage,memory usage,CPU usage,network..?

How to monitor the IBM AIX server for I/O usage, memory usage, CPU usage, network usage, storage usage? (3 Replies)
Discussion started by: laknar
3 Replies

6. Programming

Is my code in an Infinite Loop?

Production C code compiled without the dash-g option is running, and seems to be in an infinite loop. Is there a way to tell? Is there a diagnostic tool that will report what objects or what lines of code or even what functions are being executed? Or is my best option to kill it with a dump? ... (5 Replies)
Discussion started by: marcus121
5 Replies

7. Solaris

Multi CPU Solaris system shows 100% CPU usage.

Hello Friends, On one of my Solaris 10 box, CPU usage shows 100% using "sar", "vmstat". However, it has 4 CPUs and prstat and glance are not showing enough processes to justify high CPU utilization. ========================================================================= $ prstat -a ... (4 Replies)
Discussion started by: mahive
4 Replies

8. Solaris

current CPU usage, memory usage, disk I/O oid(snmp)

Hi, I want to monitor the current cpu usage, monitor usage , disk I/o and network utlization for solaris using SNMP. I want the oids for above tasks. can you please tell me that Thank you (2 Replies)
Discussion started by: S_venkatesh
2 Replies

9. HP-UX

how can I find cpu usage memory usage swap usage and logical volume usage

how can I find cpu usage memory usage swap usage and I want to know CPU usage above X% and contiue Y times and memory usage above X % and contiue Y times my final destination is monitor process logical volume usage above X % and number of Logical voluage above can I not to... (3 Replies)
Discussion started by: alert0919
3 Replies

10. Programming

Monitor CPU usage and Memory Usage

how can i monitor usages of CPU, Memory, Hard disk etc. under SUN Solaries through a c program or java program i want to store that data into database so i can show it graphically thanks in advance (2 Replies)
Discussion started by: Gajanad Bihani
2 Replies
Login or Register to Ask a Question