handle possible EPERM or ESRCH in MultiProc method
This commit is contained in:
parent
5da628b67b
commit
0fcaf19bb9
|
@ -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;
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue