kill static method
Future<List<int> >
kill(
- Iterable<
int> pids, { - ProcessSignal signal = io.ProcessSignal.sigterm,
- bool tree = false,
- Duration timeout = const Duration(seconds: 5),
Kills the processes pids and waits for them to exit: signal
(sigterm by default) first, then sigkill for the ones still running
after timeout (2 more seconds for these).
tree kills their descendants too (descendantsOf, read before the
first signal). The current process is never killed. On Windows every
signal terminates the process at once.
Returns the pids still running at the end (the descendants included, the ones not allowed to be killed too), empty when all exited.
Implementation
static Future<List<int>> kill(
Iterable<int> pids, {
io.ProcessSignal signal = io.ProcessSignal.sigterm,
bool tree = false,
Duration timeout = const Duration(seconds: 5),
}) async {
var targets = <int>{...pids};
if (tree && targets.isNotEmpty) {
targets.addAll(processTableDescendantIds(await readProcessTable(), pids));
}
targets.remove(io.pid);
if (targets.isEmpty) {
return [];
}
for (var pid in targets) {
_killPid(pid, signal);
}
var remaining = await _waitProcessesExit(targets.toList(), timeout);
if (remaining.isNotEmpty && signal != io.ProcessSignal.sigkill) {
for (var pid in remaining) {
_killPid(pid, io.ProcessSignal.sigkill);
}
remaining = await _waitProcessesExit(
remaining,
const Duration(seconds: 2),
);
}
return remaining;
}