- May
- 13,193
- 180
In another thread, there's some discussion about using ON CLOSE to TASKEND some _STARTPIDs. A better solution to that is to put the STARTed processes in a job with JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE; they will terminate automatically when the instance that STARTed them terminates (taking all the job handles with it).. That's what JOBS /K is supposed to do, but it doesn't. When I "JOBS /n=job1 /k" TCC does this.
The "4" circled is JobObjectBasicUIRestrictions, not appropriate for setting JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE (which needs JobObjectExtendedLimitInformation (9)).
To verify that the strategy does work, I got around the difficulty with a plugin (JOB) to give the job the desired limit. Snippets:
Here's that code in action.
At this point, any process I start with "START /JOB=job1 ... " will terminate automatically when the current TCC terminates.
The "4" circled is JobObjectBasicUIRestrictions, not appropriate for setting JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE (which needs JobObjectExtendedLimitInformation (9)).
To verify that the strategy does work, I got around the difficulty with a plugin (JOB) to give the job the desired limit. Snippets:
Code:
else if ( !_wcsicmp(argv[i], L"/Q") ) // query KILL-ON-CLOSE
{
JOBOBJECT_EXTENDED_LIMIT_INFORMATION jo_eli;
DWORD dwLen;
QueryInformationJobObject(hJob, JobObjectExtendedLimitInformation, &jo_eli, sizeof(jo_eli), &dwLen);
BOOL bKillOnClose = (jo_eli.BasicLimitInformation.LimitFlags & JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE);
Printf(L"JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE ... %s\r\n", bKillOnClose ? L"Yes" : L"No");
}
else if ( !_wcsicmp(argv[i], L"/K") ) // set KILL-ON-CLOSE
{
JOBOBJECT_EXTENDED_LIMIT_INFORMATION jo_eli;
DWORD dwLen;
QueryInformationJobObject(hJob, JobObjectExtendedLimitInformation, &jo_eli, sizeof(jo_eli), &dwLen);
jo_eli.BasicLimitInformation.LimitFlags |= JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE;
SetInformationJobObject(hJob, JobObjectExtendedLimitInformation, &jo_eli, sizeof(jo_eli));
}
At this point, any process I start with "START /JOB=job1 ... " will terminate automatically when the current TCC terminates.