Children processes created in ASP.NET Core Process gets killed on exit
See the question and my original answer on StackOverflowAs I said in my comment, there is a Job Object which is created by ASP.NET core in the out-of-process scenario. The relevant source code portion is here:
HRESULT
SERVER_PROCESS::SetupJobObject(VOID)
{
HRESULT hr = S_OK;
JOBOBJECT_EXTENDED_LIMIT_INFORMATION jobInfo = { 0 };
if (m_hJobObject == NULL)
{
....
jobInfo.BasicLimitInformation.LimitFlags =
JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE;
if (!SetInformationJobObject(m_hJobObject,
JobObjectExtendedLimitInformation,
&jobInfo,
sizeof jobInfo))
{
hr = HRESULT_FROM_WIN32(GetLastError());
}
}
}
return hr;
}
As per documentation, JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE:
Causes all processes associated with the job to terminate when the last handle to the job is closed.
If you dig the source further, it does not seem to be optional.
Now, you can actually see this by yourself, if you reproduce your steps. Use Process Explorer, and navigate to your dotnet.exe process, this is what it will display:
- note 1: in fact
calc.exe
stays alive (at least in my Windows 10 installation because it's now a WinRT app, so it will not end up as child of dotnet.exe), that's why I usednotepad.exe
- note 2:
iisexpress.exe
also creates a job object, but it's configured as breakaway ok, which means it won't kill child processes. - note 3: if you run from Visual Studio (not my screenshot), you may see an intermediary
VSIISExeLauncher.exe
process betweeniisexpress.exe
anddotnet.exe
. This one also creates a Job Object with 'kill on close' to add to the confusion...