Results 1 to 10 of 12
does any one know...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 04-18-2007 #1Just Joined!
- Join Date
- Apr 2007
- Posts
- 3
c program in linux for finding the cpu utilization
does any one know
- 04-18-2007 #2
you could use "top" from the command line. that shows CPU utilisation, as well as memory usage and updates (relatively) real time.
"I am not an alcoholic, alcoholics go to meetings"
Registered Linux user = #372327
- 04-18-2007 #3
you could use "top" from the command line. that shows CPU utilisation, as well as memory usage and updates (relatively) real time.
To Mods: Sorry, accidentally hit post twice, someone delete the dupe here. Ta."I am not an alcoholic, alcoholics go to meetings"
Registered Linux user = #372327
- 04-19-2007 #4Just Joined!
- Join Date
- Apr 2007
- Posts
- 3
i need only c program...
no command ......
any one know function for that top command how its calling.....
- 04-19-2007 #5
Here again I dare to advertise my C code snippets from here:
http://www.linuxforums.org/forum/lin...0-link-ip.html
Instead of the "ifconfig" command you can use every shell command with the popen C function.
Use then "awk" or something similar to break up the string from the shell into the appropriate pieces.
Those code snippets are from test programs I've written only for use within our lab. So, there might be more secure or versatile solutions. With more effort on the C code side you could also omit "awk".
There might be also further info from the proc file system regarding the cpu usage. If so, you could use this probabably easier than "top".Bus Error: Passengers dumped. Hech gap yo'q.
- 04-20-2007 #6Just Joined!
- Join Date
- Apr 2007
- Posts
- 3
i need the cpu utilization percentage progam in c ...... i dont need the command "top" for that ...
to see all information
- 04-20-2007 #7Just Joined!
- Join Date
- May 2005
- Posts
- 21
one of the easiest method is to put system command present in stdlib.h
- 05-29-2007 #8Just Joined!
- Join Date
- May 2007
- Posts
- 3
u can get the source code of top to study it.
i can roughly tell u how to do the cpu utilization code.
the easiest way is ... same as what top does.
read infomation in /proc
and grab some numberical date from respective files and manipulate them.
then u r on ur way to get what u want.
for proc file system u might want to refer
The /proc filesystem
or u just check the wikipedia website to get some info on proc file system.
it is nice to know some info on proc.
good luck.
- 05-30-2007 #9
i agree..better open /proc file via c program and read the required info. from there.
First they ignore you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
-----
FOSS India Award winning ext3fs Undelete tool www.giis.co.in. Online Linux Terminal http://www.webminal.org
- 06-09-2007 #10
The virtual file /proc/stat has the information, although you will have to do a small amount of arithmetic to create a '% CPU" figure.
for detailsCode:man proc
--- rod.Stuff happens. Then stays happened.


Reply With Quote
