Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Getting proccessor speed and Memory size from program.

Posted on 2003-11-20
12
Medium Priority
?
372 Views
Last Modified: 2010-04-21
I want get processor speed and Memory size using system calls(like sysctl system call).Can any body suggest me how to do it.
0
Comment
Question by:mahesha_krpet
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
  • 2
  • +1
12 Comments
 
LVL 3

Accepted Solution

by:
scn earned 500 total points
ID: 9788420
processor speed can be read from /proc/cpuinfo entry
memory size can either be read from /proc/meminfo or obtained with the sysinfo() system call
0
 
LVL 24

Assisted Solution

by:shivsa
shivsa earned 500 total points
ID: 9788831
#include <stdio.h>
#include <string.h>

float get_cpu_clock_speed()
{
 FILE *fp;
char buffer[1024];
size_t bytes_read;
char *match;
float clock_speed;

fp=fopen("/proc/cpuinfo","r");
bytes_read= fread(buffer,1,sizeof(buffer),fp);
fclose(fp);

if(bytes_read == 0 || bytes_read == sizeof(buffer) )
return 0;

buffer[bytes_read] = '\0';
match = strstr(buffer,"cpu Mhz");
if(match == NULL)
return 0;

sscanf(match, "cpu Mhz:"%f", &clock_speed);
return clock_speed;
}

int main()
{
 printf("CPU clock speed: %4.0f Mhz\n",get_cpu_clock_speed());
return 0;
}
0
 
LVL 24

Expert Comment

by:shivsa
ID: 9788863
and about getiing Mem.

#include <linux/kernel.h>
#include <linux/sys.h>
#include <stdio.h>
#include <sys/sysinfo.h>

int main()
{

struct sysinfo si;
sysinfo(&si);

printf("total RAM:%5.1f MB\n",sitotalram/megabyte);
printf("free RAM: %5,1f MB \n", sifreeram/megabyte);

return 0;
}
0
Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

 
LVL 12

Expert Comment

by:paullamhkg
ID: 9794520
Do you mean the status of the processor and the memory ? if yes, you can use 'top' to see

eg.
 12:52:42  up 34 days, 5 min,  1 user,  load average: 0.00, 0.00, 0.00
62 processes: 60 sleeping, 2 running, 0 zombie, 0 stopped
CPU states:   0.3% user   0.1% system   0.0% nice   0.0% iowait  99.4% idle
Mem:   126044k av,  123676k used,    2368k free,       0k shrd,   68828k buff
                     84512k actv,       0k in_d,    1744k in_c
Swap: 1044144k av,   26764k used, 1017380k free                   31280k cached

Actually there are already many monitoring application you can use like this one http://secure.netroedge.com/~lm78/index.html
0
 
LVL 24

Expert Comment

by:shivsa
ID: 9795568
did these programs work. let us know the results.
0
 
LVL 24

Expert Comment

by:shivsa
ID: 9809421
Hi Mahesha,

any update, did the programs worked. if worked please accept the answer
0
 
LVL 24

Expert Comment

by:shivsa
ID: 10188848
I think i answered this questions.
0
 
LVL 12

Expert Comment

by:paullamhkg
ID: 10199332
suggest points split for all
0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 10303700
Paul, the question was about getting this information via a system call, so using top is IMHO not an acceptable answer.
0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 10303704
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
Split between scn and shivsa
Please leave any comments here within the next four days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

khkremer
EE Cleanup Volunteer
0

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How many times have you wanted to quickly do the same thing to a list but found yourself typing it again and again? I first figured out a small time saver with the up arrow to recall the last command but that can only get you so far if you have a bi…
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Suggested Courses

704 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question