Hi @CiS ,
Thank you for the detailed scenario, and for separating what you have already verified from what you are asking.
In short: No. Windows doesn't document an admission-completion barrier, a list of pending admissions, or a recovery protocol for an interrupted CreateProcessW. Only the caller ever learns whether its call completed.
Your goal is narrower than per-call completion, though. You need to know that no in-flight creation can still leave a live process in the private job. The job's active-process limit is a documented way to close the job to new members, so a zero count read after closing it means the job is empty. One point needs to be confirmed on your builds; it is marked below.
1. Interrupted process creation
- Confirmed by docs: the outcome is reported only when the call returns, and the call returns before the new process has finished initializing (CreateProcessW).
- Not documented: cancellation, rollback, or visibility if the caller terminates. A blocked caller is no different: the call may still complete later, and no API lets another process observe it. Treat that request as indeterminate.
2. Partial job assignment
- Confirmed by docs:
PROC_THREAD_ATTRIBUTE_JOB_LISTassigns the jobs in the order specified (UpdateProcThreadAttribute), and that order must form a valid hierarchy (Nested Jobs). Once a process is associated with a job, the association cannot be broken (Job Objects). - Not documented: all-or-nothing behavior, or what happens to the process when a later entry fails.
- You can avoid the multi-entry case entirely: list only the private job, and get any outer job from the creator through inheritance.
3. Late admission
- The docs don't rule it out.
- The close sequence below makes it harmless for your private job, because an association attempted after the gate fails.
4. Admission closure
- No single call both blocks new admissions and confirms that pending calls have finished.
- The closest documented control is
JOB_OBJECT_LIMIT_ACTIVE_PROCESS. If an association would push the active count overActiveProcessLimit, the process is terminated and the association fails (JOBOBJECT_BASIC_LIMIT_INFORMATION).
5. Termination semantics
-
TerminateJobObjectends the processes currently associated with the job and its child jobs (TerminateJobObject). It is not described as an admission barrier. - The rule that assignment fails while a job is terminating is stated only for
AssignProcessToJobObject(AssignProcessToJobObject).
6. Kill-on-close
- Confirmed by docs: closing the last handle terminates the processes associated with the job (same page as Q4).
- Not documented: how this is ordered against an assignment in progress or against internal references.
- Keep the guardian's handle open until the close sequence returns Empty. Treat kill-on-close only as the backstop for a guardian crash.
7. Guardian verification
- Accounting queries alone are not enough:
ActiveProcessesandJobObjectBasicProcessIdListare snapshots. - Completion-port messages are not enough either. Except for notification-limit messages, they are not guaranteed to arrive, and a missing message doesn't mean the event didn't happen (JOBOBJECT_ASSOCIATE_COMPLETION_PORT). Use them only as wake-ups.
- For a process you hold a handle to, IsProcessInJob confirms membership.
- For pending or unknown processes, use the close sequence below.
8. Nested jobs
- Confirmed by docs: by default a child is associated with every job in its creator's job chain unless breakaway is allowed (Nested Jobs).
- The active process limit is not one of the limits combined across the chain. A process takes it from its immediate job (AssignProcessToJobObject).
- Not documented: any change to the interrupted-creation behavior.
- Set the limit on the private job and on any child job that a creator can name.
- Versions:
JOB_LISTrequires Windows 10 / Windows Server 2016 or later, nested jobs require Windows 8 / Windows Server 2012 or later, and the active-process limit is available from Windows XP / Windows Server 2003.
Closing a private job and confirming it is empty
- Sweep and gate. Terminate the current members and set
ActiveProcessLimit = 0. Retry until the limit is accepted. - Sweep again. Terminate anything admitted before the gate took effect.
- Verify. Report Empty only when
ActiveProcessesreads zero after the gate is in place. Every later association attempt fails, so that read is final for live membership. A refused attempt can still raise the count for a moment, because it stays counted until that process ends and its handles are closed. It does not become a member. A timeout returns "still terminating", never Empty.
Per-request outcomes are a separate question. The request ledger in the AI-generated answer on this thread is a good model: Pending, then Succeeded or Failed, and Indeterminate if the caller dies. After the gate, an Indeterminate request can no longer leave a live process in this job.
#include <windows.h>
enum class JobState { Empty, StillTerminating, Error };
// hJob needs JOB_OBJECT_QUERY | JOB_OBJECT_SET_ATTRIBUTES | JOB_OBJECT_TERMINATE.
// Returns Empty only when the active count reads zero with the admission gate in place.
JobState CloseAndVerifyEmpty(HANDLE hJob, DWORD timeoutMs)
{
const ULONGLONG deadline = GetTickCount64() + timeoutMs;
// Keep the job's existing limits and add ActiveProcessLimit = 0.
JOBOBJECT_EXTENDED_LIMIT_INFORMATION li{};
if (!QueryInformationJobObject(hJob, JobObjectExtendedLimitInformation, &li, sizeof(li), nullptr))
return JobState::Error;
DWORD& flags = li.BasicLimitInformation.LimitFlags;
if (flags & JOB_OBJECT_LIMIT_JOB_TIME) { // keep an existing job-time limit as it is
flags &= ~static_cast<DWORD>(JOB_OBJECT_LIMIT_JOB_TIME);
flags |= JOB_OBJECT_LIMIT_PRESERVE_JOB_TIME;
}
flags |= JOB_OBJECT_LIMIT_ACTIVE_PROCESS;
li.BasicLimitInformation.ActiveProcessLimit = 0;
// 1. Sweep and gate. Retried because the docs don't say whether the limit
// can be set while members are still running down.
for (;;) {
TerminateJobObject(hJob, ERROR_CANCELLED);
if (SetInformationJobObject(hJob, JobObjectExtendedLimitInformation, &li, sizeof(li)))
break;
if (GetTickCount64() >= deadline)
return JobState::Error; // no gate: not proven empty
Sleep(20);
}
// 2. Sweep anything admitted before the gate took effect.
TerminateJobObject(hJob, ERROR_CANCELLED);
// 3. Verify. A deadline never turns into Empty.
for (;;) {
JOBOBJECT_BASIC_ACCOUNTING_INFORMATION ai{};
if (!QueryInformationJobObject(hJob, JobObjectBasicAccountingInformation, &ai, sizeof(ai), nullptr))
return JobState::Error;
if (ai.ActiveProcesses == 0)
return JobState::Empty;
if (GetTickCount64() >= deadline)
return JobState::StillTerminating;
Sleep(20);
}
}
To confirm on your target builds: the docs don't state a minimum value for ActiveProcessLimit. They also don't say whether creation-time association (through JOB_LIST or inheritance) is checked against that limit in the same way. Please test both before relying on step 1. If the limit isn't accepted, the function returns Error, not Empty.
Two containment notes:
- Don't use
PROC_THREAD_ATTRIBUTE_PARENT_PROCESSin the creator. The new process inherits the job object of the process you specify (UpdateProcThreadAttribute). - A process started through an out-of-job broker, such as
Win32_Process.Create, is not associated with the job (Job Objects).
For a Microsoft statement on Q1, Q2, Q3 and Q6, I recommend opening a case with Microsoft Support for Business. They can advise whether the question can be routed to Windows engineering for clarification. Please note that this is a paid support option. You can also use the feedback control on the UpdateProcThreadAttribute page to ask for the interrupted-creation case to be documented.
I hope this helps. If it answers your question, please follow this guide to share your feedback so others with the same question can find it.