LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 04-05-2005, 04:37 AM   #1
davyzhang
LQ Newbie
 
Registered: Feb 2005
Location: china
Posts: 8

Rep: Reputation: 0
How can I get the system's cpu Load Average by c.


How can I get the information of cpu load average by any way.
Use 'top' can see the information on top. But ,how can I get it or make it use programming.
How dose the value of cpu load average make?
Can you help me ? Thanks !

Last edited by davyzhang; 04-05-2005 at 05:08 AM.
 
Old 04-05-2005, 04:43 AM   #2
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Slack, Debian, Mint, Puppy, Raspbian
Posts: 3,465

Rep: Reputation: 220Reputation: 220Reputation: 220
uptime

It's probably in /proc somewhere.
 
Old 04-05-2005, 08:50 AM   #3
alred
Member
 
Registered: Mar 2005
Location: singapore
Distribution: puppy and Ubuntu and ... erh ... redhat(sort of) :( ... + the venerable bsd and solaris ^_^
Posts: 658
Blog Entries: 8

Rep: Reputation: 31
you may try

Code:
 

double load[3];  
    
   if (getloadavg(load, 3) != -1)
   {  
   printf("load average : %f , %f , %f\n", load[0],load[1],load[2]);
   }
read man 3 getloadavg

::note:it may not work on your machine

Last edited by alred; 04-05-2005 at 11:52 AM.
 
Old 04-05-2005, 10:04 PM   #4
davyzhang
LQ Newbie
 
Registered: Feb 2005
Location: china
Posts: 8

Original Poster
Rep: Reputation: 0
how can I get the remote computer's load average?

Thank you very much ,alred.
If I want to know the remote computer's load average.
How can I do ?
 
Old 04-05-2005, 10:15 PM   #5
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 912Reputation: 912Reputation: 912Reputation: 912Reputation: 912Reputation: 912Reputation: 912Reputation: 912
Copy your program to the remote computer and
run it there?



Cheers,
Tink
 
Old 04-06-2005, 12:32 AM   #6
davyzhang
LQ Newbie
 
Registered: Feb 2005
Location: china
Posts: 8

Original Poster
Rep: Reputation: 0
I am sorry , I mean , the program has to run in my computer and I want to get the remote computer's load average.
I can not log on the remote computer, I can just visit it . I know it's IP and I have been got the information of it's MIB.
How can i do ?

Last edited by davyzhang; 04-06-2005 at 01:53 AM.
 
Old 04-06-2005, 05:55 AM   #7
alred
Member
 
Registered: Mar 2005
Location: singapore
Distribution: puppy and Ubuntu and ... erh ... redhat(sort of) :( ... + the venerable bsd and solaris ^_^
Posts: 658
Blog Entries: 8

Rep: Reputation: 31
just a random possibility , at last resort you may try

netcat

look at the examples scripts then might be able to execute netcat script through coding


for a more serious ones , you may try looking for snmp socket libraries
at freashmeat or sourceforge
 
Old 04-06-2005, 01:17 PM   #8
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 912Reputation: 912Reputation: 912Reputation: 912Reputation: 912Reputation: 912Reputation: 912Reputation: 912
http://www.securityfocus.com/tools/137
Is netcat's official home ...

And that said: to make any use of netcat in that
scenario you'd still need some sort of server-
process on the remote machine that will output
info on an arbitrary port that nc can listen on.



Cheers,
Tink

Last edited by Tinkster; 04-06-2005 at 01:29 PM.
 
Old 08-02-2007, 12:21 AM   #9
expeliarmus
LQ Newbie
 
Registered: Jul 2007
Posts: 17

Rep: Reputation: 0
does killing child processes reduce CPU load average??

Hi,
am using a program that forks child processes to increase CPU load.this seems to work,but when I try killing the child processes the load doesnot seem to decrease.Does killing child processes decrease CPU load average?????
regards,
expeliarmus
 
Old 08-02-2007, 12:33 AM   #10
Lothar Schwab
LQ Newbie
 
Registered: Aug 2007
Location: Minnesota, USA
Distribution: Lubuntu
Posts: 19

Rep: Reputation: 2
Quote:
Originally Posted by expeliarmus
Hi,
am using a program that forks child processes to increase CPU load.this seems to work,but when I try killing the child processes the load doesnot seem to decrease.Does killing child processes decrease CPU load average?????
regards,
expeliarmus
There is no general answer. It depends on whether
your applications are:
- CPU bound or
- I/O bound or
- synchronizing with each other is some way

In other words: where is the bottleneck? Is it
CPU or I/O or latency time because the processes
wait for each other (or even deadlock).

Without a clear understanding of these questions
you cannot meaningfully discuss your question.
 
Old 08-02-2007, 12:44 AM   #11
SPF
Member
 
Registered: Jul 2007
Location: /home
Distribution: Debian
Posts: 37

Rep: Reputation: 15
You could also make a php webpage with the load information. But you must be allowed to run external programs from php scripts:

<?

echo exec('cat /proc/loadavg');

// or

echo exec('uptime');

?>
 
Old 08-02-2007, 01:14 AM   #12
edenCC
Member
 
Registered: May 2006
Location: China
Distribution: Debian
Posts: 198
Blog Entries: 1

Rep: Reputation: 32
Also you have a try to use a monitor application.
like zabbix(www.zabbix.com):
when the client is running on a remotely machine, you can use the following command to get when exactly you want, e.g. :

# the avarage CPU load
bin/get -s IP_HERE -p10051 -k system.cpu[load1]

# the avaliable partition volume for '/'
bin/get -s IP_HERE -p10051 -k vfs.fs.size[/,free]

#the inbound transfer
bin/get -s IP_HERE -p10051 -k net.if.in[eth0]
 
Old 08-03-2007, 07:51 AM   #13
expeliarmus
LQ Newbie
 
Registered: Jul 2007
Posts: 17

Rep: Reputation: 0
thanks a lot guys!!
 
  


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
Qmail problems - CPU load average rising too high xbaez Linux - Software 0 11-16-2005 12:23 PM
load average? ampex189 Linux - Newbie 2 03-06-2005 07:17 PM
RH8 Load Average High - No CPU Utilization jj91709 Red Hat 2 08-29-2004 12:28 AM
Load average stuck at 7.00, CPU usage ~ 0.1%, what gives? BrianK Linux - General 4 02-16-2004 08:45 PM
Average load Cyth Linux - General 1 01-22-2002 03:33 PM

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

All times are GMT -5. The time now is 07:14 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration