use of org.hyperic.sigar.SigarException in project scheduling by ow2-proactive.
the class SigarProcesses method getProcesses.
@SuppressWarnings("unchecked")
@Override
public ProcessInfo[] getProcesses() throws SigarException {
Sigar sigar = new Sigar();
long[] pids = sigar.getProcList();
List<ProcessInfo> result = new ArrayList<>(pids.length);
for (int i = 0; i < pids.length; i++) {
long pid = pids[i];
try {
@SuppressWarnings("rawtypes") List // Add standard info.
info = Ps.getInfo(sigar, pid);
// Add also arguments of each process.
info.add(sigar.getProcArgs(pid));
// Add cpu usage (perc.).
info.add(sigar.getProcCpu(pid).getPercent());
result.add(new ProcessInfo(info));
} catch (SigarException e) {
// Ignore it, probably the process does not exist anymore.
logger.warn("Could not get information for PID " + pid + ": " + e.getMessage());
}
// TODO see why sigar.getProcCpu(pid).getPercent()
// returns '0.0' always.
}
return result.toArray(new ProcessInfo[] {});
}
Aggregations