Class WindowsOSProcess
- All Implemented Interfaces:
OSProcess
-
Nested Class Summary
Nested classes/interfaces inherited from interface OSProcess
OSProcess.State -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final longprotected static final booleanprotected static final boolean -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedWindowsOSProcess(int pid, OperatingSystem os, Map<Integer, ProcessPerfCounterBlock> processMap, Map<Integer, WtsInfo> processWtsMap, Map<Integer, ThreadPerfCounterBlock> threadMap) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract OSThreadcreateOSThread(int pid, int tid, String procName, ThreadPerfCounterBlock pcb) Creates a platform-specific OS thread instance.Makes a best effort attempt to get a list of the the command-line arguments of the process.intAttempts to get the bitness (32 or 64) of the process.longGets the bytes read by the process.longGets the bytes written by the process.Gets the process command line used to start the process, including arguments if available to be determined.Makes a best effort attempt to obtain the current working directory for the process.Returns the memoized CWD/CommandLine/Environment triplet.Makes a best effort attempt to obtain the environment variables of the process.getGroup()Gets the group under which the process is executing.Gets the group id under which the process is executing.longGets the hard limit for open file handles (or network connections) that belong to the given process.longGets kernel/system (privileged) time used by the process.longGets the number of minor (soft) faults the process has made which have not required loading a memory page from disk.getName()Gets the name of the process, often the executable program.longGets the number of open file handles (or network connections) that belongs to the process.protected OperatingSystemgetOs()Returns theOperatingSysteminstance associated with this process.intGets the process ID of this process's parent.getPath()Gets the full filesystem path of the executing process.intGets the priority of this process.longReturns an estimate of the portion of physical memory (RAM) uniquely attributed to this process.longReturns the total amount of physical memory (RAM) currently mapped to the process's address space.longGets the soft limit for open file handles (or network connections) of the given process.longGets the process start time.getState()Gets the process state.intGets the number of threads being executed by this process.Retrieves the threads of the process and their details.longGets up time / elapsed time since the process started.getUser()Gets the user name of the process owner.Gets the user id of the process owner.longGets user time used by the process.longGets the Virtual Memory Size (VSZ).Queries the argument list for this process.protected abstract StringQueries the command line for this process.Queries the current working directory, command line, and environment variables from process memory.Queries group account information for this process.protected abstract Map<Integer, ThreadPerfCounterBlock> queryMatchingThreads(Set<Integer> pids) Queries thread performance data matching the given process IDs.Queries user account information for this process.protected voidsetBitness(int bitness) Sets the process bitness.protected voidSets the process name.protected voidSets the process executable path.protected voidsetState(OSProcess.State state) Sets the process state.protected voidsetTcb(Map<Integer, ThreadPerfCounterBlock> tcb) Sets the thread counter block map.protected booleanupdateAttributes(ProcessPerfCounterBlock pcb, WtsInfo wts) Updates process attributes from performance counter and WTS data, then performs native-specific updates.Methods inherited from class AbstractOSProcess
getProcessCpuLoadBetweenTicks, getProcessCpuLoadCumulative, getProcessID, toStringMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface OSProcess
getAffinityMask, getContextSwitches, getInvoluntaryContextSwitches, getMajorFaults, getVoluntaryContextSwitches, updateAttributes
-
Field Details
-
MAX_WINDOWS_HANDLES
protected static final long MAX_WINDOWS_HANDLES -
USE_BATCH_COMMANDLINE
protected static final boolean USE_BATCH_COMMANDLINE -
USE_PROCSTATE_SUSPENDED
protected static final boolean USE_PROCSTATE_SUSPENDED
-
-
Constructor Details
-
WindowsOSProcess
protected WindowsOSProcess(int pid, OperatingSystem os, Map<Integer, ProcessPerfCounterBlock> processMap, Map<Integer, WtsInfo> processWtsMap, Map<Integer, ThreadPerfCounterBlock> threadMap) Constructor.- Parameters:
pid- the pidos- the osprocessMap- the processMapprocessWtsMap- the processWtsMapthreadMap- the threadMap
-
-
Method Details
-
getOs
Returns theOperatingSysteminstance associated with this process.- Returns:
- the operating system instance
-
getCwdCmdEnv
-
getName
-
getPath
-
getCommandLine
Description copied from interface:OSProcessGets the process command line used to start the process, including arguments if available to be determined. This method generally returns the same information asOSProcess.getArguments()in a more user-readable format, and is more robust to non-elevated access.The format of this string is platform-dependent, may be truncated, and may require the end user to parse the result. Users should generally prefer
OSProcess.getArguments()which already parses the results, and use this method as a backup.On AIX and Solaris, the string may be truncated to 80 characters if there was insufficient permission to read the process memory.
On Windows, attempts to retrieve the value from process memory, which requires that the process be owned by the same user as the executing process, or elevated permissions, and additionally requires the target process to have the same bitness (e.g., this will fail on a 32-bit process if queried by 64-bit and vice versa). If reading process memory fails, by default, performs a single WMI query for this process, with some latency. If this method will be frequently called for multiple processes, see the configuration file to enable a batch query mode to improve performance via caching, or configure the option via
GlobalConfigbefore instantiating anyOSProcessobject.- Returns:
- the process command line.
-
getArguments
Description copied from interface:OSProcessMakes a best effort attempt to get a list of the the command-line arguments of the process. Returns the same information asOSProcess.getCommandLine()but parsed to a list. May require elevated permissions or same-user ownership.- Returns:
- A list of Strings representing the arguments. May return an empty list if there was a failure (for example, because the process is already dead or permission was denied).
-
getEnvironmentVariables
Description copied from interface:OSProcessMakes a best effort attempt to obtain the environment variables of the process. May require elevated permissions or same-user ownership.- Returns:
- A map representing the environment variables and their values. May return an empty map if there was a failure (for example, because the process is already dead or permission was denied).
-
getCurrentWorkingDirectory
-
getUser
-
getUserID
-
getGroup
Description copied from interface:OSProcessGets the group under which the process is executing.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. When successful, returns a the default primary group with access to this process, corresponding to the SID in
OSProcess.getGroupID().- Returns:
- the group.
-
getGroupID
Description copied from interface:OSProcessGets the group id under which the process is executing.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. When successful, returns the default primary group SID with access to this process, corresponding to the name in
OSProcess.getGroup().- Returns:
- the groupID.
-
getState
Description copied from interface:OSProcessGets the process state.- Returns:
- the execution state of the process.
-
getParentProcessID
public int getParentProcessID()Description copied from interface:OSProcessGets the process ID of this process's parent.- Returns:
- the parentProcessID, if any; 0 otherwise.
-
getThreadCount
public int getThreadCount()Description copied from interface:OSProcessGets the number of threads being executed by this process. More information is available usingOSProcess.getThreadDetails().- Returns:
- the number of threads in this process.
-
getPriority
public int getPriority()Description copied from interface:OSProcessGets the priority of this process.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).
macOS 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.
- Returns:
- the priority of this process.
-
getVirtualSize
public long getVirtualSize()Description copied from interface:OSProcessGets the Virtual Memory Size (VSZ). Includes all memory that the process can access, including memory that is swapped out and memory that is from shared libraries.- Returns:
- the Virtual Memory Size
-
getResidentMemory
public long getResidentMemory()Description copied from interface:OSProcessReturns the total amount of physical memory (RAM) currently mapped to the process's address space. This value represents the Resident Set Size (RSS) and includes both private memory and memory shared with other processes (such as shared libraries). This aligns with the reporting behavior of standard command-line utilities likepsandtop.On Linux, returns the RSS value from
/proc/[pid]/stat, which may be inaccurate because of a kernel-internal scalability optimization. If accurate values are required, read/proc/[pid]/smapsusingFileUtil#getKeyValueMapFromFile(String, String).- Returns:
- The resident set size in bytes.
-
getPrivateResidentMemory
public long getPrivateResidentMemory()Description copied from interface:OSProcessReturns an estimate of the portion of physical memory (RAM) uniquely attributed to this process. This metric excludes shared libraries and other memory segments mapped by multiple processes, providing a more accurate representation of the process's individual impact on system resources. This value aligns with the primary "Memory" column in graphical system monitors, such as Windows Task Manager, macOS Activity Monitor, and the GNOME System Monitor.- Returns:
- The private or "footprint" resident memory in bytes if available. Defaults to
OSProcess.getResidentMemory()otherwise.
-
getKernelTime
public long getKernelTime()Description copied from interface:OSProcessGets kernel/system (privileged) time used by the process.- Returns:
- the number of milliseconds the process has executed in kernel/system mode.
-
getUserTime
public long getUserTime()Description copied from interface:OSProcessGets user time used by the process.- Returns:
- the number of milliseconds the process has executed in user mode.
-
getUpTime
public long getUpTime()Description copied from interface:OSProcessGets up time / elapsed time since the process started.- Returns:
- the number of milliseconds since the process started.
-
getStartTime
public long getStartTime()Description copied from interface:OSProcessGets the process start time.- Returns:
- the start time of the process in number of milliseconds since January 1, 1970 UTC.
-
getBytesRead
public long getBytesRead()Description copied from interface:OSProcessGets the bytes read by the process. This includes all I/O activity generated by the process to include file, network, and device I/Os.On Solaris, includes both bytes read and written.
- Returns:
- the number of bytes the process has read.
-
getBytesWritten
public long getBytesWritten()Description copied from interface:OSProcessGets the bytes written by the process. This includes all I/O activity generated by the process to include file, network, and device I/Os.On Solaris, all IO bytes are included read bytes so this value is 0.
- Returns:
- the number of bytes the process has written to disk.
-
getOpenFiles
public long getOpenFiles()Description copied from interface:OSProcessGets the number of open file handles (or network connections) that belongs to the process.On FreeBSD and Solaris, this value is only populated if information for a single process id is requested.
- Returns:
- open files or -1 if unknown or not supported
-
getSoftOpenFileLimit
public long getSoftOpenFileLimit()Description copied from interface:OSProcessGets the soft limit for open file handles (or network connections) of the given process.Retrieving the soft limit for processes other than the calling process is only supported on Linux, FreeBsd and Solaris.
- Returns:
- the soft open file limit for the process if available. Returns -1 if the calling process is not the same as this OSProcess instance and the underlying operating system does not support retrieving the soft limit for other processes.
-
getHardOpenFileLimit
public long getHardOpenFileLimit()Description copied from interface:OSProcessGets the hard limit for open file handles (or network connections) that belong to the given process.Retrieving the hard limit for processes other than the calling process is only supported on Linux, FreeBsd and Solaris.
- Returns:
- the hard open file limit for the process if available. Returns -1 if the calling process is not the same as this OSProcess instance and the underlying operating system does not support retrieving the hard limit for other processes.
-
getBitness
public int getBitness()Description copied from interface:OSProcessAttempts to get the bitness (32 or 64) of the process.- Returns:
- The bitness, if able to be determined, 0 otherwise.
-
getMinorFaults
public long getMinorFaults()Description copied from interface:OSProcessGets the number of minor (soft) faults the process has made which have not required loading a memory page from disk. Sometimes called reclaims.On Windows, this includes the total of major and minor faults.
Not available on AIX.
- Returns:
- minor page faults (reclaims).
-
getThreadDetails
-
createOSThread
protected abstract OSThread createOSThread(int pid, int tid, String procName, ThreadPerfCounterBlock pcb) Creates a platform-specific OS thread instance.- Parameters:
pid- the owning process IDtid- the thread IDprocName- the process namepcb- the thread performance counter block- Returns:
- a new OSThread instance
-
updateAttributes
Updates process attributes from performance counter and WTS data, then performs native-specific updates. Subclasses should callsuper.updateAttributes(pcb, wts)and then perform native handle-based updates.- Parameters:
pcb- Performance counter block for this process, or null if unavailablewts- WTS info for this process, or null if unavailable- Returns:
- true if the process is valid after the update
-
setName
Sets the process name. Used by subclasses to ensure the name is current before querying threads.- Parameters:
name- the process name to set
-
setBitness
protected void setBitness(int bitness) Sets the process bitness. Used by subclasses to update after WOW64 check.- Parameters:
bitness- the bitness to set
-
setPath
Sets the process executable path. Used by subclasses to update after native query.- Parameters:
path- the path to set
-
setState
Sets the process state. Used by subclasses to mark a process as invalid.- Parameters:
state- the state to set
-
setTcb
Sets the thread counter block map. Used by subclasses during attribute updates.- Parameters:
tcb- the thread performance counter block map
-
queryMatchingThreads
Queries thread performance data matching the given process IDs.- Parameters:
pids- the set of process IDs to match- Returns:
- a map of thread ID to thread performance counter block
-
queryCommandLine
Queries the command line for this process.- Returns:
- the command line string
-
queryArguments
-
queryUserInfo
-
queryGroupInfo
-
queryCwdCommandlineEnvironment
-
defaultCwdCommandlineEnvironment
-
defaultPair
-