Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 377
  • Last Modified:

Getting proccessor speed and Memory size from program.

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
mahesha_krpet
Asked:
mahesha_krpet
  • 5
  • 2
  • 2
  • +1
2 Solutions
 
scnCommented:
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
 
shivsaCommented:
#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
 
shivsaCommented:
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
paullamhkgCommented:
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
 
shivsaCommented:
did these programs work. let us know the results.
0
 
shivsaCommented:
Hi Mahesha,

any update, did the programs worked. if worked please accept the answer
0
 
shivsaCommented:
I think i answered this questions.
0
 
paullamhkgCommented:
suggest points split for all
0
 
Karl Heinz KremerCommented:
Paul, the question was about getting this information via a system call, so using top is IMHO not an acceptable answer.
0
 
Karl Heinz KremerCommented:
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

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

  • 5
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now