Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inactivity meter [duplicate]

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

like image 487
kdlannoy Avatar asked May 01 '26 19:05

kdlannoy


1 Answers

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.

like image 126
Tom Cammann Avatar answered May 04 '26 07:05

Tom Cammann