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://docs.microsoft.com/en-us/windows/desktop/procthread/job-objects and https://docs.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.