readProcessExecutable function

String? readProcessExecutable(
  1. int pid
)

Absolute path to the executable image of the process at pid, or null when the process is gone, inaccessible, or the host has no cheap way to resolve it.

Linux: reads /proc/<pid>/exe (always points at the original executable even after rename/delete). Windows: QueryFullProcessImageNameW via package:win32. macOS returns null - proc_pidpath via FFI is doable but not yet wired; macOS identity checks fall back to argv matching.

Implementation

String? readProcessExecutable(int pid) {
  if (Platform.isWindows) return _readWindowsImagePath(pid);
  if (Platform.isLinux) {
    try {
      return Link('/proc/$pid/exe').targetSync();
    } on FileSystemException {
      return null;
    }
  }
  return null;
}