isProcessRunning function

Future<bool> isProcessRunning(
  1. int pid
)

Implementation

Future<bool> isProcessRunning(int pid) async {
  if (Platform.isWindows) {
    var result = await Process.run(
      'powershell',
      ['ps', '-Id', '$pid'],
      runInShell: true,
    );
    return result.exitCode == 0;
  } else if (Platform.isLinux || Platform.isMacOS) {
    var result = await Process.run(
      'ps',
      ['$pid'],
      runInShell: true,
    );
    return result.exitCode == 0;
  }

  throw UnsupportedError(
      'Not able to find parent process on ${Platform.operatingSystem}');
}