fix: check for running VM processes using kill -0

This commit is contained in:
Martin Wimpress 2024-07-03 11:31:19 +01:00 committed by Martin Wimpress
parent ada669500f
commit 679f5c3523
1 changed files with 4 additions and 2 deletions

View File

@ -156,8 +156,10 @@ class _ManagerState extends State<Manager> with PreferencesMixin {
File pidFile = File('$name/$name.pid');
if (pidFile.existsSync()) {
String pid = pidFile.readAsStringSync().trim();
Directory procDir = Directory('/proc/$pid');
if (procDir.existsSync()) {
// Check if the process is still running using kill -0, which is
// a portable way to check if a process is running on macOS and Linux.
ProcessResult result = Process.runSync('kill', ['-0', pid]);
if (result.exitCode == 0) {
if (_activeVms.containsKey(name)) {
activeVms[name] = _activeVms[name]!;
} else {