OS process
Represents the current native macOS process, including its identity, execution state, resource usage, and threads
Original source
The process information are provided by MacOsOSProcess, which inherits OSProcess
KInfo's source
Retrieve operatingSystem as shown in the Operating system API
Each access to procTaskAllInfo collects a new snapshot of the current process and its threads.
The returned object stores those values; reading its properties does not refresh them
Warning
Retrieving the process throws an IllegalStateException when the required native task information cannot be read
Properties
name
The name of the current process
path
The path to the process executable, or an empty string when unavailable
val path: String = currentProcess.path
println(path) // e.g. /Applications/KInfoDemo.app/Contents/MacOS/KInfoDemo
commandLine
The first entry in arguments, normally the executable path. The macOS implementation does not join the remaining arguments into a full command line
val commandLine: String = currentProcess.commandLine
println(commandLine) // e.g. /Applications/KInfoDemo.app/Contents/MacOS/KInfoDemo
arguments
The process arguments reported by Foundation, including the executable as the first entry
val arguments: List<String> = currentProcess.arguments
println(arguments) // e.g. [/Applications/KInfoDemo.app/Contents/MacOS/KInfoDemo, --mode, demo]
environmentVariables
The environment variables reported for the current process
val environmentVariables: Map<String, String> = currentProcess.environmentVariables
println(environmentVariables) // e.g. {LANG=en_US.UTF-8, APP_MODE=demo}
currentWorkingDirectory
The current working directory, or an empty string when unavailable
val currentWorkingDirectory: String = currentProcess.currentWorkingDirectory
println(currentWorkingDirectory) // e.g. /Users/demo
user
The username associated with the process user ID, or an empty string when the lookup fails
userId
The process user ID represented as a string
group
The group name associated with the process group ID, or an empty string when the lookup fails
groupId
The process group ID represented as a string
state
The process execution state mapped from its native status. The native process mapping returns NEW, RUNNING,
SLEEPING, STOPPED, ZOMBIE, or OTHER
State entries
The State enum is shared by processes and threads. The available entries are:
| State | Description |
|---|---|
| NEW | Intermediate state in process creation |
| RUNNING | Actively executing |
| SLEEPING | Interruptible sleep or a native waiting thread |
| WAITING | Uninterruptible thread wait |
| ZOMBIE | Intermediate state in process termination |
| STOPPED | Stopped process, or stopped or halted thread |
| OTHER | A native state not recognized by the mapper |
| INVALID | Shared enum entry not emitted by the native macOS process or thread mapper |
| SUSPENDED | Shared enum entry not emitted by the native macOS process or thread mapper |
processId
The identifier of the current process
parentProcessId
The identifier of the parent process
threadCount
The number of threads reported by the native task query. The separately collected threadDetails list can contain fewer entries
priority
The scheduling priority reported for the process
virtualSize
The virtual memory size of the process in bytes
residentMemory
The resident memory size of the process in bytes
privateResidentMemory
The physical memory footprint reported by macOS in bytes. This uses ri_phys_footprint, rather than subtracting
shared pages from residentMemory. A failed native resource query returns -1
val privateResidentMemory: Long = currentProcess.privateResidentMemory
println(privateResidentMemory) // e.g. 58720256
kernelTime
The cumulative time spent by the process in kernel mode in milliseconds, or -1 when the resource usage query fails
userTime
The cumulative time spent by the process in user mode in milliseconds, or -1 when the resource usage query fails
startTime
The process start time in milliseconds since the Unix epoch
bytesRead
The cumulative disk I/O bytes read by the process, or -1 when the native resource query fails
bytesWritten
The cumulative disk I/O bytes written by the process, or -1 when the native resource query fails
openFiles
The number of open file descriptors reported for the process
softOpenFileLimit
The current soft limit for open file descriptors, or -1 when the limit query fails
val softOpenFileLimit: Long = currentProcess.softOpenFileLimit
println(softOpenFileLimit) // e.g. 256
hardOpenFileLimit
The current hard limit for open file descriptors, or -1 when the limit query fails
val hardOpenFileLimit: Long = currentProcess.hardOpenFileLimit
println(hardOpenFileLimit) // e.g. 10240
processCpuLoadCumulative
The ratio of accumulated process CPU time (userTime + kernelTime) to elapsed time since the process started.
The value is not normalized by the processor count and can exceed 1.0 when multiple threads use multiple CPUs.
Multiply by 100 to express the value as a percentage of one CPU
A zero elapsed time returns 0.0. Failed CPU-time queries can produce a negative result
val processCpuLoadCumulative: Double = currentProcess.processCpuLoadCumulative
println(processCpuLoadCumulative) // e.g. 0.2
processCpuLoadBetweenTicks
The ratio of CPU time gained to elapsed time since the previous registered sample. Like the cumulative load,
this value can exceed 1.0
The first sample, an interval shorter than one second, or a decrease in CPU time uses processCpuLoadCumulative
as a fallback. Read operatingSystem.procTaskAllInfo again after at least one second to collect another sample;
reading this property on the same process object returns its stored value
val processCpuLoadBetweenTicks: Double = currentProcess.processCpuLoadBetweenTicks
println(processCpuLoadBetweenTicks) // e.g. 0.35
bitness
The process bitness derived from its native flags: 32 or 64
affinityMask
A mask synthesized from the available logical processor count. It does not describe a queried scheduling restriction.
The result is 0 for a nonpositive count and -1 for 64 or more logical processors
updateAttributes
Whether this object supports updating its attributes. The native implementation returns false; retrieve
operatingSystem.procTaskAllInfo again for a new snapshot
threadDetails
The list of threads captured for the current process. Entries whose native details cannot be read are omitted, and the list can be empty
minorFaults
The native task fault count minus its page-in count
majorFaults
The native task page-in count
contextSwitches
The combined context switch count reported by the native task query. The voluntary and involuntary counters are collected separately, so their sum can differ from this snapshot
voluntaryContextSwitches
The voluntary context switches reported for the current process across its threads, or -1 when the resource usage query fails
val voluntaryContextSwitches: Long = currentProcess.voluntaryContextSwitches
println(voluntaryContextSwitches) // e.g. 15000
involuntaryContextSwitches
The involuntary context switches reported for the current process across its threads, or -1 when the resource usage query fails