#!/usr/bin/env python3 """ Mock llama-server process for NixOS VM tests. Sets /proc/self/comm to "llama-server" via prctl so that monitoring scripts (llama-cpp-annotations, llama-cpp-xmrig-pause) can discover this process the same way they discover the real one. Usage: python3 mock-llama-server-proc.py The state file controls behavior: "busy" -> burn CPU in a tight loop (simulates prompt processing / inference) "idle" -> sleep (simulates waiting for requests) """ import ctypes import ctypes.util import sys import time STATE_FILE = sys.argv[1] # PR_SET_NAME = 15, sets /proc/self/comm libc = ctypes.CDLL(ctypes.util.find_library("c"), use_errno=True) libc.prctl(15, b"llama-server", 0, 0, 0) with open(STATE_FILE, "w") as f: f.write("idle") while True: try: with open(STATE_FILE) as f: state = f.read().strip() except Exception: state = "idle" if state == "busy": end = time.monotonic() + 0.1 while time.monotonic() < end: _ = sum(range(10000)) else: time.sleep(0.5)