Solved

Getting proccessor speed and Memory size from program.

Posted on 2003-11-20
12
355 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
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 125 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
linux pull logs and export FTP 4 71
is my large folder zipped corrupted 4 67
android secure ftp 3 38
Using sort and uniq to pare down large syslog 6 35
This is the error message I got (CODE) Error caused by incompatible libmp3lame 3.98-2 with ffmpeg I've googled this error message and found out sometimes it attaches this note "can be treated with downgrade libmp3lame to version 3.97 or 3.98" …
Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

831 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