1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.miloss.fgsms.osagent;
17
18 import org.hyperic.sigar.SigarException;
19 import org.hyperic.sigar.SigarNotImplementedException;
20 import org.hyperic.sigar.SigarPermissionDeniedException;
21 import org.hyperic.sigar.ProcFd;
22 import org.hyperic.sigar.ProcExe;
23 import org.hyperic.sigar.cmd.Shell;
24
25
26
27
28 public class ProcFileInfo extends SigarCommandBase implements Closable{
29
30 public ProcFileInfo(Shell shell) {
31 super(shell);
32 }
33
34 public ProcFileInfo() {
35 super();
36 }
37
38
39 public long GetOpenFileCount(String processname) throws SigarException {
40 long[] pids = this.shell.findPids(processname);
41 if (pids == null || pids.length == 0) {
42 return -1;
43 }
44 long openfiles = 0;
45
46 for (int i = 0; i < pids.length; i++) {
47 try {
48 ProcFd fd = sigar.getProcFd(pids[i]);
49 println("open file descriptors=" + fd.getTotal());
50 } catch (SigarNotImplementedException e) {
51 }
52 }
53 return openfiles;
54 }
55
56 @Override
57 public void close() throws Exception{
58 if (sigar != null) {
59 sigar.close();
60 sigar = null;
61 }
62 }
63 @Override
64 protected void finalize() throws Throwable
65 {
66
67 if (sigar != null) {
68 System.out.println("WARN,. finalize called without closing sigar first"+ this.getClass().getCanonicalName());
69 sigar.close();
70 }
71 super.finalize();
72 }
73 }