public class OSProcess extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
OSProcess.State
Process Execution States
|
| Constructor and Description |
|---|
OSProcess(OperatingSystem operatingSystem)
Constructor for OSProcess.
|
OSProcess(OperatingSystem operatingSystem,
int processID)
Constructor for OSProcess given a Process ID.
|
| Modifier and Type | Method and Description |
|---|---|
double |
calculateCpuPercent()
Calculates CPU usage of this process.
|
int |
getBitness()
Attempts to get the bitness (32 or 64) of the process.
|
long |
getBytesRead()
Getter for the field
bytesRead. |
long |
getBytesWritten()
Getter for the field
bytesWritten. |
String |
getCommandLine()
Getter for the field
commandLine. |
String |
getCurrentWorkingDirectory()
Getter for the field
currentWorkingDirectory. |
String |
getGroup()
Getter for the field
group. |
String |
getGroupID()
Getter for the field
groupID. |
long |
getKernelTime()
Getter for the field
kernelTime. |
String |
getName()
Getter for the field
name. |
long |
getOpenFiles()
Sets the number of open file handles (or network connections) that belongs to
the process
|
int |
getParentProcessID()
Getter for the field
parentProcessID. |
String |
getPath()
Getter for the field
path. |
int |
getPriority()
Getter for the field
priority. |
int |
getProcessID()
Getter for the field
processID. |
long |
getResidentSetSize()
Getter for the field
residentSetSize. |
long |
getStartTime()
Getter for the field
startTime. |
OSProcess.State |
getState()
Getter for the field
state. |
int |
getThreadCount()
Getter for the field
threadCount. |
long |
getUpTime()
Getter for the field
upTime. |
String |
getUser()
Getter for the field
user. |
String |
getUserID()
Getter for the field
userID. |
long |
getUserTime()
Getter for the field
userTime. |
long |
getVirtualSize()
Getter for the field
virtualSize. |
void |
setBitness(int bitness)
Setter for the field
bitness. |
void |
setBytesRead(long bytesRead)
Set the number of bytes the process has read from disk.
|
void |
setBytesWritten(long bytesWritten)
Set the number of bytes the process has written to disk.
|
void |
setCommandLine(String commandLine)
Sets the process command line.
|
void |
setCurrentWorkingDirectory(String currentWorkingDirectory)
Sets the process current working directory
|
void |
setGroup(String group)
Sets the group.
|
void |
setGroupID(String groupID)
Sets the Group ID.
|
void |
setKernelTime(long kernelTime)
Set the number of milliseconds the process has executed in kernel mode.
|
void |
setName(String name)
Set the name of the process.
|
void |
setOpenFiles(long count)
Sets the number of open file handles (or network connections) that belongs to
the process
|
void |
setParentProcessID(int parentProcessID)
Set the parentProcessID.
|
void |
setPath(String path)
Set the full path of the executing process.
|
void |
setPriority(int priority)
Set the priority of this process.
|
void |
setProcessID(int processID)
Set the processID.
|
void |
setResidentSetSize(long residentSetSize)
Set the Resident Set Size (RSS).
|
void |
setStartTime(long startTime)
Set the start time of the process in number of milliseconds since January 1,
1970.
|
void |
setState(OSProcess.State state)
Set the execution state of the process.
|
void |
setThreadCount(int threadCount)
Set the number of threads in this process.
|
void |
setUpTime(long upTime)
Set the number of milliseconds since the process started.
|
void |
setUser(String user)
Sets the user.
|
void |
setUserID(String userID)
Sets the User ID.
|
void |
setUserTime(long userTime)
Set the number of milliseconds the process has executed in user mode.
|
void |
setVirtualSize(long virtualSize)
Set the Virtual Memory Size (VSZ).
|
String |
toString() |
boolean |
updateAttributes()
Attempts to updates all process attributes.
|
boolean |
updateAttributes(boolean slowFields)
Attempts to updates all process attributes.
|
public OSProcess(OperatingSystem operatingSystem)
Constructor for OSProcess.
operatingSystem - a OperatingSystem instancepublic OSProcess(OperatingSystem operatingSystem, int processID) throws InstantiationException
Constructor for OSProcess given a Process ID. Instantiates an object with
current statistics for that process ID, and is equivalent to
OperatingSystem.getProcess(int).
If a process with that ID does not exist, this constructor will throw an
InstantiationException.
operatingSystem - a OperatingSystem instanceprocessID - process IDInstantiationException - If a process by that ID does not exist.public boolean updateAttributes()
public boolean updateAttributes(boolean slowFields)
slowFields - If false, skip fields that are slow to retrieve (e.g., group
information on Windows, open files on Unix and Linux). If true,
include all fields, regardless of how long it takes to retrieve
the data.public String getName()
Getter for the field name.
public void setName(String name)
name - process namepublic String getPath()
Getter for the field path.
public void setPath(String path)
path - process pathpublic String getCommandLine()
Getter for the field commandLine.
On Linux and macOS systems, the string is null-character-delimited, to permit the end user to parse the executable and arguments if desired. Further, the macOS variant may include environment variables which the end user may wish to exclude from display. On Solaris, the string is truncated to 80 characters.
public void setCommandLine(String commandLine)
commandLine - The commandLine to set.public String getCurrentWorkingDirectory()
Getter for the field currentWorkingDirectory.
On Windows, this value is only populated for the current process.
public void setCurrentWorkingDirectory(String currentWorkingDirectory)
currentWorkingDirectory - The currentWorkingDirectory to set.public String getUser()
Getter for the field user.
public void setUser(String user)
user - The user to set.public String getUserID()
Getter for the field userID.
public void setUserID(String userID)
userID - The userID to set.public String getGroup()
Getter for the field group.
On Windows systems, populating this value for processes other than
the current user requires administrative privileges (and still may
fail for some system processes) and can incur significant latency.
The value is only calculated for single process queries using
OperatingSystem.getProcess(int). When
successful, returns a comma-delimited list of groups with access to
this process, corresponding to the SIDs in getGroupID().
public void setGroup(String group)
group - The group to set.public String getGroupID()
Getter for the field groupID.
On Windows systems, populating this value for processes other than
the current user requires administrative privileges (and still may
fail for some system processes) and can incur significant latency.
The value is only calculated for single process queries using
OperatingSystem.getProcess(int). When
successful, returns a comma-delimited list of group SIDs with access
to this process, corresponding to the names in getGroup().
public void setGroupID(String groupID)
groupID - The groupID to set.public OSProcess.State getState()
Getter for the field state.
public void setState(OSProcess.State state)
state - execution statepublic int getProcessID()
Getter for the field processID.
public void setProcessID(int processID)
processID - process IDpublic int getParentProcessID()
Getter for the field parentProcessID.
public void setParentProcessID(int parentProcessID)
parentProcessID - parent process IDpublic int getThreadCount()
Getter for the field threadCount.
public void setThreadCount(int threadCount)
threadCount - number of threadspublic int getPriority()
Getter for the field priority.
For Linux and Unix, priority is a value in the range -20 to 19 (20 on some systems). The default priority is 0; lower priorities cause more favorable scheduling.
For Windows, priority values can range from 0 (lowest priority) to 31 (highest priority).
Mac OS X has 128 priority levels, ranging from 0 (lowest priority) to 127 (highest priority). They are divided into several major bands: 0 through 51 are the normal levels; the default priority is 31. 52 through 79 are the highest priority regular threads; 80 through 95 are for kernel mode threads; and 96 through 127 correspond to real-time threads, which are treated differently than other threads by the scheduler.
public void setPriority(int priority)
For Linux, priority is a value in the range -20 to 19 (20 on some systems). The default priority is 0; lower priorities cause more favorable scheduling.
For Windows, priority values can range from 0 (lowest priority) to 31 (highest priority).
Mac OS X has 128 priority levels, ranging from 0 (lowest priority) to 127 (highest priority). They are divided into several major bands: 0 through 51 are the normal levels; the default priority is 31. 52 through 79 are the highest priority regular threads; 80 through 95 are for kernel mode threads; and 96 through 127 correspond to real-time threads, which are treated differently than other threads by the scheduler.
priority - prioritypublic long getVirtualSize()
Getter for the field virtualSize.
public void setVirtualSize(long virtualSize)
virtualSize - virtual sizepublic long getResidentSetSize()
Getter for the field residentSetSize.
public void setResidentSetSize(long residentSetSize)
residentSetSize - resident set sizepublic long getKernelTime()
Getter for the field kernelTime.
public void setKernelTime(long kernelTime)
kernelTime - kernel timepublic long getUserTime()
Getter for the field userTime.
public void setUserTime(long userTime)
userTime - user timepublic long getUpTime()
Getter for the field upTime.
public void setUpTime(long upTime)
upTime - up timepublic long getStartTime()
Getter for the field startTime.
public void setStartTime(long startTime)
startTime - start timepublic long getBytesRead()
Getter for the field bytesRead.
public void setBytesRead(long bytesRead)
bytesRead - number of bytes readpublic long getBytesWritten()
Getter for the field bytesWritten.
public void setBytesWritten(long bytesWritten)
bytesWritten - number of bytes writtenpublic long getOpenFiles()
On FreeBSD and Solaris, this value is only populated if information for a single process id is requested.
public void setOpenFiles(long count)
count - The number of handlespublic double calculateCpuPercent()
public int getBitness()
public void setBitness(int bitness)
Setter for the field bitness.
bitness - The bitness to set.Copyright © 2020. All rights reserved.