Skip to content

Process discovery and classification

Daemonitor discovers build processes passively by enumerating OS processes on each poll cycle and matching executable and command-line signatures—no build-tool instrumentation is required for live monitoring.

Discovery pipeline

In daemonitor-cored (cored/internal/poll/poll.go), each poll runs in two passes:

  1. Pass 1 — OS discovery and classification:
  2. Enumerates PIDs via gopsutil and reads each process's command line.
  3. Applies strict-precedence classification rules. Processes that do not match any rule are dropped (there is no UNKNOWN catch-all type).
  4. Collects OS metrics (RSS, virtual memory, CPU counters, threads, I/O, page faults, context switches, file descriptors, and platform-specific metrics such as macOS proc_pid_rusage or Linux cgroups/PSS).
  5. Pass 1b (Xcode children): If at least one XCODE_BUILD or XCODE_BUILD_SERVICE process is live, candidate child tools (codesign, lipo, strip, plutil, sh/bash/zsh, or unscoped compilers) are verified by walking parent PIDs up to depth 6.
  6. Pass 2 — Bounded JVM probes:
  7. Runs jcmd, jstat, and jinfo concurrently up to ProbeConcurrency (default 2) with a 750ms timeout per probe on eligible JVM processes.
  8. Probe failures never drop the process's OS row; unavailable JVM fields remain null and record sanitized diagnostics (heap_probe_diagnostics).

In the Kotlin --jvm-collector fallback (ProcessCollector.kt), OSHI enumerates processes scoped to the same effective UID (excluding selfPid), and skips Pass 1b Xcode ancestor-child verification.

Classification dimensions

Daemonitor classifies every discovered process along four independent dimensions (cored/internal/model/classification.go and ProcessClassification.kt):

Dimension Values Purpose
BuildSystem GRADLE, BAZEL, XCODE, AMPER (Kotlin Toolchain), UNKNOWN Build system responsible for the process (display order: Gradle → Bazel → Xcode → Kotlin Toolchain → Other / Unknown)
Runtime JVM, NATIVE, UNKNOWN Execution runtime — controls column layouts and gates live JVM probing (jcmd/jstat)
Toolchain JAVA, KOTLIN, SWIFT, CLANG, CPP, GO, RUST, UNKNOWN Language/compiler toolchain associated with the process
ProcessType GRADLE_DAEMON, BAZEL_SERVER, BAZEL_WORKER, BAZEL_TEST, KOTLIN_DAEMON, KOTLIN_TOOLCHAIN, XCODE_BUILD, etc. Specific role of the observed process

Classification examples

Workload BuildSystem Runtime Toolchain ProcessType
Gradle Kotlin daemon GRADLE JVM KOTLIN KOTLIN_DAEMON
Bazel rules_kotlin worker BAZEL JVM KOTLIN BAZEL_WORKER
Bazel Swift persistent worker BAZEL NATIVE SWIFT BAZEL_WORKER
Bazel native test leaf BAZEL NATIVE UNKNOWN / toolchain BAZEL_TEST
Xcode Swift compiler XCODE NATIVE SWIFT XCODE_COMPILER
Kotlin Toolchain / Amper CLI AMPER JVM KOTLIN KOTLIN_TOOLCHAIN
Unattributed Kotlin daemon UNKNOWN JVM KOTLIN KOTLIN_DAEMON

Ambiguous classifications and conservative fallbacks

  • Build system: Validated OS ancestry takes precedence (BazelOwnerPID > HasAmperAncestor > HasGradleAncestor > HasXcodeAncestor), followed by command-line markers. An unattributed KOTLIN_DAEMON defaults to BuildSystem.UNKNOWN rather than assuming Gradle.
  • Runtime: BAZEL_WORKER, BAZEL_TEST, and GRADLE_WRAPPER inspect the OS executable (java/javaw → JVM; shell/sandbox wrappers → NATIVE; ambiguous → UNKNOWN). Live JVM probing runs only when runtime == JVM and the executable is a JVM binary.

Process identity and PID reuse protection

Operating systems reuse PIDs after a process exits. Daemonitor guards against PID-reuse corruption across every layer using (pid, createTimeMs) (plus hostID in SQLite):

  • CPU delta calculation: Keyed by incarnationKey{pid, createTimeMs} with monotonic counter checks (user, system, total must not decrease).
  • Platform collector: If the OS reports a creation time differing by > 1000ms from the expected CreateTimeMs, metrics are marked stale.
  • JVM probe cache: Keyed by (pid, startTimeMs).
  • SQLite lifecycle tracking: process_instances.id = "<hostID>:<pid>:<createTimeMs>" (UNIQUE(host_id, pid, create_time_ms)), emitting process.first_observed, process.disappearance_detected, and process.configuration_observed events without fabricating exit codes.
  • TUI termination & hierarchy: Verifies live OS CreateTime matches startTimeMs immediately before sending a termination signal.