org.hyperic.sigar.ptql.ProcessFinder Java Examples
The following examples show how to use
org.hyperic.sigar.ptql.ProcessFinder.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SigarProcessManager.java From kkFileViewOfficeEdit with Apache License 2.0 | 6 votes |
public long findPid(ProcessQuery query) throws IOException { Sigar sigar = new Sigar(); try { long[] pids = ProcessFinder.find(sigar, "State.Name.eq=" + query.getCommand()); for (int i = 0; i < pids.length; i++) { String[] arguments = sigar.getProcArgs(pids[i]); if (arguments != null && argumentMatches(arguments, query.getArgument())) { return pids[i]; } } return PID_NOT_FOUND; } catch (SigarException sigarException) { throw new IOException("findPid failed", sigarException); } finally { sigar.close(); } }
Example #2
Source File: SigarProcessManager.java From kkFileView with Apache License 2.0 | 6 votes |
public long findPid(ProcessQuery query) throws IOException { Sigar sigar = new Sigar(); try { long[] pids = ProcessFinder.find(sigar, "State.Name.eq=" + query.getCommand()); for (int i = 0; i < pids.length; i++) { String[] arguments = sigar.getProcArgs(pids[i]); if (arguments != null && argumentMatches(arguments, query.getArgument())) { return pids[i]; } } return PID_NOT_FOUND; } catch (SigarException sigarException) { throw new IOException("findPid failed", sigarException); } finally { sigar.close(); } }
Example #3
Source File: MetricParamsSigar.java From perfmon-agent with Apache License 2.0 | 6 votes |
private long getPIDByPTQL(String token) { String query = token.substring(token.indexOf("=") + 1); try { final ProcessFinder finder = new ProcessFinder(sigar); long[] pids = finder.find(query); if (pids.length < 1) { log.warn("Unable to find process from query: " + query); return -1; } else { return pids[0]; } } catch (SigarException ex) { log.warn("Error querying PTQL: " + query, ex); return -1; } }
Example #4
Source File: ProcessCleaner.java From scheduling with GNU Affero General Public License v3.0 | 5 votes |
private Set<Integer> getAliveWithSigar(boolean printProcesses) { Sigar sigar = new Sigar(); try { long[] pids = new ProcessFinder(sigar).find("State.Name.eq=java,Args.*.re=" + pattern); Set<Integer> setOfPids = new HashSet<>(); for (long pid : pids) { setOfPids.add((int) pid); if (printProcesses) System.out.println("Running java processes matching regex:" + pid); } return setOfPids; } catch (SigarException e) { return Collections.emptySet(); } }
Example #5
Source File: SysteminfoBinding.java From openhab1-addons with Eclipse Public License 2.0 | 5 votes |
private long getPid(String processName) throws SigarException { long pid; ProcessFinder processFinder = new ProcessFinder(sigarImpl); String query; if (processName.equals("$$")) { pid = sigar.getPid(); logger.debug("Return own pid {}", pid); return pid; } else if (processName.startsWith("*")) { query = "State.Name.sw=" + processName.replace("*", ""); } else if (processName.endsWith("*")) { query = "State.Name.ew=" + processName.replace("*", ""); } else if (processName.startsWith("=")) { query = "State.Name.eq=" + processName.replace("=", ""); } else if (processName.startsWith("#")) { query = processName.replace("#", ""); } else { query = "State.Name.ct=" + processName; } logger.debug("Query pid by '{}'", query); pid = processFinder.findSingleProcess(query); logger.debug("Return pid {}", pid); return pid; }