Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Fixed JOBS /K doesn't work

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.
upload_2017-5-29_23-10-10.png

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));
}
Here's that code in action.
upload_2017-5-29_23-27-45.png

At this point, any process I start with "START /JOB=job1 ... " will terminate automatically when the current TCC terminates.
 
JOBS *does* use JobObjectExtendedLimitInformation to see the JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE option. However, in the current build the /K and /L options were reversed, so JOBS was setting the wrong flag. It has been fixed in build 29.

Note that your example won't work even with the fixed JOBS, because you're not closing the original handle.
 
JOBS *does* use JobObjectExtendedLimitInformation to see the JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE option. However, in the current build the /K and /L options were reversed, so JOBS was setting the wrong flag. It has been fixed in build 29.

Note that your example won't work even with the fixed JOBS, because you're not closing the original handle.
Thanks for the quick fix. I don't know what you mean in your second paragraph. If /K were working, I close the original handle (JOBS /C) then the processes in the job would terminate immediately. I want them to terminate when the job-creating instance terminates.

Another thing ... this strategy of getting STARTed processes to terminate when the STARTing process terminates doesn't work if a process is added to a job like this:
Code:
JOB /n=name /K PID
That's because, when added that way, the added process gets an open job handle and then, terminating the job-creating process doesn't close all the handles. See the difference: In the first below, all the job handles are in the host instance. In the second below, the process put into the job also gets a handle (can you prevent that?).
upload_2017-5-30_13-23-21.png


upload_2017-5-30_13-19-34.png
 
Back
Top
[FOX] Ultimate Translator
Translate