Solved

Getting proccessor speed and Memory size from program.

Posted on 2003-11-20
12
356 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Setting up two Raspberry Pi gateways/routers 3 82
Linux VM 6 101
Apache LDAP Authentication 20 24
Syslog-ng works. Now what? How to filter and manage? 8 56
Network Interface Card (NIC) bonding, also known as link aggregation, NIC teaming and trunking, is an important concept to understand and implement in any environment where high availability is of concern. Using this feature, a server administrator …
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 …
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 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…

809 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