Class BsdOSThread
java.lang.Object
oshi.software.common.AbstractOSThread
oshi.software.common.os.unix.bsd.BsdOSThread
- All Implemented Interfaces:
OSThread
- Direct Known Subclasses:
DragonFlyBsdOSThread, FreeBsdOSThread, NetBsdOSThread, OpenBsdOSThread
Abstract base shared by the BSD-family OSThread implementations (FreeBSD, OpenBSD, DragonFly, NetBSD). Holds the
field storage, the trivial accessors, and the shared
ps thread-row parsing. Differences in the available
columns (thread-id keyword, name, elapsed/cpu time, thread address) are handled by checking which keys are present.
Platform-specific work (the ordered column list and the ps command used to refresh a single thread) is
provided by the per-platform subclasses.-
Nested Class Summary
Nested classes/interfaces inherited from interface OSThread
OSThread.ThreadFilteringModifier and TypeInterfaceDescriptionstatic final classConstants which may be used to filter Thread lists -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected longprotected longprotected longprotected longprotected Stringprotected intprotected longprotected longprotected OSProcess.Stateprotected intprotected longprotected long -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionlongA snapshot of the context switches the thread has done.longKernel (privileged) time used by the thread.longThe number of major (hard) faults the thread has made which have required loading a memory page from disk.longThe number of minor (soft) faults the thread has made which have not required loading a memory page from disk.getName()The name of the thread.intPriority of the thread, the meaning of which is dependent on the OS.longThe memory address above which this thread can run.longThe start time of the thread.getState()Gets the execution state of the task/thread.intThe thread id.longElapsed/up-time of the thread.longUser time used by the thread.protected abstract StringReturns thepscommand (without the trailing-p <pid>) used to enumerate this process's threads when refreshing a single thread.protected abstract List<BsdPsThreadKeyword> Returns this platform's orderedpsthread column keys, used to parse thread rows positionally.booleanAttempts to updates process attributes.protected booleanupdateAttributes(Map<BsdPsThreadKeyword, String> threadMap) Populates this thread's attributes from a parsedpsthread row.Methods inherited from class AbstractOSThread
getOwningProcessId, getThreadCpuLoadBetweenTicks, getThreadCpuLoadCumulative, toStringModifier and TypeMethodDescriptionintThe owning process of this thread.doublegetThreadCpuLoadBetweenTicks(OSThread priorSnapshot) Gets CPU usage of this thread since a previous snapshot of the same thread, provided as a parameter.doubleGets cumulative CPU usage of this thread.toString()
-
Field Details
-
threadId
protected int threadId -
name
-
state
-
minorFaults
protected long minorFaults -
majorFaults
protected long majorFaults -
startMemoryAddress
protected long startMemoryAddress -
contextSwitches
protected long contextSwitches -
kernelTime
protected long kernelTime -
userTime
protected long userTime -
startTime
protected long startTime -
upTime
protected long upTime -
priority
protected int priority
-
-
Constructor Details
-
BsdOSThread
protected BsdOSThread(int processId)
-
-
Method Details
-
getThreadId
public int getThreadId()Description copied from interface:OSThreadThe thread id. The meaning of this value is OS-dependent.- Returns:
- Returns the id of the thread.
-
getName
-
getState
Description copied from interface:OSThreadGets the execution state of the task/thread.- Returns:
- Returns the execution state of the task/thread.
-
getStartMemoryAddress
public long getStartMemoryAddress()Description copied from interface:OSThreadThe memory address above which this thread can run.- Returns:
- The start address.
-
getContextSwitches
public long getContextSwitches()Description copied from interface:OSThreadA snapshot of the context switches the thread has done. Since the context switches could be voluntary and non-voluntary, this gives the sum of both.Not available on AIX.
- Returns:
- sum of both voluntary and involuntary context switches.
-
getMinorFaults
public long getMinorFaults()Description copied from interface:OSThreadThe number of minor (soft) faults the thread has made which have not required loading a memory page from disk. Sometimes called reclaims. Linux only.- Returns:
- minor faults.
-
getMajorFaults
public long getMajorFaults()Description copied from interface:OSThreadThe number of major (hard) faults the thread has made which have required loading a memory page from disk. Linux only.- Returns:
- major faults.
-
getKernelTime
public long getKernelTime()Description copied from interface:OSThreadKernel (privileged) time used by the thread.- Returns:
- Returns the number of milliseconds the task/thread has executed in kernel/system mode.
-
getUserTime
public long getUserTime()Description copied from interface:OSThreadUser time used by the thread.- Returns:
- Returns the number of milliseconds the task/thread has executed in user mode.
-
getUpTime
public long getUpTime()Description copied from interface:OSThreadElapsed/up-time of the thread.- Returns:
- Returns the number of milliseconds since the task/thread started.
-
getStartTime
public long getStartTime()Description copied from interface:OSThreadThe start time of the thread.- Returns:
- Returns the start time of the task/thread in number of milliseconds since January 1, 1970.
-
getPriority
public int getPriority()Description copied from interface:OSThreadPriority of the thread, the meaning of which is dependent on the OS.- Returns:
- priority.
-
updateAttributes
public boolean updateAttributes()Description copied from interface:OSThreadAttempts to updates process attributes. Returns false if the update fails, which will occur if the process no longer exists. Not implemented for macOS, as thread ID is simply an index and not unique.- Returns:
trueif the update was successful, false if the update failed. In addition, on a failed update the thread state will be changed toOSProcess.State.INVALID.
-
updateAttributes
Populates this thread's attributes from a parsedpsthread row. Shared by every BSD platform; differences in the available columns are handled by checking which keys are present in the map.- Parameters:
threadMap- the parsedpscolumns for this thread- Returns:
trueonce the attributes are populated
-
psThreadKeywords
Returns this platform's orderedpsthread column keys, used to parse thread rows positionally.- Returns:
- the ordered thread column keys
-
psThreadCommand
Returns thepscommand (without the trailing-p <pid>) used to enumerate this process's threads when refreshing a single thread.- Returns:
- the
pscommand prefix
-