Supported completion barrier for interrupted CreateProcessW with PROC_THREAD_ATTRIBUTE_JOB_LIST

CiS 0 Reputation points
2026-11-24T09:56:04.5566667+00:00

Hello,

I am seeking authoritative clarification about Windows process-creation and Job Object semantics, specifically when a process creator exits or becomes unavailable while CreateProcessW is in progress.

Background

We are designing a native Windows process supervisor that uses private Job Objects to contain newly created processes and their descendants.

The intended process-creation sequence uses:

STARTUPINFOEXW

EXTENDED_STARTUPINFO_PRESENT

PROC_THREAD_ATTRIBUTE_JOB_LIST

InitializeProcThreadAttributeList

UpdateProcThreadAttribute

CreateProcessW

The private Job Object is configured before process creation. The design does not use an unrestricted launch or a suspend-then-assign fallback.

Microsoft documentation describes nested Job Objects and creation-time job assignment. However, we have not found a definitive documented contract for interrupted process creation or pending job admission.

This is a hypothetical failure scenario. We have not observed or reproduced a Windows defect.

Scenario

Consider the following sequence:

T0: A private Windows Job Object exists. An independent guardian retains a valid handle to it.

T1: Another process begins a CreateProcessW call using PROC_THREAD_ATTRIBUTE_JOB_LIST to assign the new process to that job.

T2: Before CreateProcessW returns, the creator crashes, terminates unexpectedly, or becomes permanently unresponsive.

T3: The surviving guardian attempts to determine whether process creation completed, was cancelled, or remains in progress.

T4: The guardian queries the private job and observes zero active processes.

Primary question

What supported Windows API mechanism allows the guardian to establish that all in-flight process admissions have completed or been cancelled before treating the private Job Object as definitively empty?

In particular, does Windows provide an authoritative admission-completion barrier, synchronization mechanism, or documented recovery protocol?

Specific technical questions

1. Interrupted process creation

If the creator terminates while CreateProcessW is in progress, what guarantees exist regarding completion, cancellation, rollback, and process visibility?

Does the answer differ when the creator remains alive but the calling thread is blocked?

2. Partial job assignment

If PROC_THREAD_ATTRIBUTE_JOB_LIST specifies multiple jobs and one assignment fails, can a partially created process survive or execute with only some assignments completed?

3. Late admission

Can a process associated with an already-started CreateProcessW operation become active in a private job after another process has observed the job's active-process count as zero?

4. Admission closure

Is there a supported operation that prevents further admissions and confirms that all pending process-creation operations referencing the job have completed?

5. Termination semantics

Does TerminateJobObject establish an admission barrier, or does it terminate only processes already associated with the job?

6. Kill-on-close

If the final external job handle closes while process creation is in progress, how is JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE ordered against pending assignment and internal references?

7. Guardian verification

Can an independent guardian holding a Job Object handle reliably determine that all creation operations involving that job have completed?

Are job accounting queries or completion-port notifications sufficient for this purpose?

8. Nested Job Objects

Do any of these guarantees change when the creator already belongs to an existing Job Object hierarchy and the new process receives an additional nested-job assignment without requesting breakaway?

Relevant Microsoft documentation

Nested Jobs

Job Objects

UpdateProcThreadAttribute

CreateProcessW

AssignProcessToJobObject

TerminateJobObject

JOBOBJECT_ASSOCIATE_COMPLETION_PORT

Raymond Chen: A more direct and mistake-free way of creating a process in a job object

We understand that normal creation-time job assignment occurs before the new process's initial thread runs.

Our question concerns what is guaranteed if creation is interrupted before the creating API call returns.

Requested clarification

Could Microsoft provide:

The authoritative Windows API contract covering this scenario.

Any supported cancellation, synchronization, or admission-completion mechanism.

The applicable Windows-version and Job Object hierarchy requirements.

A recommended containment architecture if no definitive admission-completion barrier exists.

The answer is important because we must distinguish confirmed process-group completion from an indeterminate creation or survivor state.

We do not consider an elapsed deadline, a successful termination request, or a single empty-job accounting snapshot sufficient evidence by itself.

Thank you for your guidance.

Windows development | Windows API - Win32
0 comments No comments

2 answers

Sort by: Newest
  1. Tony Thach (WICLOUD CORPORATION) 1,445 Reputation points Microsoft External Staff Moderator
    2026-11-24T10:54:37.8633333+00:00

    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_LIST assigns 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 over ActiveProcessLimit, the process is terminated and the association fails (JOBOBJECT_BASIC_LIMIT_INFORMATION).

    5. Termination semantics

    • TerminateJobObject ends 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: ActiveProcesses and JobObjectBasicProcessIdList are 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_LIST requires 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

    1. Sweep and gate. Terminate the current members and set ActiveProcessLimit = 0. Retry until the limit is accepted.
    2. Sweep again. Terminate anything admitted before the gate took effect.
    3. Verify. Report Empty only when ActiveProcesses reads 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_PROCESS in 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.

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments

  2. AI answer

    2026-11-24T09:58:22.49+00:00

    There is no publicly documented Windows API admission-completion barrier that lets an independent guardian prove that every in-progress CreateProcessW operation referencing a Job Object has completed or been cancelled.

    PROC_THREAD_ATTRIBUTE_JOB_LIST closes the execution-before-assignment race, but the published contract does not make the Job Object an admission queue, expose pending admissions, or define a drain/close operation for them. It assigns the child to the listed jobs in order and is supported on Windows 10/Windows Server 2016 and later.^1^ Assignment occurs before the initial thread runs.^2^

    Documented guarantees—and the gaps

    1. Interrupted CreateProcessW The documented API result is available only when the call returns: nonzero with PROCESS_INFORMATION, or zero with GetLastError. It also states that a successful return precedes completion of process initialization.^3^ The public contract does not specify what a different process may infer if the caller or calling thread disappears, remains blocked, or never reports that result. In particular, it does not document:
      • cancellation caused by caller termination;
      • rollback of all process-creation state;
      • a recoverable transaction identifier;
      • a waitable object representing the outstanding creation;
      • a maximum time by which admission must become visible.
      Consequently, an empty-job snapshot cannot establish that an operation which had already started cannot later affect observable state. This does not establish that late admission occurs; it means the published contract does not provide the requested proof that it cannot occur.
    2. Multiple jobs and partial assignment The documented behavior is sequential assignment in the supplied order, and the order must form a valid job hierarchy.^1^ Nested-job rules explain which hierarchy orders are valid and that invalid explicit assignments fail.^4^ The cited public contract does not define atomic all-or-nothing rollback for PROC_THREAD_ATTRIBUTE_JOB_LIST, nor does it document that a process can permanently survive with only a prefix of the requested jobs after creation fails. Either conclusion would exceed the published guarantee. The pre-initial-thread guarantee does establish that the child cannot execute user code between these creation-time assignments.
    3. Accounting and process-ID queries ActiveProcesses is current job accounting, not a count of pending CreateProcessW operations.^5^ Likewise, JobObjectBasicProcessIdList reports processes associated with the job and, for nested jobs, its child jobs; it does not report pending admissions.^6^
    4. Completion-port notifications JOB_OBJECT_MSG_ACTIVE_PROCESS_ZERO means the active count was decremented to zero. It is not documented as an admission fence. Ordinary job messages—including new-process, exit-process, and active-process-zero notifications—are notifications whose delivery is generally not guaranteed, and Microsoft explicitly warns about races involving new/exit messages.^7^ Therefore, neither receipt of ACTIVE_PROCESS_ZERO nor the absence of a subsequent NEW_PROCESS notification proves admission closure.
    5. TerminateJobObject This terminates processes currently associated with the job and, for a nested job, processes currently associated with its child jobs.^8^ It is not documented as:
      • preventing future assignment;
      • waiting for pending creation operations;
      • cancelling operations holding job handles;
      • permanently placing the job into an admission-closed state.
      The related explicit-assignment contract says assignment fails if that job or a parent job is terminating, but it does not turn TerminateJobObject into a general drain barrier for already-started creation-time assignments.^9^
    6. Kill-on-close JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE terminates processes associated with the job when its last handle closes.^10^ The public documentation does not define ordering between final external-handle closure and undocumented internal references held during process creation. It therefore cannot be used as proof that a pending admission has drained.
    7. Nested jobs Nested jobs are supported starting with Windows 8 and Windows Server 2012; PROC_THREAD_ATTRIBUTE_JOB_LIST itself requires Windows 10 or Windows Server 2016 or later. Nested jobs aggregate accounting and propagate applicable notifications and termination through the hierarchy, but they do not add an admission barrier.^4^

    Treat job containment and creation completion as separate properties:

    1. Route every launch through a single long-lived broker.
    2. Persist or publish a request record before dispatching CreateProcessW.
    3. During shutdown, atomically stop accepting submissions and serialize that transition against request creation.
    4. Keep each request outstanding until CreateProcessW returns and the broker transfers the resulting process/thread handles and final status to the guardian.
    5. If the broker dies with an outstanding request, retain the state as indeterminate; do not convert it to failure merely because the broker terminated.
    6. Use PROC_THREAD_ATTRIBUTE_JOB_LIST for containment, and use the application protocol—not job accounting—as the admission counter.
    7. Permit no other component to receive or use assign-capable job handles outside that protocol. Otherwise, protocol closure cannot be authoritative.
    8. Optionally place the broker or an anchor process in a containing kill-on-close job. This reduces the risk of an uncontained survivor, but it still does not prove completion or cancellation of an interrupted admission.

    A minimal transaction state model is:

    record(request, Pending);       // durable/shared state
    if (!accepting_launches)
        transition(request, Rejected);
    else {
        BOOL ok = CreateProcessW(/* JOB_LIST attributes */);
        if (ok)
            transfer_handles_and_mark(request, Succeeded);
        else
            mark(request, Failed, GetLastError());
    }
    // Broker death while Pending => Indeterminate, not Failed.
    

    Authoritative clarification from Microsoft

    Because rollback, pending-admission visibility, multi-job failure atomicity, and kill-on-close ordering are not specified by the public API contract, definitive reliance on those behaviors requires an official Microsoft Support case for Windows application development. Request escalation to the Windows process/job-object engineering or documentation team and ask for one of:

    • a documented supported contract;
    • an explicit statement that no supported guarantee exists; or
    • a documentation clarification covering interrupted CreateProcessW, multi-job rollback, TerminateJobObject, and final-handle-close ordering.

    Until such a contract is supplied, distinguish contained/observably empty from creation protocol conclusively completed.


    References

    1. UpdateProcThreadAttribute function (processthreadsapi.h)
    2. February 9, 2023 - The Old New Thing
    3. CreateProcessW function (processthreadsapi.h)
    4. Nested Jobs
    5. JOBOBJECT_BASIC_ACCOUNTING_INFORMATION structure (winnt.h)
    6. JOBOBJECT_BASIC_PROCESS_ID_LIST structure (winnt.h)
    7. JOBOBJECT_ASSOCIATE_COMPLETION_PORT structure (winnt.h)
    8. TerminateJobObject function (jobapi2.h)
    9. AssignProcessToJobObject function (jobapi2.h)
    10. JOBOBJECT_BASIC_LIMIT_INFORMATION structure (winnt.h)
    AI-generated content may be incorrect. Read our transparency notes for more information.

    Was this answer helpful?

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.