"""Operational process state for the three project services; no customer scan.""" def service_processes(payload): result={} for name in ('rmm-agent-remote.service','rmm-helper-cloud.service','rmm-apt-helper.service'): values=subprocess.run(['systemctl','show',name,'-p','ActiveState','-p','SubState','-p','MainPID','-p','NRestarts'], capture_output=True,check=True,timeout=10).stdout.decode() fields=dict(line.split('=',1) for line in values.splitlines() if '=' in line) pid=int(fields['MainPID']);processes=[] # Kernel scheduling metadata only; never command lines, environment, # descriptors, credentials, arbitrary process memory or customer logs. if pid: pending=[pid] while pending and len(processes)<32: current=pending.pop(0);root=Path('/proc')/str(current) if not root.exists():continue processes.append(dict(pid=current,comm=(root/'comm').read_text().strip(),wchan=(root/'wchan').read_text().strip(), state=next((s.split(':',1)[1].strip() for s in (root/'status').read_text().splitlines() if s.startswith('State:')),None))) processes[-1]['threads']=[dict(tid=int(p.name),comm=(p/'comm').read_text().strip(),wchan=(p/'wchan').read_text().strip()) for p in sorted((root/'task').iterdir())[:32] if p.is_dir()] children=root/'task'/str(current)/'children' if children.exists():pending.extend(int(s) for s in children.read_text().split()) result[name]=dict(service=fields,processes=processes) return result