What is meant by CPU Utilization of a process?
How to measure it?
What are the means for reducing it?
I have always been confused with this concept. I have tried to measure the CPU used by using 'top' command in the Linux. But, what I notice is, when there are no other user process running, then my process seem to spike up and take 99% CPU when it's not blocked in I/O. But, if there are other process running then it comes to 45% or 50%. Is it acceptable for a process to take 99% of CPU when no other process is running?
Any links or pointers in the direction will also help.
CPU utilization in this context is the proportion of the total available processor cycles that are consumed by each process.
If it's just computing some long-winded calculation, then what you are seeing is normal: the OS is dividing the available 100% of computing resources fairly between the processes that are asking for it.
If, instead, your program should be waiting for some event, like waiting for the user to press a key or for input to arrive from teh network, it sounds like your program is in an infinite loop: it never waits for anything but just churns away all the time. If that is the case, you should consider rewriting it so that, when it has no work to do, it waits for something. This might be waiting for the user to press a key, for a packet to arrive on a network connection or whatever. If that is the case, you should be looking for code that goes "Is there any work to do? No! Is there any work to do? No! Is there any work to do? No!" madly. If this is the case, you should find a way to make it wait for work using an appropriate operating system call or library function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With