LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 06-08-2004, 06:39 AM   #1
t_sunil_kumar
LQ Newbie
 
Registered: Jun 2004
Posts: 1

Rep: Reputation: 0
how to get "load average" using a program


Hi friends,

My system is Red hat linux 6.2, kernel 2.2.14. Through a C program, I want to get the "load average" that is shown by "top" command in its first line (load average: 0.19, 0.36, 0.41)

Please help me if any system call is available to get this.

Regards,
-Sunil
 
Old 06-08-2004, 10:43 AM   #2
Technoslave
Member
 
Registered: Dec 2003
Location: Northern VA
Posts: 493

Rep: Reputation: 30
cat /proc/loadavg
 
Old 06-08-2004, 10:51 AM   #3
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
..and in C that would be something like:
Code:
#include <stdio.h>

#define LEN 14

int main()
{
	 FILE *fp;
	 char str[LEN+1];

	 if ((fp = fopen("/proc/loadavg", "r")) == NULL) {
		  perror("");
		  return 1;
	 }
	 if (fread(str, 1, LEN, fp) != LEN) {
		  fprintf(stderr, "Error reading loadavg\n");
		  return 2;
	 }
	 str[LEN] = '\0';
	 printf("load average: %s\n", str);
	 return 0;
}
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Flash won't load in Konqueror - "Unable to load Netscape plugin" rollo Linux - Software 2 09-10-2005 12:28 PM
C -communicating with system("ftp"); using "program|ftp>>myfifo" probably hansschmucker Programming 1 03-23-2005 01:39 PM
Getting error: "ALSA device "default" is already in use by another program." brynjarh Debian 7 02-04-2005 11:45 AM
"Failed to load module "i915"" Kane635 Linux - Software 0 11-22-2004 08:17 PM
"User" & "System" CPU load difference JJX Linux - General 3 06-06-2004 01:42 AM

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

All times are GMT -5. The time now is 05:24 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