The public Win32 API contract does not guarantee fail-closed containment when the creator terminates during CreateProcessW; PROC_THREAD_ATTRIBUTE_JOB_LIST is the supported creation-time association mechanism, but its documentation does not specify atomic commit, rollback, or orphan cleanup for an interrupted call.
Documented guarantees
-
PROC_THREAD_ATTRIBUTE_JOB_LISTrequests that the child be assigned to the listed jobs, in the specified order, during process creation. It is supported on Windows 10/Windows Server 2016 and later. The job-handle array and its storage must remain valid until the attribute list is deleted.^1^ -
CREATE_SUSPENDEDguarantees only that the new process’s primary thread is created suspended and does not run untilResumeThreadis called.^2^ - A successful
CreateProcessWreturns process and thread handles. A failed call returns zero and provides an error throughGetLastError. The function can return before process initialization finishes, and later initialization failure can terminate the process.^3^ - Once a process has been associated with a job, that association cannot be removed.^4^
- If association would exceed
JOB_OBJECT_LIMIT_ACTIVE_PROCESS, the process is terminated and the association fails.^5^ The same termination behavior is documented forAssignProcessToJobObject.^6^
What is not documented
The cited contracts do not state:
- That creation and all
PROC_THREAD_ATTRIBUTE_JOB_LISTassignments form an atomic transaction. - That
CreateProcessW(FALSE)means no process object was temporarily or permanently left alive. - That Windows rolls back or terminates a partially created process if the calling process or calling thread disappears during the system call.
- The exact ordering between process-object creation, each job-list association, initialization of the user-mode address space, publication of the PID, and return to the caller.
- That job assignment is complete before all possible user-mode initialization activity.
CREATE_SUSPENDEDdocuments only the state of the primary thread, so it should not be treated as a broader initialization-order guarantee. - That failure while assigning one job from a multi-job list rolls back assignments already completed.
Consequently, a design requiring proof that no uncontained process can survive any creator failure point cannot derive that property from these documented APIs. This does not establish that an uncontained child actually survives on a particular Windows build; it means that relying on the opposite would be an implementation assumption rather than a documented contract.
Creator termination and job-handle lifetime
When a process terminates, Windows automatically closes its handles.^7^ Closing a handle decrements the object’s handle count; object lifetime depends on the remaining handles and object-specific retention rules.^8^
For a job configured with JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE, closing the last job handle terminates all processes already associated with that job. For a nested job, it also terminates processes in its child jobs.^4^
Therefore:
- Creator death closes the creator’s job handle.
- If another process holds a job handle, this is not the last close, so kill-on-close does not trigger.
- If it is the last handle, associated processes are terminated.
- No guarantee extends to a process that had not been successfully associated.
An unnamed job cannot subsequently be reopened by name. A separate supervisory process may retain a duplicated/inherited job handle to control its lifetime, but that improves availability and cleanup only; it does not close the undocumented partial-creation window.
Existing and nested jobs
On current supported systems, a process can belong to a hierarchy of nested jobs. A new association succeeds only when Windows can form a valid hierarchy; UI limits can make nesting invalid. Creation-time implicit association also carries the child into every job in its parent’s job chain unless applicable breakaway behavior permits otherwise.^9^
Parent jobs can impose more restrictive effective limits. For some limits, the most restrictive value in the chain applies; other limits come from the immediate job.^6^ Thus, an existing parent job, invalid hierarchy, UI restrictions, a terminating job, session incompatibility, or exhausted limits can prevent an intended association. No-breakaway settings prevent later voluntary escape, but do not add documented transactional rollback to creation.
Supported design conclusion
Continue using PROC_THREAD_ATTRIBUTE_JOB_LIST rather than post-creation AssignProcessToJobObject, because it is the documented way to request association as part of creation. Keep CREATE_SUSPENDED, omit both breakaway limits and flags, retain KILL_ON_JOB_CLOSE, and treat success as valid only after CreateProcessW returns successfully.
However, there is no publicly documented Win32 mechanism in these contracts that guarantees fail-closed containment if the creator itself can be terminated at an arbitrary point inside CreateProcessW. If that guarantee is a security requirement, the process performing creation must itself be kept alive by a trusted supervisory boundary until the call completes; this is an architectural mitigation, not an API-level proof of atomic containment.
References
- UpdateProcThreadAttribute function (processthreadsapi.h)
- Process Creation Flags
- CreateProcessW function (processthreadsapi.h)
- Job Objects
- JOBOBJECT_BASIC_LIMIT_INFORMATION structure (winnt.h)
- AssignProcessToJobObject function (jobapi2.h)
- Object Interface
- CloseHandle function (handleapi.h)
- Nested Jobs