killAllWatchers function

Future<void> killAllWatchers({
  1. bool silent = false,
})

Implementation

Future<void> killAllWatchers({bool silent = false}) async {
  final ps = await Process.run('ps', ['aux']);

  if (ps.exitCode != 0) {
    if (!silent) print('❌ Failed to run ps command.');
    return;
  }

  final lines = (ps.stdout as String).split('\n');

  for (final line in lines) {
    if (line.contains('commands') && line.contains('watch') && !line.contains('grep')) {
      final parts = line.trim().split(RegExp(r'\s+'));
      if (parts.length > 1) {
        final pid = int.tryParse(parts[1]);
        if (pid != null) {
          try {
            Process.killPid(pid);
            if (!silent) print('💀 Killed commands watcher PID: $pid');
          } catch (e) {
            if (!silent) print('❌ Failed to kill PID $pid: $e');
          }
        }
      }
    }
  }
}