Here the code I am using for testing this on solaris spar system.
uname -a
SunOS cl-test-t5220-1-vm1 5.10 Generic_141414-02 sun4v sparc SUNW,SPARC-Enterprise-T5220
Please let me know if there is any issue in this code or why processTime is returning future time
import org.hyperic.sigar.Cpu;
import org.hyperic.sigar.CpuPerc;
import org.hyperic.sigar.FileSystem;
import org.hyperic.sigar.FileSystemUsage;
import org.hyperic.sigar.Mem;
import org.hyperic.sigar.Sigar;
import org.hyperic.sigar.SigarException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
public class Test{
public static void main(String args[])
{
System.out.println("Inside main method");
Sigar sigar;
// process id of current process
long pid;
sigar = new Sigar();
// pid = 14956;
pid = sigar.getPid();
System.out.println("Pid : " +pid);
try{
System.out.println("Inside try block....");
long processStarttime = sigar.getProcTime(pid).getStartTime();
double uptime = sigar.getUptime().getUptime();
System.out.println("System Up time time in millis : " + uptime
+ " Uptime in date = " + toDate((long)uptime));
System.out.println("Process Start time in millis : " + processS
tarttime + " in Date Format : " + toDate(processStarttime));
long systemCurTime = System.currentTimeMillis()
;
System.out.println("System Current time : " + systemCurTime + "
In Date Format " + toDate(systemCurTime));
long processUptime = systemCurTime-processStarttime;
System.out.println("Process upTime : "+processUptime);
}
catch(SigarException e)
{
System.out.println("Sigar Exception ..." +e);
}
}
private static String toDate(long millis) {
DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss.SS
S");
//long now = System.currentTimeMillis();
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(millis);
// System.out.println(now + " = " + formatter.format(calendar.getTime(
)));
return (formatter.format(calendar.getTime()));
}
}
Output:
Inside main method
Pid : 16628
Inside try block....
System Up time time in millis : 1068307.0 Uptime in date = 31/12/1969 07:17:48.307
Process Start time in millis : 1330434543000 in Date Format : 28/02/2012 08:09:03.000
System Current time : 1321555976635 In Date Format 17/11/2011 01:52:56.635
Process upTime : -8878566365
Note the process Start time is in Future time.
uname -a
SunOS cl-test-t5220-1-vm1 5.10 Generic_141414-02 sun4v sparc SUNW,SPARC-Enterprise-T5220
Please let me know if there is any issue in this code or why processTime is returning future time
import org.hyperic.sigar.Cpu;
import org.hyperic.sigar.CpuPerc;
import org.hyperic.sigar.FileSystem;
import org.hyperic.sigar.FileSystemUsage;
import org.hyperic.sigar.Mem;
import org.hyperic.sigar.Sigar;
import org.hyperic.sigar.SigarException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
public class Test{
public static void main(String args[])
{
System.out.println("Inside main method");
Sigar sigar;
// process id of current process
long pid;
sigar = new Sigar();
// pid = 14956;
pid = sigar.getPid();
System.out.println("Pid : " +pid);
try{
System.out.println("Inside try block....");
long processStarttime = sigar.getProcTime(pid).getStartTime();
double uptime = sigar.getUptime().getUptime();
System.out.println("System Up time time in millis : " + uptime
+ " Uptime in date = " + toDate((long)uptime));
System.out.println("Process Start time in millis : " + processS
tarttime + " in Date Format : " + toDate(processStarttime));
long systemCurTime = System.currentTimeMillis()
;
System.out.println("System Current time : " + systemCurTime + "
In Date Format " + toDate(systemCurTime));
long processUptime = systemCurTime-processStarttime;
System.out.println("Process upTime : "+processUptime);
}
catch(SigarException e)
{
System.out.println("Sigar Exception ..." +e);
}
}
private static String toDate(long millis) {
DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss.SS
S");
//long now = System.currentTimeMillis();
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(millis);
// System.out.println(now + " = " + formatter.format(calendar.getTime(
)));
return (formatter.format(calendar.getTime()));
}
}
Output:
Inside main method
Pid : 16628
Inside try block....
System Up time time in millis : 1068307.0 Uptime in date = 31/12/1969 07:17:48.307
Process Start time in millis : 1330434543000 in Date Format : 28/02/2012 08:09:03.000
System Current time : 1321555976635 In Date Format 17/11/2011 01:52:56.635
Process upTime : -8878566365
Note the process Start time is in Future time.