// caution: code is not tested but shows the general approach List<ProcessInformation> processInfo = new ArrayList<>(); String pInfoStr = new String[3]; int processInfoIndex = 0; String[] processInfoHolder = new String[3]; String processInfo = ""; int c; while( (c = reader.read()) != -1 ) { if (Character.isWhitespace(c)) { processInfoHolder[processInfoIndex++] = processInfo; processInfoStr = ""; } else if (c == 10) { // not sure if correct codepoint for whitespace processInfo.add(new ProcessInfo(processInfoHolder)); processInfoIndex = 0; } else { processInfoStr += c; } }
public ProcessInfo getThisProcess() { long self = sigar.getPid(); ProcessInfo info = new ProcessInfo(self); return info; }
public ProcessInfo getThisProcess() { long self = sigar.getPid(); ProcessInfo info = new ProcessInfo(self); return info; }
public List<ProcessInfo> getAllProcesses() { ArrayList<ProcessInfo> processes = new ArrayList<ProcessInfo>(); long[] pids = null; log.debug("Retrieving PIDs of all running processes..."); long startTime = System.currentTimeMillis(); try { pids = sigar.getProcList(); long elapsedTime = System.currentTimeMillis() - startTime; log.debug("Retrieval of " + pids.length + " PIDs took " + elapsedTime + " ms."); // NOTE: Do not close sigarImpl on success, as the ProcessInfos created below will reuse it. } catch (Exception e) { log.warn("Failed to retrieve PIDs of all running processes.", e); } if (pids != null) { for (long pid : pids) { if (log.isTraceEnabled()) { log.trace("Loading process info for pid " + pid + "..."); } ProcessInfo info = new ProcessInfo(pid, sigar); processes.add(info); } } return processes; }
public List<ProcessInfo> getAllProcesses() { ArrayList<ProcessInfo> processes = new ArrayList<ProcessInfo>(); long[] pids = null; log.debug("Retrieving PIDs of all running processes..."); long startTime = System.currentTimeMillis(); try { pids = sigar.getProcList(); long elapsedTime = System.currentTimeMillis() - startTime; log.debug("Retrieval of " + pids.length + " PIDs took " + elapsedTime + " ms."); // NOTE: Do not close sigarImpl on success, as the ProcessInfos created below will reuse it. } catch (Exception e) { log.warn("Failed to retrieve PIDs of all running processes.", e); } if (pids != null) { for (long pid : pids) { if (log.isTraceEnabled()) { log.trace("Loading process info for pid " + pid + "..."); } ProcessInfo info = new ProcessInfo(pid, sigar); processes.add(info); } } return processes; }
/** * Returns a {@link ProcessInfo} instance for the parent of this process. * * This method uses the parent process id which is not static (it can change if the parent process dies before its * child). So in theory it should be moved to the {@link ProcessInfoSnapshot} type. * * In practice, it stays here because the parent {@link ProcessInfo} instance is cached after creation. * * @since 4.4 */ public ProcessInfo getParentProcess() throws SystemInfoException { if (this.parentProcess == null) { this.parentProcess = new ProcessInfo(priorSnaphot().getParentPid(), sigar); } else { this.parentProcess.refresh(); } return this.parentProcess; }
/** * Returns a {@link ProcessInfo} instance for the parent of this process. * * This method uses the parent process id which is not static (it can change if the parent process dies before its * child). So in theory it should be moved to the {@link ProcessInfoSnapshot} type. * * In practice, it stays here because the parent {@link ProcessInfo} instance is cached after creation. * * @since 4.4 */ public ProcessInfo getParentProcess() throws SystemInfoException { if (this.parentProcess == null) { this.parentProcess = new ProcessInfo(priorSnaphot().getParentPid(), sigar); } else { this.parentProcess.refresh(); } return this.parentProcess; }