checkProcess function
Looks pid up with ps: stopped on state T, gone only when ps says there is no such process, unknown when ps fails.
Implementation
Future<ProcessCheck> checkProcess(int pid) async {
try {
final r = await runBounded('ps', ['-o', 'stat=', '-p', '$pid'], timeout: const Duration(seconds: 2), phase: 'ps');
final state = (r.stdout as String).trim();
if (r.exitCode == 0 && state.isNotEmpty) {
if (state.startsWith('Z')) return (life: ProcessLife.gone, state: state);
return (life: state.startsWith('T') ? ProcessLife.stopped : ProcessLife.running, state: state);
}
return r.exitCode == 1 && state.isEmpty ? (life: ProcessLife.gone, state: null) : _unknownProcess;
} on Object {
return _unknownProcess;
}
}