Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 3583434

Browse files
committed
Fix process enumeration bug on Linux
To find all of the processes on the system, we enumerate procfs looking for all of the pids, and then try to parse the data for each pid. Between the time that we find a pid and try to open the relevant file for it, the process might go away, resulting in an exception. We're currently catching FileNotFoundException, but other IOExceptions are possible for the same condition. Same goes for subsequently enumerating the threads associated with a process. The fix is simply to be a bit more lenient in what we catch..
1 parent ae73c4f commit 3583434

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

src/System.Diagnostics.Process/src/System/Diagnostics/ProcessManager.Linux.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ private static ProcessInfo CreateProcessInfo(int pid)
9696
// arbitrary other processes.
9797
};
9898
}
99-
catch (FileNotFoundException)
99+
catch (IOException)
100100
{
101101
// Between the time that we get an ID and the time that we try to read the associated stat
102102
// file(s), the process could be gone.
@@ -128,8 +128,7 @@ private static ProcessInfo CreateProcessInfo(int pid)
128128
}
129129
}
130130
}
131-
catch (FileNotFoundException) { } // process and/or threads may go away by the time we try to read from them
132-
catch (DirectoryNotFoundException) { }
131+
catch (IOException) { } // process and/or threads may go away by the time we try to read from them
133132

134133
// Finally return what we've built up
135134
return pi;

0 commit comments

Comments
 (0)