processTable function

Future<Map<int, String>> processTable()

Every live process by PID, as ps reports it.

LOUD when ps fails: this census is the only account of a server that outlived its store, and a silently empty answer is indistinguishable from a clean teardown — which is exactly the report that let an abandoned Dolt server sit on a station host for six days.

Implementation

Future<Map<int, String>> processTable() async {
  final result = await Process.run('ps', ['-axo', 'pid=,command=']);
  if (result.exitCode != 0) {
    throw StateError(
      'ps census failed (${result.exitCode}): ${result.stdout}${result.stderr}',
    );
  }
  final row = RegExp(r'^\s*(\d+)\s+(.*)$');
  return {
    for (final line in (result.stdout as String).split('\n'))
      if (row.firstMatch(line) case final match?)
        int.parse(match.group(1)!): match.group(2)!,
  };
}