LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-01-2009, 07:58 PM   #1
CoderMan
Member
 
Registered: Jan 2009
Location: Gemini Capsule 25164
Distribution: Gentoo
Posts: 375
Blog Entries: 24

Rep: Reputation: 43
Question C library for *nix system statistics


Is there a convenient C library out there for getting *nix system statistics, like RAM usage, disk usage, CPU load, etc.? I've heard that these stats are all in the proc files, but was hoping to avoid writing code for parsing all that if someone else already had.
 
Old 02-01-2009, 09:40 PM   #2
Guitarist88
Member
 
Registered: Feb 2004
Location: Nz
Posts: 240

Rep: Reputation: 30
I think there is something like <sys/proc.h>.
 
Old 02-01-2009, 11:26 PM   #3
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
It's easy - honest!

Here's a naive, simplistic example of the enormous amount of work needed to "parse" the Linux procfs:
Code:
#include <stdio.h>

int
main (int argc, char *argv[])
{
  FILE *fp = fopen ("/proc/loadavg", "r");
  float a = 0;
  if (!fp)
  {
    perror ("err");
    return 1;
  }
  fscanf (fp, "%f", &a);
  printf ("load avg= %f\n", a);
  fclose (fp);
  return 0;
}
And here's a good tutorial on the subject:
http://www.linuxjournal.com/article/177

'Hope that helps .. PSM
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
System can't find a library that is there dctopcat Linux - Newbie 8 11-17-2008 09:23 AM
System Hardware statistics? Lola Kews Linux - Software 7 10-01-2007 06:19 PM
System monitor/statistics TBKDan Linux - Software 5 01-14-2006 02:28 AM
Does your *nix system participate in a distributed computing project? sether Linux - General 9 12-11-2004 07:01 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:47 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration