public class ProcessInfo extends Object
Encapsulates information about a known process.
A few process properties (i.e. PID, command line) will never change during the lifetime of the process and can be
read directly with this class accessors. Other process properties (i.e. state, cpu usage) will vary and their values
are grouped in ProcessInfo.ProcessInfoSnapshot instances.
Operations on static properties of the process must be implemented in the ProcessInfo type. Operations on
non static properties must be implemented in the ProcessInfo.ProcessInfoSnapshot type. The ProcessInfo.ProcessInfoSnapshot
subtype has been created to remind users of the class that they are working with cached data.
For example, if you want to be sure a process is still alive, you should use this code:
processInfo.freshSnapshot().isRunning()
Rather than:
processInfo.priorSnapshot().isRunning()
| Modifier and Type | Class and Description |
|---|---|
class |
ProcessInfo.ProcessInfoSnapshot
Exposes non static process properties and operations computed on them (like
ProcessInfo.ProcessInfoSnapshot.isRunning() method). |
| Modifier and Type | Field and Description |
|---|---|
protected String |
baseName |
protected String[] |
commandLine |
protected Map<String,String> |
environmentVariables |
protected boolean |
initialized |
protected String |
name |
protected ProcessInfo |
parentProcess |
protected long |
pid |
protected org.hyperic.sigar.ProcCpu |
procCpu
Deprecated.
as of 4.6. To read this property call
priorSnaphot() and then corresponding method
from the returned ProcessInfo.ProcessInfoSnapshot. |
protected org.hyperic.sigar.ProcCred |
procCred
Deprecated.
as of 4.6. To read this property call
priorSnaphot() and then corresponding method
from the returned ProcessInfo.ProcessInfoSnapshot. |
protected org.hyperic.sigar.ProcCredName |
procCredName
Deprecated.
as of 4.6. To read this property call
priorSnaphot() and then corresponding method
from the returned ProcessInfo.ProcessInfoSnapshot. |
protected Map<String,String> |
procEnv |
protected boolean |
processDied |
protected org.hyperic.sigar.ProcExe |
procExe
Deprecated.
as of 4.6. To read this property call
priorSnaphot() and then corresponding method
from the returned ProcessInfo.ProcessInfoSnapshot. |
protected org.hyperic.sigar.ProcFd |
procFd
Deprecated.
as of 4.6. To read this property call
priorSnaphot() and then corresponding method
from the returned ProcessInfo.ProcessInfoSnapshot. |
protected org.hyperic.sigar.ProcMem |
procMem
Deprecated.
as of 4.6. To read this property call
priorSnaphot() and then corresponding method
from the returned ProcessInfo.ProcessInfoSnapshot. |
protected org.hyperic.sigar.ProcState |
procState
Deprecated.
as of 4.6. To read this property call
priorSnaphot() and then corresponding method
from the returned ProcessInfo.ProcessInfoSnapshot. |
protected org.hyperic.sigar.ProcTime |
procTime
Deprecated.
as of 4.6. To read this property call
priorSnaphot() and then corresponding method
from the returned ProcessInfo.ProcessInfoSnapshot. |
protected org.hyperic.sigar.SigarProxy |
sigar |
| Modifier | Constructor and Description |
|---|---|
protected |
ProcessInfo() |
|
ProcessInfo(long pid) |
|
ProcessInfo(long pid,
org.hyperic.sigar.SigarProxy sigar) |
| Modifier and Type | Method and Description |
|---|---|
void |
destroy() |
boolean |
equals(Object obj)
Two
ProcessInfo objects are equal if their pids are the same. |
ProcessInfo.ProcessInfoSnapshot |
freshSnapshot()
Takes a fresh snapshot of the non static process properties.
|
AggregateProcessInfo |
getAggregateProcessTree()
Returns an object that provides aggregate information on this process and all its children.
|
String |
getBaseName()
Similar to
getName(), this is a convenience method that returns the first command line argument, which
is the name of the program that the process is executing. |
String[] |
getCommandLine() |
org.hyperic.sigar.ProcCpu |
getCpu()
Deprecated.
as of 4.6. For similar purpose, call
priorSnaphot() and then corresponding method
from the returned ProcessInfo.ProcessInfoSnapshot. |
org.hyperic.sigar.ProcCred |
getCredentials()
Deprecated.
as of 4.6. For similar purpose, call
priorSnaphot() and then corresponding method
from the returned ProcessInfo.ProcessInfoSnapshot. |
org.hyperic.sigar.ProcCredName |
getCredentialsName()
Deprecated.
as of 4.6. For similar purpose, call
priorSnaphot() and then corresponding method
from the returned ProcessInfo.ProcessInfoSnapshot. |
String |
getCurrentWorkingDirectory()
Deprecated.
as of 4.6. For similar purpose, call
priorSnaphot() and then corresponding method
from the returned ProcessInfo.ProcessInfoSnapshot. |
String |
getEnvironmentVariable(String name)
Retrieves a specific environment property if it exists,
null otherwise. |
Map<String,String> |
getEnvironmentVariables() |
org.hyperic.sigar.ProcExe |
getExecutable()
Deprecated.
as of 4.6. For similar purpose, call
priorSnaphot() and then corresponding method
from the returned ProcessInfo.ProcessInfoSnapshot. |
org.hyperic.sigar.ProcFd |
getFileDescriptor()
Deprecated.
as of 4.6. For similar purpose, call
priorSnaphot() and then corresponding method
from the returned ProcessInfo.ProcessInfoSnapshot. |
org.hyperic.sigar.ProcMem |
getMemory()
Deprecated.
as of 4.6. For similar purpose, call
priorSnaphot() and then corresponding method
from the returned ProcessInfo.ProcessInfoSnapshot. |
String |
getName()
Convenience method that returns the first command line argument, which is the name of the program that the
process is executing.
|
long |
getParentPid()
Deprecated.
as of 4.6. For similar purpose, call
priorSnaphot() and then corresponding method
from the returned ProcessInfo.ProcessInfoSnapshot. |
ProcessInfo |
getParentProcess()
Returns a
ProcessInfo instance for the parent of this process. |
long |
getPid() |
org.hyperic.sigar.ProcState |
getState()
Deprecated.
as of 4.6. For similar purpose, call
priorSnaphot() and then corresponding method
from the returned ProcessInfo.ProcessInfoSnapshot. |
org.hyperic.sigar.ProcTime |
getTime()
Deprecated.
as of 4.6. For similar purpose, call
priorSnaphot() and then corresponding method
from the returned ProcessInfo.ProcessInfoSnapshot. |
int |
hashCode()
A process' pid makes it unique - this returns the
getPid() itself. |
boolean |
isRunning()
Deprecated.
as of 4.6. For similar purpose, call
priorSnaphot() and then corresponding method
from the returned ProcessInfo.ProcessInfoSnapshot. |
void |
kill(String signalName)
Send the signal with the specified name to this process.
|
ProcessInfo.ProcessInfoSnapshot |
priorSnaphot()
Returns the last snasphot of the non static process properties.
|
void |
refresh()
Takes a fresh snapshot of non static properties of the underlying process.
|
String |
toString() |
protected boolean initialized
protected org.hyperic.sigar.SigarProxy sigar
protected long pid
protected String name
protected String[] commandLine
protected String baseName
protected ProcessInfo parentProcess
@Deprecated protected org.hyperic.sigar.ProcState procState
priorSnaphot() and then corresponding method
from the returned ProcessInfo.ProcessInfoSnapshot.@Deprecated protected org.hyperic.sigar.ProcExe procExe
priorSnaphot() and then corresponding method
from the returned ProcessInfo.ProcessInfoSnapshot.@Deprecated protected org.hyperic.sigar.ProcTime procTime
priorSnaphot() and then corresponding method
from the returned ProcessInfo.ProcessInfoSnapshot.@Deprecated protected org.hyperic.sigar.ProcMem procMem
priorSnaphot() and then corresponding method
from the returned ProcessInfo.ProcessInfoSnapshot.@Deprecated protected org.hyperic.sigar.ProcCpu procCpu
priorSnaphot() and then corresponding method
from the returned ProcessInfo.ProcessInfoSnapshot.@Deprecated protected org.hyperic.sigar.ProcFd procFd
priorSnaphot() and then corresponding method
from the returned ProcessInfo.ProcessInfoSnapshot.@Deprecated protected org.hyperic.sigar.ProcCred procCred
priorSnaphot() and then corresponding method
from the returned ProcessInfo.ProcessInfoSnapshot.@Deprecated protected org.hyperic.sigar.ProcCredName procCredName
priorSnaphot() and then corresponding method
from the returned ProcessInfo.ProcessInfoSnapshot.protected boolean processDied
protected ProcessInfo()
public ProcessInfo(long pid)
throws SystemInfoException
SystemInfoExceptionpublic ProcessInfo(long pid,
org.hyperic.sigar.SigarProxy sigar)
throws SystemInfoException
SystemInfoExceptionpublic void refresh()
throws SystemInfoException
SystemInfoExceptionpublic ProcessInfo.ProcessInfoSnapshot priorSnaphot()
Returns the last snasphot of the non static process properties.
Caveat the returned may hold stale data has it was taken with previous SIGAR calls.
Calling freshSnapshot() instead is almost always a better idea.
ProcessInfo.ProcessInfoSnapshot possibly holding stale datapublic ProcessInfo.ProcessInfoSnapshot freshSnapshot()
ProcessInfo.ProcessInfoSnapshotpublic void destroy()
throws SystemInfoException
SystemInfoExceptionpublic long getPid()
public String getName()
getBaseName(),
getCommandLine()public String getBaseName()
getName(), this is a convenience method that returns the first command line argument, which
is the name of the program that the process is executing. However, this is only the relative filename of the
program, which does not include the full path to the program (e.g. this would return "sh" if the name of the
process is "/usr/bin/sh").getName(),
getCommandLine()public String[] getCommandLine()
@Nullable public String getEnvironmentVariable(@NotNull String name)
null otherwise.name - the name of the property to find@Deprecated public long getParentPid() throws SystemInfoException
priorSnaphot() and then corresponding method
from the returned ProcessInfo.ProcessInfoSnapshot.SystemInfoException@Deprecated public org.hyperic.sigar.ProcState getState() throws SystemInfoException
priorSnaphot() and then corresponding method
from the returned ProcessInfo.ProcessInfoSnapshot.SystemInfoException@Deprecated public org.hyperic.sigar.ProcExe getExecutable() throws SystemInfoException
priorSnaphot() and then corresponding method
from the returned ProcessInfo.ProcessInfoSnapshot.SystemInfoException@Deprecated public org.hyperic.sigar.ProcTime getTime() throws SystemInfoException
priorSnaphot() and then corresponding method
from the returned ProcessInfo.ProcessInfoSnapshot.SystemInfoException@Deprecated public org.hyperic.sigar.ProcMem getMemory() throws SystemInfoException
priorSnaphot() and then corresponding method
from the returned ProcessInfo.ProcessInfoSnapshot.SystemInfoException@Deprecated public org.hyperic.sigar.ProcCpu getCpu() throws SystemInfoException
priorSnaphot() and then corresponding method
from the returned ProcessInfo.ProcessInfoSnapshot.SystemInfoException@Deprecated public org.hyperic.sigar.ProcFd getFileDescriptor() throws SystemInfoException
priorSnaphot() and then corresponding method
from the returned ProcessInfo.ProcessInfoSnapshot.SystemInfoException@Deprecated public org.hyperic.sigar.ProcCred getCredentials() throws SystemInfoException
priorSnaphot() and then corresponding method
from the returned ProcessInfo.ProcessInfoSnapshot.SystemInfoException@Deprecated public org.hyperic.sigar.ProcCredName getCredentialsName() throws SystemInfoException
priorSnaphot() and then corresponding method
from the returned ProcessInfo.ProcessInfoSnapshot.SystemInfoException@Deprecated public String getCurrentWorkingDirectory() throws SystemInfoException
priorSnaphot() and then corresponding method
from the returned ProcessInfo.ProcessInfoSnapshot.SystemInfoException@Deprecated public boolean isRunning() throws SystemInfoException
priorSnaphot() and then corresponding method
from the returned ProcessInfo.ProcessInfoSnapshot.SystemInfoExceptionpublic AggregateProcessInfo getAggregateProcessTree()
public ProcessInfo getParentProcess() throws SystemInfoException
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 ProcessInfo.ProcessInfoSnapshot type.
In practice, it stays here because the parent ProcessInfo instance is cached after creation.SystemInfoExceptionpublic void kill(String signalName) throws org.hyperic.sigar.SigarException
signalName - the name of the signal to sendIllegalArgumentException - if the signal name is not validorg.hyperic.sigar.SigarException - if the native kill() call failspublic int hashCode()
getPid() itself.hashCode in class ObjectObject.hashCode()public boolean equals(Object obj)
ProcessInfo objects are equal if their pids are the same.equals in class ObjectObject.equals(java.lang.Object)Copyright © 2008-2014 Red Hat, Inc.. All Rights Reserved.