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§
- Process
Start - 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 fixedUSER_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>/statline. Why:parseLinuxStat: the command name ends at the last); field 22 must be a safe integer asNumberreads it. - parse_
lstart - What:
The fields of a
ps -o lstart=line: year, month (0 to 11), day, hour, minute, second. Why:Date.parsereads this local-time form; the conversion to an instant happens apart. - parse_
uptime - What:
The seconds since boot in
/proc/uptimetext, its first field. Why: The start isnow - 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:
resolveProcessStartwith the host’s mechanism.