os: CurrentProcess resources, processors and memory limit (OS slice 2, part 3) #252

Closed
opened 2026-10-09 06:16:21 +00:00 by orion · 4 comments
Collaborator

Goal

The second half of CurrentProcess (OS.md section 5.9): what the process has used and what it is held to. Split from #126 (OS slice 2).

Source

Current state on main

No CurrentProcess exists yet; the first half (identifier, parentIdentifier, executable, workingDirectory, uptime) is #251 and creates std/os/src/process.trb. ByteSize is #126.

Scope

On CurrentProcess: resources(): Result<ProcessResources, OsError> (userTime, systemTime, resident, peakResident; getrusage on POSIX with the ru_maxrss unit arm of OS.md, GetProcessTimes and GetProcessMemoryInfo on Windows), processors(): Result<Int, OsError> (affinity mask, container CPU quota rounded up: sched_getaffinity plus cgroup cpu.max on Linux, GetProcessAffinityMask plus job-object CPU rate on Windows, hw.ncpu on macOS), memoryLimit(): Result<ByteSize?, OsError> (cgroup memory.max v2 and v1 on Linux, job-object limit on Windows, None on macOS). FreeBSD arms answer Unsupported until the FreeBSD slice.

Acceptance criteria

  • resources(): after a loop that burns processor time and allocates 64 MiB, userTime + systemTime > 0, resident > 0, peakResident >= resident on linux-x64, linux-arm64, macos-arm64 and windows-x64; the ru_maxrss unit conversion is a pure function tested on every machine with captured values for both units.
  • processors() is between 1 and the machine's processor count; the cgroup cpu.max parser is pure and tested with captured files (max 100000, 150000 100000, v1 cpu.cfs_quota_us of -1).
  • memoryLimit() answers Ok(None) without a limit and Ok(Some(n)) with one; the cgroup memory.max parser (max, a number, a missing file) is pure and tested; a denied or hidden /sys is Ok(None), not an error, and the doc comment says so.
  • torb check --every-target std/os is clean; docs updated, skills/ regenerated.
  • CI coverage as in the sibling issue: linux-x64 on the forge, the other three through forge runners where configured and otherwise the portable workflow; the real-system tests run there, the parsers on every machine.

Seed

None: the compiler does not use these natives, so one commit adds natives and their users together (feat(os): ...).

Size

One PR, one Conventional Commit.

Dependencies

#251 (creates the module) and #126 (ByteSize).

## Goal The second half of `CurrentProcess` (OS.md section 5.9): what the process has used and what it is held to. Split from #126 (OS slice 2). ## Source - [OS.md section 5.9](https://git.torb.dev/torbscript/language/src/commit/9889e8f998db8d4289b23fe9ce9441607e986c2e/docs/design/OS.md#L1310) - [OS.md slice 2](https://git.torb.dev/torbscript/language/src/commit/9889e8f998db8d4289b23fe9ce9441607e986c2e/docs/design/OS.md#L1622) ## Current state on main No `CurrentProcess` exists yet; the first half (`identifier`, `parentIdentifier`, `executable`, `workingDirectory`, `uptime`) is #251 and creates `std/os/src/process.trb`. `ByteSize` is #126. ## Scope On `CurrentProcess`: `resources(): Result<ProcessResources, OsError>` (`userTime`, `systemTime`, `resident`, `peakResident`; `getrusage` on POSIX with the `ru_maxrss` unit arm of OS.md, `GetProcessTimes` and `GetProcessMemoryInfo` on Windows), `processors(): Result<Int, OsError>` (affinity mask, container CPU quota rounded up: `sched_getaffinity` plus cgroup `cpu.max` on Linux, `GetProcessAffinityMask` plus job-object CPU rate on Windows, `hw.ncpu` on macOS), `memoryLimit(): Result<ByteSize?, OsError>` (cgroup `memory.max` v2 and v1 on Linux, job-object limit on Windows, `None` on macOS). FreeBSD arms answer `Unsupported` until the FreeBSD slice. ## Acceptance criteria - [ ] `resources()`: after a loop that burns processor time and allocates 64 MiB, `userTime + systemTime > 0`, `resident > 0`, `peakResident >= resident` on linux-x64, linux-arm64, macos-arm64 and windows-x64; the `ru_maxrss` unit conversion is a pure function tested on every machine with captured values for both units. - [ ] `processors()` is between 1 and the machine's processor count; the cgroup `cpu.max` parser is pure and tested with captured files (`max 100000`, `150000 100000`, v1 `cpu.cfs_quota_us` of -1). - [ ] `memoryLimit()` answers `Ok(None)` without a limit and `Ok(Some(n))` with one; the cgroup `memory.max` parser (`max`, a number, a missing file) is pure and tested; a denied or hidden `/sys` is `Ok(None)`, not an error, and the doc comment says so. - [ ] `torb check --every-target std/os` is clean; docs updated, `skills/` regenerated. - [ ] CI coverage as in the sibling issue: linux-x64 on the forge, the other three through forge runners where configured and otherwise the portable workflow; the real-system tests run there, the parsers on every machine. ## Seed None: the compiler does not use these natives, so one commit adds natives and their users together (`feat(os): ...`). ## Size One PR, one Conventional Commit. ## Dependencies #251 (creates the module) and #126 (`ByteSize`).
Author
Collaborator

[loop:torbscript] intake: in scope (author orion, label loop, split from #126), not a duplicate, no collision with a design record (OS.md 5.9). Body is complete. next: waiting (dependency #251 creates std/os/src/process.trb) until 2026-10-10T04:00:00Z

[loop:torbscript] intake: in scope (author orion, label loop, split from #126), not a duplicate, no collision with a design record (OS.md 5.9). Body is complete. next: waiting (dependency #251 creates std/os/src/process.trb) until 2026-10-10T04:00:00Z
Author
Collaborator

[loop:torbscript] refine: ready as written. Dependency #251 part 1 landed (PR #262, std/os/src/process.trb exists with CurrentProcess); #126 landed (ByteSize). No seed impact (the compiler uses none of the new natives), so one commit is enough.

[loop:torbscript] refine: ready as written. Dependency #251 part 1 landed (PR #262, std/os/src/process.trb exists with CurrentProcess); #126 landed (ByteSize). No seed impact (the compiler uses none of the new natives), so one commit is enough.
Author
Collaborator

[loop:torbscript] claim implement by session:loop-torbscript-20261009 until 2026-10-09T16:20Z

[loop:torbscript] claim implement by session:loop-torbscript-20261009 until 2026-10-09T16:20Z
argus closed this issue 2026-10-09 12:02:11 +00:00
Author
Collaborator

[loop:torbscript] close: PR #263 approved and merged by argus at 2026-10-09T12:02Z as 0a1a03f0 (feat(os): add CurrentProcess resources, processors and memory limit); the issue closed with the merge. Main CI on 0a1a03f0 is running at the time of this comment. Claim released. OS slice 2 part 2 (#251) still waits for a published seed.

[loop:torbscript] close: PR https://git.torb.dev/torbscript/language/pulls/263 approved and merged by argus at 2026-10-09T12:02Z as 0a1a03f0 (`feat(os): add CurrentProcess resources, processors and memory limit`); the issue closed with the merge. Main CI on 0a1a03f0 is running at the time of this comment. Claim released. OS slice 2 part 2 (#251) still waits for a published seed.
Sign in to join this conversation.
No labels
loop
ready
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
torbscript/language#252
No description provided.