handle possible EPERM or ESRCH in MultiProc method

This commit is contained in:
Doug MacEachern 2008-07-13 23:15:08 +00:00
parent 5da628b67b
commit 0fcaf19bb9
2 changed files with 14 additions and 2 deletions

View File

@ -64,7 +64,13 @@ public class MultiProcCpu extends ProcCpu {
cpu.nproc = pids.length;
for (int i=0; i<pids.length; i++) {
ProcTime time = sigar.getProcTime(pids[i]);
ProcTime time;
try {
time = sigar.getProcTime(pids[i]);
} catch (SigarException e) {
//process may have gone away or EPERM
continue;
}
cpu.total += time.total;
cpu.user += time.user;
cpu.sys += time.sys;

View File

@ -31,7 +31,13 @@ public class MultiProcMem extends ProcMem {
long[] pids = ProcessFinder.find(sigar, query);
for (int i=0; i<pids.length; i++) {
ProcMem pmem = sigar.getProcMem(pids[i]);
ProcMem pmem;
try {
pmem = sigar.getProcMem(pids[i]);
} catch (SigarException e) {
//process may have gone away or EPERM
continue;
}
mem.size += pmem.size;
mem.resident += pmem.resident;
if (pmem.share != Sigar.FIELD_NOTIMPL) {