LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-04-2005, 07:19 AM   #1
Volcano
Member
 
Registered: Sep 2005
Posts: 225

Rep: Reputation: 15
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 ?
 
Old 10-04-2005, 07:38 AM   #2
Volcano
Member
 
Registered: Sep 2005
Posts: 225

Original Poster
Rep: Reputation: 15
can i get the percentage CPU from this output ?
 
Old 10-04-2005, 09:52 AM   #3
kjordan
Member
 
Registered: Jul 2004
Distribution: LFS, I felt the itch and scratched it
Posts: 227

Rep: Reputation: 31
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).
 
Old 10-04-2005, 08:24 PM   #4
Volcano
Member
 
Registered: Sep 2005
Posts: 225

Original Poster
Rep: Reputation: 15
>Percentage CPU of what?
when run "top" command you get CPU states in percent. i want to get similar results without using "top"
 
Old 10-04-2005, 11:27 PM   #5
kjordan
Member
 
Registered: Jul 2004
Distribution: LFS, I felt the itch and scratched it
Posts: 227

Rep: Reputation: 31
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
*/
              };
 
Old 10-05-2005, 11:15 PM   #6
Volcano
Member
 
Registered: Sep 2005
Posts: 225

Original Poster
Rep: Reputation: 15
but where is the CPU in percent in your code ?
 
Old 10-05-2005, 11:17 PM   #7
kjordan
Member
 
Registered: Jul 2004
Distribution: LFS, I felt the itch and scratched it
Posts: 227

Rep: Reputation: 31
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
bash mathematics possible? stabu Linux - Newbie 5 04-30-2004 04:45 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:58 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration