• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

How can i get the CPU usage through Java program

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi coffeebeans,
I am having the requirement to get the CPU usage of the machine where my java application is running. Not only that, i need to show the memory usage etc., statistics. Is there any solution for this problem.
I can issue a TOP command on linux and get the output but it should be platform independant.
Any help???
Thanx
Ravi Kollepara
 
Ranch Hand
Posts: 1140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't think there is a way for you to get these information using pure Java. There might be some JNI libraries that can get this info, which you can use it in your Java application.
This way, your application will be platform independent, but you need different JNI libs for different platforms.
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No way to do it platform independent, but if you are on Linux, you should know about the proc filesystem. The information you seek and much, much more is available there in a simple text file format. So simple to use you will curse other OS's that keep that information under the hood.
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Google finds the following article: http://www.javaworld.com/javaworld/javaqa/2002-11/01-qa-1108-cpu.html
 
RAVI Kollepara
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi preuss,
But the example says abt win 32 application. Can u give me the JNI example for Linux O/s . Is there any possiblity to give a solution which has to work independant of platform?
Anyway Thanx for showing a window to my problem.
Ravi Kollepara
 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by RAVI Kollepara:
Is there any possiblity to give a solution which has to work independant of platform?


No, there isn't. If you want to use it on different platforms, you will have to write JNI library for every platform. As posted before, on Win32 you can use the Win32 API, and on Linux (and other unices) you can use the proc filesystem to do this.

Regards,
Kris
[ June 21, 2004: Message edited by: Kris Philippaerts ]
 
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks so much Ilja!! I was trying to do just this recently. I asked the question here at the ranch, can't remember where and just got the - you'll need jni response. I now have a solution!!

Thanks,
Aaron R>
 
Ilja Preuss
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're very welcome!
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic