Skip to main content

Module process_start

Module process_start 

Source
Expand description

Process start times for lock owners, read from /proc, ps or the Windows process table. What: The wall-clock start time of a process, with its resolution, for comparing a Git lock PID file’s owner with the lock’s change time. Why: A PID file names a live owner only when that process started no later than the lock changed; a younger process reused the PID. Linux derives the start from /proc/<pid>/stat field 22, /proc/uptime and the current time; macOS reads ps -o lstart=; Windows reads Get-Process StartTime (src/index-lock/process-start-time.ts).

In TS you’d write (pseudocode):

const start = await resolveProcessStart({ pid });

Enums§

ProcessStart
What: When a process started, or why that is not known. Why: ProcessStart.

Constants§

DARWIN_RESOLUTION_MS
Resolution of ps -o lstart=, which prints whole seconds.
LINUX_RESOLUTION_MS
Resolution of a Linux start time: one tick plus the centisecond resolution of /proc/uptime.
LINUX_USER_HZ
Clock ticks per second in /proc/<pid>/stat, the kernel’s fixed USER_HZ.
START_TICKS_FIELD_INDEX
Index of the start-tick field among the fields after the command name (field 22 overall).
WINDOWS_RESOLUTION_MS
Resolution granted to Windows start times.

Functions§

linux_start
What: A Linux process’s start from a proc root. Why: linuxStart; a vanished stat file or a zombie is a missing process.
now_ms
What: The current time in milliseconds since the epoch. Why: Date.now().
parse_linux_stat
What: The state letter and start ticks of a /proc/<pid>/stat line. Why: parseLinuxStat: the command name ends at the last ); field 22 must be a safe integer as Number reads it.
parse_lstart
What: The fields of a ps -o lstart= line: year, month (0 to 11), day, hour, minute, second. Why: Date.parse reads this local-time form; the conversion to an instant happens apart.
parse_uptime
What: The seconds since boot in /proc/uptime text, its first field. Why: The start is now - uptime + ticks / USER_HZ.
process_exists
What: Whether a process with this PID exists; a permission denial means it does. Why: processExists.
resolve_process_start
What: Whether a PID names a running process and when it started. Why: resolveProcessStart with the host’s mechanism.