3

Possible Duplicate:
java cpu usage monitoring

I'm trying to write a program in Java that can shutdown your computer when the computer hasn't been active (like CPU usage) for an amount of time.

I have written a program that can shutdown your pc (windows/mac/linux) after an amount of time. But i don't seem to find a way to check for the CPU usage or inactivity in JAVA.

Can anyone help me pls?

kind regards,

kdlannoy

Community
  • 1
  • 1
kdlannoy
  • 103
  • 1
  • 8
  • See also: http://stackoverflow.com/questions/47177/how-to-monitor-the-computers-cpu-memory-and-disk-usage-in-java and http://stackoverflow.com/questions/6284384/get-memory-and-cpu-usage – assylias Dec 19 '12 at 17:13
  • Low CPU usage is not necessarily a sign of inactivity. – Jordão Dec 19 '12 at 17:24

1 Answers1

1

I'm afraid you probably will have to find a native library. There doesn't appear to be any non-native way of acquiring the CPU usage, however there is support for finding memory usage and other usage indicators.

If you wanted to implement this yourself in a native way, you could look up what terminal command shows you your CPU usage, such as for linux you could execute the top command and then parse through Java.

Tom Cammann
  • 15,343
  • 4
  • 34
  • 47
  • Thx for the quick response. I agree with you it is one way of making it possible, but i don't think with the windows built in termal commands this is possible in any way, nor is the stdout retrievable i think. – kdlannoy Dec 19 '12 at 17:27
  • @kdlannoy on Windows you can repeatedly run `tasklist.exe /V` which displays the CPU time, retrieve and compare the output over time. – assylias Dec 19 '12 at 18:00
  • ty, but i'm looking for a more "beatiful" way to code this. – kdlannoy Jun 15 '13 at 07:53