Record Class ProcessInfo
java.lang.Object
java.lang.Record
cloud.opencode.base.core.process.ProcessInfo
- Record Components:
pid- the process ID - 进程 IDcommand- the executable name (may be empty) - 可执行文件名(可能为空)commandLine- the full command line (may be empty) - 完整命令行(可能为空)user- the process owner (may be empty) - 进程所有者(可能为空)startTime- when the process started, ornullif unknown - 进程启动时间,未知时为 nullcpuDuration- total CPU time used, ornullif unknown - 已使用的 CPU 总时间,未知时为 nullalive- whether the process is currently alive - 进程是否存活
public record ProcessInfo(long pid, String command, String commandLine, String user, Instant startTime, Duration cpuDuration, boolean alive)
extends Record
ProcessInfo - Immutable snapshot of process information
ProcessInfo - 进程信息的不可变快照
Captures key attributes of an operating system process at a point in time.
Built from ProcessHandle via the from(ProcessHandle) factory method.
在某一时刻捕获操作系统进程的关键属性。
通过 from(ProcessHandle) 工厂方法从 ProcessHandle 构建。
Fields | 字段:
pid- Process ID - 进程 IDcommand- Executable name only (may be empty) - 可执行文件名(可能为空)commandLine- Full command line (may be empty for security) - 完整命令行(出于安全可能为空)user- Process owner (may be empty) - 进程所有者(可能为空)startTime- When process started (may be null) - 进程启动时间(可能为 null)cpuDuration- Total CPU time used (may be null) - 已使用的 CPU 总时间(可能为 null)alive- Whether process is currently alive - 进程是否存活
Thread Safety | 线程安全: This record is immutable and thread-safe. 此记录是不可变的,线程安全。
- Since:
- JDK 25, opencode-base-core V1.0.3
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanalive()Returns the value of thealiverecord component.command()Returns the value of thecommandrecord component.Returns the value of thecommandLinerecord component.Returns the value of thecpuDurationrecord component.cpuTime()Returns the CPU time as anOptional.final booleanIndicates whether some other object is "equal to" this one.static ProcessInfofrom(ProcessHandle handle) Creates aProcessInfofrom aProcessHandle.static ProcessInfoCreates aProcessInfofor the current JVM process.final inthashCode()Returns a hash code value for this object.longpid()Returns the value of thepidrecord component.Returns the start time as anOptional.Returns the value of thestartTimerecord component.final StringtoString()Returns a string representation of this record class.longReturns the uptime in milliseconds since the process started, or-1if unknown.user()Returns the value of theuserrecord component.
-
Constructor Details
-
ProcessInfo
-
-
Method Details
-
from
Creates aProcessInfofrom aProcessHandle. 从ProcessHandle创建ProcessInfo。All optional fields from
ProcessHandle.Infoare handled gracefully with sensible defaults (empty strings, null for temporal values).ProcessHandle.Info中的所有可选字段均以合理默认值优雅处理 (空字符串、时间值为 null)。- Parameters:
handle- the process handle - 进程句柄- Returns:
- a new ProcessInfo snapshot - 新的 ProcessInfo 快照
- Throws:
NullPointerException- if handle is null - 若 handle 为 null
-
fromCurrent
Creates aProcessInfofor the current JVM process. 为当前 JVM 进程创建ProcessInfo。- Returns:
- process info for the current process - 当前进程的进程信息
-
startInstant
-
cpuTime
-
uptimeMillis
public long uptimeMillis()Returns the uptime in milliseconds since the process started, or-1if unknown. 返回进程启动以来的毫秒数,未知时返回-1。- Returns:
- uptime in milliseconds, or -1 if start time is unknown - 运行时间(毫秒),未知时为 -1
-
toString
-
hashCode
-
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared withObjects::equals(Object,Object); primitive components are compared with thecomparemethod from their corresponding wrapper classes. -
pid
-
command
-
commandLine
Returns the value of thecommandLinerecord component.- Returns:
- the value of the
commandLinerecord component
-
user
-
startTime
-
cpuDuration
Returns the value of thecpuDurationrecord component.- Returns:
- the value of the
cpuDurationrecord component
-
alive
-