LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   How can I get the system's cpu Load Average by c. (https://www.linuxquestions.org/questions/programming-9/how-can-i-get-the-system%27s-cpu-load-average-by-c-309875/)

davyzhang 04-05-2005 04:37 AM

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 !

bigearsbilly 04-05-2005 04:43 AM

uptime

It's probably in /proc somewhere.

alred 04-05-2005 08:50 AM

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

davyzhang 04-05-2005 10:04 PM

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 ?

Tinkster 04-05-2005 10:15 PM

Copy your program to the remote computer and
run it there?



Cheers,
Tink

davyzhang 04-06-2005 12:32 AM

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 ?

alred 04-06-2005 05:55 AM

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

Tinkster 04-06-2005 01:17 PM

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

expeliarmus 08-02-2007 12:21 AM

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

Lothar Schwab 08-02-2007 12:33 AM

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.

SPF 08-02-2007 12:44 AM

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');

?>

edenCC 08-02-2007 01:14 AM

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]

expeliarmus 08-03-2007 07:51 AM

thanks a lot guys!!


All times are GMT -5. The time now is 04:49 PM.