11-28-2008
Your while loop does nothing but compute. It tries to use as much cpu as it can get. Outputing some data and sleeping do not use the cpu. I don't understand why you find any of this confusing.
As for avoiding cpu usage, you actually show two ways to do this. I don't understand why you then pose the question.
But there is nothing wrong with using the cpu if that is what your program needs to do. It's the kernel's job to ensure that all processes are allowed to run. The kernel will limit your process' cpu usage as it needs to. In general, a cpu bound process can hog the cpu for a few seconds, but its priority will be worsened as a result. It soon will have to least priority of any process and will find itself running only when the kernel can't find anything else to do.
At most, the only thing you need to do is to consider adding a nice() call like this:
nice(5);
This is a clue to the kernel to lower your process' priority.
10 More Discussions You Might Find Interesting
1. Programming
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
2. Programming
Please tell me solaris functions/api for getting following information
1- Function that tells how much memory used by current process
2- Function that tells how much memory used by all running processes
3- Function that tells how much CPU is used by current process
4- Function that tells how... (1 Reply)
Discussion started by: mansoorulhaq
1 Replies
3. UNIX for Advanced & Expert Users
System FreeBSD.
Issue: I see that system idle = 0% in the same time top and other commands show that all process eat 0% of cpu.
System calls 98%
CPU states: 7.9% user, 0.0% nice, 91.8% system,<==!!!
But top does not show any process which eats more than 0%
Question: how can I see... (0 Replies)
Discussion started by: mirusnet
0 Replies
4. HP-UX
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
5. Solaris
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
6. Solaris
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
7. AIX
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
8. Programming
Hi all,
I'm using python and psutil a library to get system informations like cpu usage (percent) for a given process.
My question is if I have the value in % of the cpu usage how I could get the cpu usage in cycle number I mean not in percent?
Thanks a lot
D. (5 Replies)
Discussion started by: Dedalus
5 Replies
9. AIX
Hi Guys,
I am a newbie on the forum. This is my first post, so first of all I would like to introduce myself.
I am a SAS Analyst programmer working for an Health Insurance client. SAS is installed on a 16 CPU AIX Server with partitions running with shared processor. I have couple of... (2 Replies)
Discussion started by: saurabhiim2003
2 Replies
10. HP-UX
Hi Experts,
We encountered problem in one of the production system where some processes were taking higher CPU and after some time it came back to normal..
From system prespective, is there any way to check why processes took more cpu during that particular period. (16 Replies)
Discussion started by: sai_2507
16 Replies
LEARN ABOUT ULTRIX
iostat
iostat(1) General Commands Manual iostat(1)
Name
iostat - report I/O statistics
Syntax
iostat [ -c ] [ -t ] [ disknames ] [ interval ] [ count ]
Description
The command reports I/O statistics for terminals, disks and cpus. For terminals the number of input and output characters are counted.
For disks the number of 512 byte blocks per second and number of transfers per second are displayed. For cpus, it provides the percentage
of time the system has spent in user mode, in user mode running low priority (niced) processes, in system mode, and idling. On multipro-
cessor systems these cpu statistics represent a cumulative summary of all the cpus.
The optional disknames argument causes disk statistics to be displayed for the specified disks. If this argument is not specified then
disk statistics will be displayed for the first 3 disks only.
The optional interval argument causes to report once each interval seconds. The first report is for all time since a reboot and each sub-
sequent report is for the last interval only.
The optional count argument restricts the number of reports.
Options
-c Displays the percentage of time each cpu spent in user mode, running low priority (nice'd) processes, in system mode, and idling.
-t Displays the number of characters read from and written to terminals.
Examples
This example will cause cpu and disk statistics for the 5 disks ra0, ra1, ra2, ra3, and ra4.
iostat ra0 ra1 ra2 ra3 ra4
This example will cause cpu, terminal, and disk statistics for ra0 to be displayed and updated every 2 seconds.
iostat -t ra0 2
Files
See Also
vmstat(1), cpustat(1)
iostat(1)