LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   mathematics ? (http://www.linuxquestions.org/questions/programming-9/mathematics-369639/)

Volcano 10-04-2005 07:19 AM

mathematics ?
 

# cat /proc/stat
cpu 340465 1397 326489 540360
cpu0 340465 1397 326489 540360
page 624282 398572
swap 6368 31892
intr 1998753 1208711 9141 0 0 3 0 0 0 1 0 0 31415 685495 0 63987 0
disk_io: (3,0):(64082,42839,1247940,21243,797124)
ctxt 7881082
btime 1128416208
processes 6024


i want to get the percentage CPUfrom this . whats the mathematics ?

Volcano 10-04-2005 07:38 AM

can i get the percentage CPU from this output ?

kjordan 10-04-2005 09:52 AM

Quote:

Originally posted by Volcano
can i get the percentage CPU from this output ?
Percentage CPU of what?
Code:

cpu  3357 0 4313 1362393
                    The  amount  of  time,  measured  in  units  of  USER_HZ
                    (1/100ths of a second on  most  architecures),  that  the
                    system  spent  in  user mode, user mode with low priority
                    (nice), system mode, and  the  idle  task,  respectively.
                    The  last  value should be USER_HZ times the second entry
                    in the uptime pseudo-file.

                    In Linux 2.6 this line includes three additional columns:
                    iowait - time waiting for I/O to complete (since 2.5.41);
                    irq -  time  servicing  interrupts  (since  2.6.0-test4);
                    softirq - time servicing softirqs (since 2.6.0-test4).


Volcano 10-04-2005 08:24 PM

>Percentage CPU of what?
when run "top" command you get CPU states in percent. i want to get similar results without using "top"

kjordan 10-04-2005 11:27 PM

Any particular language?

In C, you can use
#include <sys/sysinfo.h>

int sysinfo(struct sysinfo *info);

which will give you:
Code:

              struct sysinfo {
                  long uptime;            /* Seconds since boot */
                  unsigned long loads[3];  /* 1, 5, and 15 minute load averages */
                  unsigned long totalram;  /* Total usable main memory size */
                  unsigned long freeram;  /* Available memory size */
                  unsigned long sharedram; /* Amount of shared memory */
                  unsigned long bufferram; /* Memory used by buffers */
                  unsigned long totalswap; /* Total swap space size */
                  unsigned long freeswap;  /* swap space still available */
                  unsigned short procs;    /* Number of current processes */
                  unsigned long totalhigh; /* Total high memory size */
                  unsigned long freehigh;  /* Available high memory size */
                  unsigned int mem_unit;  /* Memory unit size in bytes */
                  char _f[20-2*sizeof(long)-sizeof(int)]; /* Padding for libc5
*/
              };


Volcano 10-05-2005 11:15 PM

but where is the CPU in percent in your code ?

kjordan 10-05-2005 11:17 PM

Quote:

Originally posted by Volcano
but where is the CPU in percent in your code ?
I *think* it might be the loads, but I've not used that before just ran across it while googling.


All times are GMT -5. The time now is 11:51 AM.