Solved

Getting proccessor speed and Memory size from program.

Posted on 2003-11-20
12
343 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
  • 5
  • 2
  • 2
  • +1
12 Comments
 
LVL 3

Accepted Solution

by:
scn earned 125 total points
Comment Utility
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 125 total points
Comment Utility
#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
Comment Utility
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
 
LVL 12

Expert Comment

by:paullamhkg
Comment Utility
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
Comment Utility
did these programs work. let us know the results.
0
Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

 
LVL 24

Expert Comment

by:shivsa
Comment Utility
Hi Mahesha,

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

Expert Comment

by:shivsa
Comment Utility
I think i answered this questions.
0
 
LVL 12

Expert Comment

by:paullamhkg
Comment Utility
suggest points split for all
0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
Comment Utility
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
Comment Utility
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
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 navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

763 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now