code wiki / (root) / nx_os_proc.nx

nx_os_proc.nx

buildroot/runtime/nx_os_proc.nx

12121 B243 linesdepth 2pulls 2 transitivereach 14 importersview sourcekind librarytopic os
docsdependenciesstructsconstsfunctions

about

nx_os_proc.nx -- OS PROCESS-INTROSPECTION abstraction (the PORTABILITY SEAM). THE ONE place OS-specific process access lives, so every tool above it (nx_heal, ...) stays OS-AGNOSTIC + portable. Interop by construction: ONE source compiles to BOTH backends via the @ifdef target guard -- LINUX backend = procfs (/proc/<pid>/{stat,cmdline}, getdents on /proc) [current NAS deploy] NISHIOS backend = native process table (@ifdef TARGET_NISHI seam) -- superior: a direct kernel query, NO text-parsing of /proc, NO USER_HZ guesswork. FAILS LOUD until wired, so a NishiOS build never silently inherits Linux assumptions. LAW (portability): NEVER scatter raw /proc, /sys, /dev, or hardcoded syscall numbers through the LOGIC layer -- put OS-specifics behind an nx_os_* seam like this one. The sovereign core (seg_store, tool logic) already only touches nx_syscalls (ABI-abstracted); this extends the same discipline to OS features. license_tier: ORIGINAL

dependencies 1 imports · 3 importers

nx_syscalls.nx nx_os_proc.nx nx_fsops_lib.nx nx_heal_lib.nx nx_leak_check_lib.nx

imports: nx_syscalls.nx

imported by: nx_fsops_lib.nxnx_heal_lib.nxnx_leak_check_lib.nx

structs

none

consts

14const OSP_HZ_LINUX: i64 = 100 // Linux USER_HZ: /proc/<pid>/stat starttime ticks/sec
15const OSP_PATH_CAP: i64 = 256
16const OSP_RD_CAP: i64 = 4096
17const OSP_STAT_CAP: i64 = 262144 // /proc/stat whole-file read cap (btime scan)
18const OSP_DENT_BUF: i64 = 65536 // getdents64 batch buffer (proven sizing)
19const OSP_F_PPID: i64 = 2 // /proc/<pid>/stat field after ')': state=1 ppid=2 ... utime=12 stime=13 ... starttime=20
20const OSP_F_START: i64 = 20
21const OSP_F_UTIME: i64 = 12 // user-mode CPU ticks (cumulative)
22const OSP_F_STIME: i64 = 13 // kernel-mode CPU ticks (cumulative)
23const OSP_ASCII_0: i64 = 48
24const OSP_ASCII_9: i64 = 57
25const OSP_SP: i64 = 32
26const OSP_NL: i64 = 10
27const OSP_RP: i64 = 41 // ')'
28const OSP_SLASH: i64 = 47
29const OSP_NUL: i64 = 0
30const OSP_SENTINEL: i64 = 0 - 1 // "not available on this OS backend"

functions

32func osp_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (OSP_NUL as u8) { n = n + 1 } return n }
called by 1: osp_list_pids
34func osp_itoa(v: i64, out: *u8) -> i64
called by 1: osp_ppath calls 1: sys_mmap
47func osp_num(buf: *u8, n: i64, off: i64, endp: *i64) -> i64
58func osp_basename(s: *u8) -> *u8
called by 1: osp_cmd_argv0
72func osp_bread(path: *u8, buf: *u8, cap: i64) -> i64
81func osp_ppath(out: *u8, pid: i64, leaf: *u8) -> i64
93func osp_list_pids(pids: *i64, cap: i64) -> i64
122func osp_fd_count(pid: i64) -> i64
151func osp_stat_field(pid: i64, fidx: i64) -> i64
174func osp_ppid(pid: i64) -> i64 { return osp_stat_field(pid, OSP_F_PPID) }
called by 1: nh_scan calls 1: osp_stat_field
175func osp_starttime_ticks(pid: i64) -> i64 { return osp_stat_field(pid, OSP_F_START) }
called by 2: nh_scanlk_proc_age_s calls 1: osp_stat_field
179func osp_cpu_ticks(pid: i64) -> i64
called by 1: main calls 1: osp_stat_field
187func osp_cmd_argv0(pid: i64, out: *u8, cap: i64) -> i64
200func osp_hz() -> i64 { return OSP_HZ_LINUX }
called by 2: nh_scanmain
203func osp_supervisor_log() -> *u8 { return "/tmp/supervisor.log" as *u8 }
called by 1: nh_diagnose
204func osp_uptime_s() -> i64 { let ts: *i64 = sys_mmap(16) as *i64; sys_clock_gettime_mono(ts); return ts[0] }
205func osp_selfpid() -> i64
213func osp_boot_epoch() -> i64