A child process is part of job and started by a process which creates the job. The parent process has already not set JOB properties to allow breakaway from job. "JOB_OBJECT_LIMIT_BREAKAWAY_OK" flag is required to set on JOB to allow child processes to breakaway from job but it is not set.
Can child process change this job properties and set flag JOB_OBJECT_LIMIT_BREAKAWAY_OK so that it or it's child processes can run free from JOB. Searched online but haven't found anywhere whether this can be done.
Already referred links
https://learn.microsoft.com/en-us/windows/desktop/procthread/job-objects and https://learn.microsoft.com/en-us/windows/desktop/procthread/process-creation-flags
doesn't say if we can do that. Or if required then how to do that.
I wrote a sample application where parent process creates a job without JOB_OBJECT_LIMIT_BREAKAWAY_OK flag. And wrote sample app which gets started by parent. In this child I tried to set JOB properties like below:
if (bInJob)
{
JOBOBJECT_EXTENDED_LIMIT_INFORMATION info1 = {};
QueryInformationJobObject(NULL, JobObjectBasicLimitInformation, &info1.BasicLimitInformation, sizeof(info1.BasicLimitInformation), NULL);
DWORD dwLimitFlags = info1.BasicLimitInformation.LimitFlags;
SetLastError(0);
info1.BasicLimitInformation.LimitFlags |= JOB_OBJECT_LIMIT_BREAKAWAY_OK;
if (SetInformationJobObject(NULL, JobObjectExtendedLimitInformation, &info1, sizeof(info1)))
{
cout << "failed";
}
DWORD fileError = GetLastError();
JOBOBJECT_BASIC_LIMIT_INFORMATION info = {};
QueryInformationJobObject(NULL, JobObjectBasicLimitInformation, &info, sizeof(info), NULL);
dwLimitFlags = info.LimitFlags;
}
It doesn't work and JOB properties remained unchanged.
for set JOB_OBJECT_LIMIT_BREAKAWAY_OK you need call SetInformationJobObject
for call SetInformationJobObject you need handle to the job whose limits are being set.
but you pass NULL here in place handle. as result you must got ERROR_INVALID_HANDLE at this point.
from IsProcessInJob
An application cannot obtain a handle to the job object in which it is running unless it has the name of the job object. However, an application can call the
QueryInformationJobObjectfunction withNULLto obtain information about the job object.
so system special not return to you handle of job object in which you running. this is by design. if child can remove self from job, this serious kill sense of job, for restrict child processes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With