Expand description
Safe wrappers for the operating-system calls the native host needs that the standard library does not offer at the minimum Rust version: file locks, no-replace publishing, termination handling, parent and child lifetime, memory shared with a worker, clocks, memory, and the OS version.
In iOS and Android apps the system owns the process, so the termination, parent-exit and child-lifetime calls have no use there; files, clocks, memory and the version do.
Macros§
- diagnostic
eprintln!through the process’s diagnostic sink (write_diagnostic).
Structs§
- Awake
Instant - A point on a clock that stops while the system sleeps, so stall checks ignore suspend.
- Cgroup
Memory - The lowest memory limit on this process’s cgroup path and what is charged against it.
- Cgroup
Memory Watch - Reads
CgroupMemoryrepeatedly for a watch, finding the lowest limit’s level again after a failed read. BelowSelf::STAT_FROM_PERCENTof the limit the working set is the charge. - Descriptor
Reader - Reads a Unix stream socket and keeps, in arrival order, the descriptors that come with its
bytes, each closed on
exec. A read that receives more than one descriptor at once closes them and fails withInvalidData. - Kill
OnClose Job - A Windows job that kills its processes when dropped or when this process ends, for probe children that may hang. A no-op elsewhere.
- Mapped
Region - A worker’s side of a region: mapped read-only.
- Memory
Capacity - The machine’s memory and this process’s limit. Unavailable figures are
None. - Name
Limit - The longest file name a directory takes.
- Process
Memory - The process’s memory, as the operating system counts it.
- Published
- A finished file moved into place.
- Retry
Policy - How long a publish retries a step refused by another program’s open handle.
- Shared
Region - The host’s side of a region, mapped read-write: a sealed
memfdon Linux, a POSIX shared memory object unlinked at once on macOS, an unnamed section on Windows. - Termination
- A request to end the process: an interrupt or termination signal on Unix, a console control event on Windows.
Enums§
- Name
Unit - What a
NameLimitcounts. - Publish
Method - How
publish_no_replaceorpublish_replacemoved a file into place.
Functions§
- cgroup_
memory CgroupMemoryof this process, read now;Nonewithout a cgroup memory limit.- cgroup_
memory_ at cgroup_memorywithrootstanding in for/. Levels without a limit (max, or v1’s near-u64::MAXdefault) are skipped; v2 is read first.- child_
exited - Whether
childhas ended, without reaping it: until it is waited for, its id names it and the process group it leads, sokill_process_treestill reaches what it started. - claim_
stdin - Takes standard input for a protocol stream.
- claim_
stdout - Takes standard output for a protocol stream.
- close_
descriptors_ except - Closes every descriptor above standard error except those of
keep(Unix only). Call it at the start of the process, before anything opens a descriptor it keeps. - create_
private_ directory - Creates
pathand its missing parents for files only this user may change. - disable_
crash_ dumps - Turns off core files (Unix) and crash dialogs (Windows) for this process.
- exit_
without_ handlers - Ends the process now with
code, without running exit handlers. The caller must flush first. - file_
version - The
major.minor.build.revisionfrom the Windows version resource ofpath;Noneelsewhere or without one. - host_
cache_ directory - The host’s cache directory, as the Node and Python clients name it, or
Nonewithout a home. - host_
cache_ directory_ from host_cache_directorywith the environment read throughvariable.- is_
retryable_ publish_ error - Whether a publish step failed because another program (antivirus, indexer, media player)
briefly holds the file open:
ERROR_ACCESS_DENIED,ERROR_SHARING_VIOLATIONorERROR_LOCK_VIOLATIONon Windows. Alwaysfalseon Unix, where open handles do not block a rename. - kill_
process_ tree - Kills
childand, on Unix, every process of the groupown_process_treegave it; call it before the child is reaped, while its id still names the group. On Windows dropping the child’s job ends the processes the child started. - limit_
heap_ arenas - Caps glibc’s malloc arenas at
arenasunlessMALLOC_ARENA_MAXis set. Does nothing elsewhere. - memory_
capacity - The machine’s memory and this process’s limit, read now.
- memory_
capacity_ at memory_capacitywithrootstanding in for/.- name_
limit - The longest file name
diraccepts:pathconf(_PC_NAME_MAX)on Unix (255 bytes if unreported), 255 UTF-16 units on Windows. - on_
termination - Calls
handleron its own thread when the process is asked to terminate, instead of ending at once.watch_parentcalls the same handler. - open_
file_ limit - The soft limit on open file descriptors;
Noneon Windows or where unlimited or unknown. - open_
handles - Handles the process holds open: file descriptors on Unix, kernel handles on Windows.
Nonewhere unavailable. - os_
version - The OS version, read once:
27.0.1 (26A434)on macOS and iOS,Ubuntu 22.04.5 LTS, kernel 6.8.0on Linux,Android 16 (API 36), kernel 6.1.0on Android,10.0.26300.9711on Windows. Missing parts are omitted;unknownif all are. - own_
process_ tree - Starts the child
commandspawns in its own process group (Unix) or without a console (Windows); on Windows also put the child in acrate::KillOnCloseJob. - prefer_
fast_ cores - Asks the scheduler to keep the calling thread on the fastest cores, so
thread_cpu_workreadings come from one kind of core:QOS_CLASS_USER_INTERACTIVEon Apple systems, noEcoQoSthrottling on Windows, nothing elsewhere. Best effort; failures are silent. - prefer_
out_ of_ memory_ kill - Makes this process the out-of-memory killer’s first choice (Linux). Does nothing elsewhere.
- process_
cpu_ time - User plus system CPU time of all the process’s threads so far;
Nonewhere unavailable. - process_
memory - The process’s memory now and at its peak; unavailable figures are
None. - publish_
no_ replace - Moves the finished file
fromtoto, never replacing an existing file atto. - publish_
replace - Moves the finished file
fromtoto, replacing any file there. Retryable errors are retried asretryallows. - quarantined
- Whether
pathhas the macOScom.apple.quarantineattribute, under which Gatekeeper refuses to load an unnotarized library.falseon other systems and for unreadable files. - same_
file - Whether
pathstill names the filefileis open on.falsewhen the path is gone, names a recreated file, or names a removed file kept visible by an open handle (Windows and SMB keep such names until the last handle closes). - same_
file_ at - Whether
aandbname one file (same device and inode, or volume serial and file index on Windows). Hard links and symlinks count as the same file.falsewhen either path is missing. - set_
diagnostic_ sink - Sends every later diagnostic line of the process to
sink, or withNoneback to standard error, or on Android, which discards an app’s standard error, to the system log asalpha2. - stop_
std_ handle_ inheritance - Stops children from implicitly inheriting this process’s standard handles (Windows only).
- sync_
directory - Makes renames into
dirsurvive a power loss byfsyncing it on Unix. File systems that cannot sync a directory are not an error. No-op on Windows, where the rename writes through. - thread_
cpu_ work - The calling thread’s CPU work so far, comparable only with other readings on the same thread:
CPU nanoseconds on Unix, cycles on Windows (
QueryThreadCycleTime). Excludes time spent waiting for a CPU.Nonewhere unavailable. - try_
lock_ exclusive - Takes an exclusive advisory lock on
filewithout waiting. ReturnsOk(false)when another open handle, in this or another process, holds it. - utf8_
arguments - The arguments as UTF-8 strings. Unlike
std::env::args, a non-UTF-8 argument is an error, not a panic. - watch_
parent - Calls the
crate::on_terminationhandler with aPARENT_EXITEDtermination (status 143) when the parent process exits, or at once if it already has. - with_
publish_ retries - Runs
stepuntil it succeeds, fails with a non-retryable error, orretrystops it. Waits 50 ms before the first retry, doubling up to 1 s. Returns the value and the retry count. - write_
diagnostic - Writes one diagnostic line to the sink
set_diagnostic_sinkchose. The default output drops the line instead of panicking when standard error is closed, so a client closing the pipe cannot abort an export. Usediagnostic!. - write_
with_ descriptor - Writes all of
bytestosocket, withdescriptorattached to the first of them, so that the reader receives a copy of it with those bytes (DescriptorReader).
Type Aliases§
- Diagnostic
Sink - Receives each diagnostic line in place of the default output.