public class GenericProcessMonitor
extends java.lang.Object
Subclasses should override the debug(String) method to log to alternative mechanisms and should override the
This class contains no extended SAFS dependencies and can be readily packaged and distributed for non-SAFS installations.
Modifier and Type | Class and Description |
---|---|
static class |
GenericProcessMonitor.ProcessInfo |
static class |
GenericProcessMonitor.SearchCondition |
static class |
GenericProcessMonitor.UnixProcessSearchCondition |
static class |
GenericProcessMonitor.WQLSearchCondition |
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
EOL
The value of System property "line.separator"
|
static java.lang.String |
FILE_SEP
The value of System property "file.separator"
|
(package private) static java.lang.String |
OS_FAMILY_MAC |
(package private) static java.lang.String |
OS_FAMILY_SYS_PROP |
(package private) static java.lang.String |
OS_FAMILY_UNIX |
(package private) static java.lang.String |
OS_FAMILY_WINDOWS |
static java.lang.String |
OS_NAME
The value of System property "os.name"
|
static java.lang.String |
osFamilyName
The operating system family name, deduced from os name
OS_NAME |
static java.lang.String |
PATH_SEP
The value of System property "path.separator"
|
(package private) static java.lang.String |
unxprockillimg |
(package private) static java.lang.String |
unxprockillpid |
(package private) static java.lang.String |
unxproclist |
(package private) static java.lang.String |
winimgoption |
(package private) static java.lang.String |
winpidoption |
(package private) static java.lang.String |
winprockill |
(package private) static java.lang.String |
winproclist |
(package private) static java.lang.String |
winwmic |
(package private) static java.lang.String |
winwmic_cmdprocess |
(package private) static java.lang.String |
winwmic_nodeoption |
Constructor and Description |
---|
GenericProcessMonitor() |
Modifier and Type | Method and Description |
---|---|
protected static void |
debug(java.lang.String message)
Writes to System.out .
|
protected static java.lang.String |
deduceOSFamily()
Deduce the 'OS family name' from the 'OS name'.
'windows' for all versions of Windows System. 'unix' for all versions of Unix, Linux System. 'mac' for all versions of Mac System. |
static java.util.List<GenericProcessMonitor.ProcessInfo> |
getProcess(java.lang.String host,
GenericProcessMonitor.SearchCondition condition,
java.util.List<java.lang.String> fields)
Attempt to get processes on a certain host according to a WQL search condition.
On Windows we are using wmic.exe. |
protected static GenericProcessCapture |
getProcessCapture(java.lang.Process aproc)
Subclasses may wish to override to return a different subclass of GenericProcessCapture.
|
static boolean |
isProcessRunning(java.lang.String procid)
Return true or false that a given process is running on the system.
|
static boolean |
isWindowsOS() |
static void |
main(java.lang.String[] args) |
static boolean |
shutdownProcess(java.lang.String procid)
Attempt to forcefully kill a given process by name or PID.
|
static java.util.List<GenericProcessMonitor.ProcessInfo> |
shutdownProcess(java.lang.String host,
GenericProcessMonitor.SearchCondition condition)
Attempt to forcefully kill processes on a certain host according to a search condition.
On Windows we are using wmic.exe. |
static java.lang.String |
wqlCondition(java.lang.String key,
java.lang.String value,
boolean partialMatch,
boolean caseSensitive)
To generate WQL search condition for "wmic".
The condition is to search according a key's string value, we use "=" or "like" to compare. Note: 1. |
static final java.lang.String winproclist
static final java.lang.String winprockill
static final java.lang.String winpidoption
static final java.lang.String winimgoption
static final java.lang.String winwmic
static final java.lang.String winwmic_nodeoption
static final java.lang.String winwmic_cmdprocess
static final java.lang.String unxproclist
static final java.lang.String unxprockillpid
static final java.lang.String unxprockillimg
public static final java.lang.String OS_NAME
public static final java.lang.String PATH_SEP
public static final java.lang.String EOL
public static final java.lang.String FILE_SEP
public static java.lang.String osFamilyName
OS_NAME
static final java.lang.String OS_FAMILY_SYS_PROP
static final java.lang.String OS_FAMILY_WINDOWS
static final java.lang.String OS_FAMILY_UNIX
static final java.lang.String OS_FAMILY_MAC
protected static java.lang.String deduceOSFamily()
java.lang.IllegalStateException
- if neither can be deduced.protected static void debug(java.lang.String message)
message
- protected static GenericProcessCapture getProcessCapture(java.lang.Process aproc)
aproc
- public static boolean isProcessRunning(java.lang.String procid) throws java.io.IOException
procid
- CMD name, or IMAGE, or PID to seek.java.io.IOException
- if any error occurs in getting the processes for evaluation.public static java.lang.String wqlCondition(java.lang.String key, java.lang.String value, boolean partialMatch, boolean caseSensitive)
key
- String, the key to match, for example, for command 'process', the key could be CommandLine, Name, ProcessId etc.value
- String, the value to matchpartialMatch
- boolean, if the match is partial.caseSensitive
- boolean, if the match is case sensitive.public static java.util.List<GenericProcessMonitor.ProcessInfo> shutdownProcess(java.lang.String host, GenericProcessMonitor.SearchCondition condition) throws SAFSException
host
- String, the host name where to kill processes. This is only supprted on Windows.condition
- SearchCondition, the search condition to find processesSAFSException
public static java.util.List<GenericProcessMonitor.ProcessInfo> getProcess(java.lang.String host, GenericProcessMonitor.SearchCondition condition, java.util.List<java.lang.String> fields) throws SAFSException
host
- String, the host name where to get processescondition
- WQLSearchCondition, the WQL search condition to find processesfields
- ListSAFSException
public static boolean shutdownProcess(java.lang.String procid) throws java.io.IOException
procid
- CMD name(nix ps-f) or IMAGE(win qprocess.exe) or PID to kill.java.io.IOException
- if no shutdown attempt was ever able to execute.public static boolean isWindowsOS()
public static void main(java.lang.String[] args) throws java.io.IOException
java.io.IOException
Copyright © SAS Institute. All Rights Reserved.