/* * RHQ Management Platform * Copyright (C) 2005-2008 Red Hat, Inc. * All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License, version 2, as * published by the Free Software Foundation, and/or the GNU Lesser * General Public License, version 2.1, also as published by the Free * Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License and the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU General Public License * and the GNU Lesser General Public License along with this program; * if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ package org.rhq.core.system.pquery; import java.io.FileInputStream; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; import org.rhq.core.system.NativeSystemInfo; import org.rhq.core.system.ProcessInfo; import org.rhq.core.system.pquery.Conditional.Qualifier; /** * Performs a query over a set of {@link ProcessInfo#getCommandLine() command line strings}. The query strings are * written in the Process Info Query Language (PIQL, pronounced pickle).In effect, your PIQL will examine * a list of running processes whose command lines match a certain set of criteria. PIQL statements are formatted by a * series of criteria, with each criteria separated with a comma: * *
CRITERIA[,CRITERIA]** *
Criteria are formatted in the following manner:
* *CONDITIONAL=VALUE* *
VALUE is either a regular expression or a pid filename to compare a value obtained using the
* CONDITIONAL. See the class javadoc for java.util.regex.Pattern to learn the syntax of valid regular
* expressions. A CONDITIONAL is defined as:
CATEGORY|ATTRIBUTE|OPERATOR[|QUALIFIER]* *
where:
* *parent is the only value currently allowedThe ATTRIBUTE can be one of the following:
* *The OPERATOR can be one of the following:
* *Some examples of PIQL are:
* *| PIQL | *What is matched | *
|---|---|
process|pidfile|match=/etc/product/lock.pid |
* the process whose pid matches the number found in the lock.pid file | *
process|pidfile|match|parent=/etc/product/lock.pid |
* child processes of the parent process whose pid matches the number found in the lock.pid file | *
process|name|match=^/foo.* |
* all processes whose executables are found under the root "foo" directory | *
process|basename|match=^java.* |
* all processes whose executable file has "java" at the start of it | *
process|basename|match=(?i)^java.* |
* all processes whose executable file has "java" at the start of it (case insensitive, so "JAVA" would also * match) | *
process|name|match=.*(product|java).* |
* all processes whose executable paths have either "product" or "java" in them | *
process|name|match=^C:.*,process|basename|nomatch=java.exe |
* all processes whose executables are found on the Windows C: drive but is not a "java.exe" process | *
arg|1|match=org\.jboss\.Main |
* all processes whose command line argument #1 has a value of "org.jboss.Main". This will NOT match a process * that does not have a command line argument at the given index. | *
arg|*|match=.*daemon.* |
* all processes whose command lines have any argument with the substring "daemon" in them | *
arg|-b|nomatch=127\.0\.0\.1 |
* all processes whose command lines have any argument named "-b" whose value is not "127.0.0.1" (e.g. "-b * 192.168.0.5"). This will NOT match a process that does not have that argument at all. | *
arg|-Dbind.address|match=127.0.0.1 |
* all processes whose command lines have any argument named "bind.address" whose value is "127.0.0.1" (e.g. * "-Dbind.address=127.0.0.1"). This will NOT match a process that does not have that argument at all. | *
arg|-cp|match=.*org\.abc\.Class.* |
* all processes whose command lines have any argument named "-cp" whose value contains "org.abc.Class". This * will NOT match a process that does not have that argument at all. | *
arg|org.jboss.Main|match=.* |
* all processes whose command lines have any argument named "org.jboss.Main" | *
process|basename|match=(?i)Apache.exe,arg|-k|match|parent=runservice |
* all Apache processes that are running as child processes to the main Apache service. | *
process|basename|nomatch|parent=exec |
* all processes that have a parent whose basename is not exec. This will match all processes that do not have a * parent. | *
* process|basename|match=^(https?d.*|[Aa]pache)$,process|name|nomatch|parent=^(https?d.*|[Aa]pache)$
* |
* all Apache processes that do not have a parent process that is also an Apache process (i.e. this eliminates * all of the httpd child processes and only returns the main Apache servers). This will match a process that does * not have a parent but has a basename of Apache. | *
process|pid|match=1016 |
* The process whose pid is 1016. | *
processes data as coming from part of the output you see in the
* typical UNIX "ps" command.
*
* @param processes
*
* @see NativeSystemInfo#getAllProcesses()
*/
public ProcessInfoQuery(Listquery defines the criteria.
*
* @param query the query string containing the criteria to match
*
* @return the matches processes' command lines
*
* @throws IllegalArgumentException if the query was invalid
*/
public Listnull if the child has no parent
*/
private ProcessInfo getParentProcess(ProcessInfo child) {
ProcessInfo parent = null;
if (child != null) {
parent = this.allProcesses.get(child.getParentPid());
}
return parent;
}
private List