1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
// Start the child process.
PROCESS_INFORMATION pi = { 0 };
STARTUPINFO si = { 0 };
si.cb = sizeof(si);
HANDLE ghJob = CreateJobObject( NULL, NULL); // GLOBAL
if( ghJob == NULL)
{
LError << "CreateJobObject failed " << GetLastError();
return -1;
}
else
{
JOBOBJECT_EXTENDED_LIMIT_INFORMATION jeli = {{{{ 0 }}}};
// Configure all child processes associated with the job to terminate when the
jeli.BasicLimitInformation.LimitFlags = JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE;
if( 0 == SetInformationJobObject( ghJob, JobObjectExtendedLimitInformation, &jeli, sizeof(jeli)))
{
CloseHandle(ghJob);
LError << "SetInformationJobObject failed " << GetLastError();
return -1;
}
}
if(!CreateProcessA(
NULL,
(char*)processName.c_str(), // Command line
NULL, // Process handle not inheritable
NULL, // Thread handle not inheritable
TRUE, // Set handle inheritance to TRUE
CREATE_BREAKAWAY_FROM_JOB,
//CREATE_NEW_CONSOLE,
NULL, // Use parent's environment block
NULL, // Use parent's starting directory
&si, // Pointer to STARTUPINFO structure
&pi) // Pointer to PROCESS_INFORMATION structure
)
{
LError << "CreateProcess failed " << GetLastError();
return -1;
}
if(ghJob)
{
if(0 == AssignProcessToJobObject( ghJob, pi.hProcess))
{
LWarning << "AssignProcessToJobObject failed " << GetLastError();
//return -1;
}
} |
Partager