Using Java runtime
I'm new to the linux world and its been quit sometime since i've done any programming. However, I'm writing a program which simply calculates the load average of a process. In doing this I need to use the uptime command for linux in a java program. I've done a little bit of searching on the net and it mentions this is possiable by using java runtime command. Unfortunatly though I have yet to find a working example of this. I've tried just simply reading the /proc/uptime file but I have no clue how to format the 2 numbers in seconds to make it the same as if you just typed in uptime in the linux command prompt.
I would love to post my code that i have so far but once agian i'm new to linux and haven't figured out how to download files from the server yet so if someone would help me out there it be greatly appreciated. I'm lost... please help! |
Easier still: just use Java I/O. Open and read from /proc/uptime exactly as you would any text file.
Simple as that :) |
Quote:
01:22:05 up 223 days, 4:57, 1 user, load average: 0.00, 0.00, 0.00 However if I use the following function to read/print the /proc/uptime file Code:
public void printFile(String fileName){ I've figured out that the first number represents the uptime in seconds... not sure what the second one is though(i'm assuming its idletime?) nor how to format these so that they appear the same as using uptime directly from the shell... better yet I need to be able to use these times for calculation. Here is the basic skeleton of the program of what I want it to do: -read /proc/uptime; store as startTotaltime & startIdletime -call a function that places a load on the system (really it will just be some random math calculation over and overagian) -read /proc/uptime agian; store as endTotaltime & endIdletime -Calculate the percentage of time that CPU was busy during the program |
All times are GMT -5. The time now is 12:22 PM. |