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(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()); } } } } }
/** * @return null if process executable or cwd is unavailable. Otherwise the Cwd as returned from the * process executable. * @throws SystemInfoException */ public String getCurrentWorkingDirectory() throws SystemInfoException { String result = null; try { if (null != ProcessInfo.this.procExe) { result = ProcessInfo.this.procExe.getCwd(); } } catch (Exception e) { ProcessInfo.this.handleSigarCallException(e, "procExe.getCwd()"); } return result; }
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; } }
/** * @return null if process executable or cwd is unavailable. Otherwise the Cwd as returned from the * process executable. * @throws SystemInfoException */ public String getCurrentWorkingDirectory() throws SystemInfoException { String result = null; try { if (null != ProcessInfo.this.procExe) { result = ProcessInfo.this.procExe.getCwd(); } } catch (Exception e) { ProcessInfo.this.handleSigarCallException(e, "procExe.getCwd()"); } return result; }
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] + "<="); } }
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 File getAbsoluteFile(File file) { File absoluteFile; if (!file.isAbsolute()) { if ((this.process != null) && (this.process.getExecutable() != null)) { String cwd = this.process.getExecutable().getCwd(); absoluteFile = new File(cwd, file.getPath()); } else { String homeDir = getSystemProperties().get(HOME_DIR_SYSPROP); if (homeDir != null) { File binDir = new File(homeDir, "bin"); absoluteFile = new File(binDir, file.getPath()); } else { LOG.error("Failed to resolve relative properties file path [" + file + "]."); return null; } } } else { absoluteFile = file; } return absoluteFile; }
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 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; }
protected File getHomeDir(ProcessInfo processInfo, JavaCommandLine javaCommandLine) { String home = javaCommandLine.getSystemProperties().get(HOME_DIR_SYSPROP); File homeDir = new File(home); if (!homeDir.isAbsolute()) { if (processInfo.priorSnaphot().getExecutable() == null) { throw new RuntimeException(HOME_DIR_SYSPROP + " for AS7 process " + processInfo + " is a relative path, and the RHQ Agent process does not have permission to resolve it."); } String cwd = processInfo.priorSnaphot().getExecutable().getCwd(); homeDir = new File(cwd, home); } return new File(FileUtils.getCanonicalPath(homeDir.getPath())); }
protected File getLogDir(ProcessInfo process, AS7CommandLine commandLine, File baseDir) { String logDirString = commandLine.getSystemProperties().get(getLogDirSystemPropertyName()); File logDir; if (logDirString != null) { logDir = new File(logDirString); if (!logDir.isAbsolute()) { if (process.priorSnaphot().getExecutable() == null) { throw new RuntimeException(getLogDirSystemPropertyName() + " for AS7 process " + process + " is a relative path, and the RHQ Agent process does not have permission to resolve it."); } String cwd = process.priorSnaphot().getExecutable().getCwd(); logDir = new File(cwd, logDirString); } logDir = new File(FileUtils.getCanonicalPath(logDir.getPath())); } else { logDir = new File(baseDir, getDefaultLogDirName()); } return logDir; }
String cwd = parentProcessExe.getCwd(); startScriptFile = new File(cwd, startScriptFile.getPath()); startScriptFile = new File(FileUtils.getCanonicalPath(startScriptFile.getPath()));
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; }
protected File getBaseDir(ProcessInfo process, JavaCommandLine javaCommandLine, File homeDir) { String baseDirString = javaCommandLine.getSystemProperties().get(getBaseDirSystemPropertyName()); File baseDir; if (baseDirString != null) { baseDir = new File(baseDirString); if (!baseDir.isAbsolute()) { if (process.priorSnaphot().getExecutable() == null) { baseDir = new File(homeDir, baseDirString); if (!baseDir.exists()) { throw new RuntimeException(getBaseDirSystemPropertyName() + " for AS7 process " + process + " is a relative path, and the RHQ Agent process does not have permission to resolve it."); } } else { String cwd = process.priorSnaphot().getExecutable().getCwd(); baseDir = new File(cwd, baseDirString); if (!baseDir.exists()) { baseDir = new File(homeDir, baseDirString); } } } baseDir = new File(FileUtils.getCanonicalPath(baseDir.getPath())); } else { baseDir = new File(homeDir, getDefaultBaseDirName()); } return baseDir; }
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; }
protected File getConfigDir(ProcessInfo process, JavaCommandLine javaCommandLine, File baseDir) { String configDirString = javaCommandLine.getSystemProperties().get(getConfigDirSystemPropertyName()); File configDir; if (configDirString != null) { configDir = new File(configDirString); if (!configDir.isAbsolute()) { if (process.priorSnaphot().getExecutable() == null) { throw new RuntimeException(getConfigDirSystemPropertyName() + " for AS7 process " + process + " is a relative path, and the RHQ Agent process does not have permission to resolve it."); } String cwd = process.priorSnaphot().getExecutable().getCwd(); configDir = new File(cwd, configDirString); } configDir = new File(FileUtils.getCanonicalPath(configDir.getPath())); } else { configDir = new File(baseDir, getDefaultConfigDirName()); } return configDir; }