Solved

Getting CPU, Memory, etc

Posted on 2001-08-21
5
321 Views
Last Modified: 2013-12-27
Hi experts,

  Does anyone know how can I get the CPU and Memory values from a Sparc with Solaris using C or C++? (Like SAR or perfmeter X Application)
  Do I need to open the kernel structure?
  How can I do that?
  I would appreciate C/C++ source code.

  Thanks in advance

  Leandro
0
Comment
Question by:leandro
5 Comments
 
LVL 3

Expert Comment

by:interiot
Comment Utility
I ran "truss uname -a" to watch what system calls it was making to determine the output of uname.  Turns out it calls sysinfo(2) several times.  The manpage is here:

    http://ist-socrates.berkeley.edu/cgi-bin/man.cgi?section=2&topic=sysinfo

And here's a code snippet I found elsewhere:

#include     <sys/systeminfo.h>
#include     <errno.h>
#include     <stdio.h>

#define     BUFF_SIZE     8192
main ()
{
     char     lBuff [BUFF_SIZE];

        long    lResult;
        errno   = 0;
        lResult = sysinfo (SI_ARCHITECTURE, lBuff, BUFF_SIZE);
        if (lResult != -1)
                 (void) printf ("sysinfo (SI_ARCHITECTURE)       = %s\\n", lBuff);
        else
                 (void) printf ("sysinfo (SI_ARCHITECTURE)       = -1, errno = %d\\n", lResult, errno);
}


There's also sysconf(3C):  http://www.bsn.com:8080/cgi-bin/htmlman?sysconf(3C)
0
 

Author Comment

by:leandro
Comment Utility
This is not exactly I want.
I wanna get the CPU and Memory load values, ie, which CPU and Memory percentage are been used for my machine.
0
 

Expert Comment

by:smartino
Comment Utility
Here is a link to the perfmeter source code. Maybe it can give you some hints.

"http://wuarchive.wustl.edu/graphics/graphics/packages/misc/?M=A"
0
 
LVL 20

Expert Comment

by:tfewster
Comment Utility
No comment has been added lately, so it's time to clean up this Topic Area.
I will leave a recommendation for this question in the Cleanup topic area as follows:

- PAQ & refund points

Please leave any comments here within the next 7 days

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !

tfewster
Cleanup Volunteer
0
 

Accepted Solution

by:
SpideyMod earned 0 total points
Comment Utility
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
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…

762 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

15 Experts available now in Live!

Get 1:1 Help Now