handle processes that may have gone away

This commit is contained in:
Doug MacEachern 2008-11-26 01:08:02 +00:00
parent c00dd5aec9
commit bdd27d6f36
1 changed files with 6 additions and 1 deletions

View File

@ -83,7 +83,12 @@ public class Top {
String cpuPerc = "?"; String cpuPerc = "?";
List info = Ps.getInfo(sigar, pid); List info;
try {
info = Ps.getInfo(sigar, pid);
} catch (SigarException e) {
continue; //process may have gone away
}
try { try {
ProcCpu cpu = sigar.getProcCpu(pid); ProcCpu cpu = sigar.getProcCpu(pid);
cpuPerc = CpuPerc.format(cpu.getPercent()); cpuPerc = CpuPerc.format(cpu.getPercent());