Fixed JOBS /K doesn't work

May 20, 2008
11,400
99
Syracuse, NY, USA
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.
 

rconn

Administrator
Staff member
May 14, 2008
12,345
150
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.
 
May 20, 2008
11,400
99
Syracuse, NY, USA
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
 
Similar threads
Thread starter Title Forum Replies Date
Joe Caverly Create Windows Jobs and optionally attach processes to a job Support 17
vefatica JOBS /K ... how does it work? Support 5
vefatica Setting array variable ignores leading spaces (and @execarray doesn't) Support 4
MickeyF Why doesn't my python program get executed without specifying its path? Support 2
gworley Virtual network drive filename completion doesn’t get directories Support 0
vefatica Win10's ANSI doesn't like 2>NUL Support 10
vefatica Win10, alternative screen buffer, cursor doesn't blink Support 11
M Trying to use ffind with a @file.lst doesn't work Support 4
Charles Dye Ctrl-Shift-Up doesn't update directory history Support 1
gschizas Take Command (Environment) doesn't show v2 ANSI colors Support 30
E Fixed SHRALIAS doesn't work / SHRALIAS.EXE is missing in v20.11.35 Support 2
D WAD Reboot doesn't shutdown or restart Support 13
M Documentation Q.Search doesn't support selection? Support 1
R Fixed 7ZIP Compression Method Option Doesn't Work Support 1
T Regex engine doesn't recognize native DOS line endings Support 2
E Fixed DEDUPE doesn't handle filenames with whitespace properly when symlinking Support 1
D Docking doesn't persist Support 5
E WAD DESCRIBE under TCC 19 doesn't work with diacritics Support 14
C VIEW PRINT /Wrap doesn't work Support 0
D CD doesn't always find everything Support 8
M View doesn't recognize Ctrl+End and Ctrl+Pos1 Support 2
M Ctrl-End doesn't work. DelToEnd is not executed Support 13
B Fixed FFIND doesn't find last character in file without CR/LF at EOF Support 1
G .BTM association doesn't work anymore Support 1
jadaml Documentation Is COPY realy doesn't work for any HTTP and FTP? Support 3
D do /s doesn't recurse Support 1
D WAD Alt-Left doesn't work, but Alt-Shift-Left does Support 1
I How to? Bat Works but BTM Doesn't Support 6
B %@lines doesn't count last line without cr/lf at eof Support 1
williamleara WAD ribbon doesn't remember expand/collapse setting Support 3
vefatica Why doesn't "IDE %_ININAME" work? Support 4
M How to? /Elevated doesn't do it for me... Support 8
D Why doesn't ffind find directory? Support 3
Phileosophos TPIPE doesn't work at all with v16 Support 3
D ejectmedia doesn't work in v16 Support 2
Phileosophos Fixed Register for all users doesn't register for all users Support 10
T "Checking for a newer version" doesn't complete Support 18
vefatica Doesn't IDE auto-indent? Support 3
C FFind /w works but FFind /= doesn't? Support 2
noahcoad WAD cmd.exe under tcc doesn't find apps Support 4
vefatica Fixed TPIPE doesn't /SPLIT at characters Support 0
M Site doesn't recognise cookies Support 0
D What's New doesn't mention copydir movedir Support 25
D TIMER OFF doesn't work Support 21
M @Files sure doesn't work the way I would have assumed it did! Support 4
M Why doesn't this @Field function work? Support 0
M Why doesn't this work? Support 12
vefatica ON BREAK doesn't always work Support 23
K_Meinhard Fixed ? TCMD 14.02 doesn't start here Support 4
Stefano Piccardi 14.01.33 unset doesn't complain about undefined variables Support 8

Similar threads