#!/usr/bin/env python3 """Run one child and report its wait4 peak RSS without /usr/bin/time.""" import os import resource import sys import time if len(sys.argv) < 2: raise SystemExit("usage: MeasureProcess.py executable [arguments ...]") address_limit, _ = resource.getrlimit(resource.RLIMIT_AS) stack_limit, _ = resource.getrlimit(resource.RLIMIT_STACK) if address_limit in (resource.RLIM_INFINITY, -1) or address_limit > 6 * 1024**3: raise SystemExit("run under prlimit --as=6442450944") if stack_limit in (resource.RLIM_INFINITY, -1) or stack_limit < 64 * 1024**2: raise SystemExit("run under prlimit --stack=67108864:67108864") if not os.sched_getaffinity(0).issubset(set(range(12))): raise SystemExit("run under taskset -c 0-11") print(f"[ProcessLimits] address_limit={address_limit} stack_limit={stack_limit} affinity={sorted(os.sched_getaffinity(0))}", flush=True) started = time.monotonic() pid = os.fork() if pid == 0: try: os.execvp(sys.argv[1], sys.argv[1:]) except OSError as error: print(f"MeasureProcess: exec failed: {error}", file=sys.stderr, flush=True) os._exit(127) _, status, usage = os.wait4(pid, 0) wall = time.monotonic() - started exit_code = os.waitstatus_to_exitcode(status) print(f"[ProcessResources] exit_code={exit_code} wall_s={wall:.6f} peak_rss_kib={usage.ru_maxrss}", flush=True) raise SystemExit(exit_code)