Find the answer to your Linux question:
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 12
does any one know...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Apr 2007
    Posts
    3

    c program in linux for finding the cpu utilization


    does any one know

  2. #2
    Linux Guru sdousley's Avatar
    Join Date
    Feb 2004
    Posts
    1,790
    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

  3. #3
    Linux Guru sdousley's Avatar
    Join Date
    Feb 2004
    Posts
    1,790
    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

  4. #4
    Just 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.....

  5. #5
    Linux Newbie dilbert's Avatar
    Join Date
    Sep 2006
    Location
    Yorkshire, GB
    Posts
    237
    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.

  6. #6
    Just 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

  7. #7
    Just Joined!
    Join Date
    May 2005
    Posts
    21
    one of the easiest method is to put system command present in stdlib.h

  8. #8
    Just 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.

  9. #9
    Linux Guru Lakshmipathi's Avatar
    Join Date
    Sep 2006
    Location
    3rd rock from sun - Often seen near moon
    Posts
    1,738

    Smile

    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

  10. #10
    Linux Newbie theNbomr's Avatar
    Join Date
    May 2007
    Location
    BC Canada
    Posts
    155
    The virtual file /proc/stat has the information, although you will have to do a small amount of arithmetic to create a '% CPU" figure.
    Code:
    man proc
    for details
    --- rod.
    Stuff happens. Then stays happened.

Page 1 of 2 1 2 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •