public void output(String[] args) throws SigarException { for (int i=0; i<args.length; i++) { String exe = args[i]; if (new File(exe).exists()) { output(exe); } else { long[] pids = this.shell.findPids(exe); for (int j=0; j<pids.length; j++) { try { output(sigar.getProcExe(pids[j]).getName()); } catch (SigarException e) { println(exe + ": " + e.getMessage()); } } } } }
public void output(long pid) throws SigarException { println("pid=" + pid); try { ProcFd fd = sigar.getProcFd(pid); println("open file descriptors=" + fd.getTotal()); } catch (SigarNotImplementedException e) {} ProcExe exe = sigar.getProcExe(pid); String name = exe.getName(); if (name.length() == 0) { name = "unknown"; } println("name=" + name); println("cwd=" + exe.getCwd()); }
public void output(long pid) throws SigarException { String[] argv = this.proxy.getProcArgs(pid); try { String exe = this.proxy.getProcExe(pid).getName(); println("exe=" + exe); } catch (SigarNotImplementedException e) { } catch (SigarException e) { println("exe=???"); } try { String cwd = this.proxy.getProcExe(pid).getCwd(); println("cwd=" + cwd); } catch (SigarNotImplementedException e) { } catch (SigarException e) { println("cwd=???"); } for (int i=0; i<argv.length; i++) { println(" " + i + "=>" + argv[i] + "<="); } }
protected void resolveExecIfNeeded() { if (!_execResolved) { try { final ProcExe procExe = _sigar.getProcExe(_pid); final String name = procExe.getName(); final File file = new File(name); if (file.isFile()) { _executable = file; } } catch (final SigarException ignored) {} _execResolved = true; } }
private String determineName(String[] procArgs, ProcExe procExe, ProcState procState) { String name; if ((procArgs != null) && (procArgs.length != 0)) { name = procArgs[0]; } else if ((procExe != null) && (procExe.getName() != null)) { name = procExe.getName(); } else if ((procState != null) && (procState.getName() != null)) { name = procState.getName(); } else { name = UNKNOWN_PROCESS_NAME; } return name; }
private String determineName(String[] procArgs, ProcExe procExe, ProcState procState) { String name; if ((procArgs != null) && (procArgs.length != 0)) { name = procArgs[0]; } else if ((procExe != null) && (procExe.getName() != null)) { name = procExe.getName(); } else if ((procState != null) && (procState.getName() != null)) { name = procState.getName(); } else { name = UNKNOWN_PROCESS_NAME; } return name; }
public Object doMonitor(Map<String, Object> params) throws Exception { Map<String, Object> result = new HashMap<>(); ProcExe procExe = SigarFactory.getSigar().getProcExe(SigarFactory.getSigar().getPid()); result.put("cmd", procExe.getCwd()); result.put("name", procExe.getName()); result.put("inputArguments", ManagementFactory.getRuntimeMXBean().getInputArguments()); return result; }
private long getPIDByProcName(String name, long index) { int procIndex = 0; long[] list; ProcExe proc; try { list = sigar.getProcList(); } catch (SigarException ex) { log.error("Failed to get process list", ex); return -1; } for (int n = 0; n < list.length; n++) { try { proc = sigar.getProcExe(list[n]); } catch (SigarException e) { log.debug("Can't get process exe for pid " + list[n], e); continue; } // case insensitive match String pname = proc.getName().toLowerCase(); if (pname.endsWith(File.separator + name.toLowerCase())) { if (procIndex == index) { return list[n]; } procIndex++; } } return -1; }
private long getPIDByProcName(String name, long index) { int procIndex = 0; long[] list; ProcExe proc; try { list = sigar.getProcList(); } catch (SigarException ex) { log.error("Failed to get process list", ex); return -1; } for (int n = 0; n < list.length; n++) { try { proc = sigar.getProcExe(list[n]); } catch (SigarException e) { log.debug("Can't get process exe for pid " + list[n], e); continue; } // case insensitive match String pname = proc.getName().toLowerCase(); if (pname.endsWith(File.separator + name.toLowerCase())) { if (procIndex == index) { return list[n]; } procIndex++; } } return -1; }