Repository navigation
Process.Unix: reap all processes when running as pid 1. - #65061
Conversation
pid 1 (the init daemon) is responsible for reaping orphaned children. Because containers usually don't have an init daemon .NET may be pid 1.
|
I couldn't figure out the best area label to add to this PR. If you have write-permissions please help me learn by adding exactly one area label. |
|
I'll manually verify this, and share the results here. |
|
Tagging subscribers to this area: @dotnet/area-system-diagnostics-process Issue Detailspid 1 (the init daemon) is responsible for reaping orphaned children. Fixes #45017. @adamsitnik ptal.
|
|
I used the following test app in a container where .NET runs as pid 1. if (ExecFunction.IsExecFunctionCommand(args))
{
return ExecFunction.Program.Main(args);
}
else
{
while (true)
{
var process = ExecFunction.Start(
() =>
{
for (int i = 0; i < 10; i++)
{
ExecFunction.Start(() =>
{
Console.WriteLine("Grand-child launched.");
System.Threading.Thread.Sleep(500);
});
}
});
process.WaitForExit();
System.Threading.Thread.Sleep(1000);
System.Console.WriteLine($"Nr of proc entries: {Directory.GetFileSystemEntries("/proc").Count()}");
}
}As shown by the output below .NET 6 doesn't cleanup the orphaned children. And with this change, it does. Using .NET 6: With this patch: |
adamsitnik
left a comment
There was a problem hiding this comment.
@tmds thank you for the fix and description of testing steps! Overall it LGTM, I just wonder whether we could reuse the process id in one place (please see my comment).
|
I've tried to use a magic URL to re-trigger the check, but I've failed. I am going to close and re-open the PR. |

pid 1 (the init daemon) is responsible for reaping orphaned children.
Because containers usually don't have an init daemon .NET may be pid 1.
Fixes #45017.
@adamsitnik ptal.