Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- HANDLE job = CreateJobObject(NULL, NULL);
- if (!job) ...
- JOBOBJECT_BASIC_LIMIT_INFORMATION jobLimit = { };
- jobLimit.LimitFlags = JOB_OBJECT_LIMIT_ACTIVE_PROCESS;
- jobLimit.ActiveProcessLimit = 1;
- if(! SetInformationJobObject(job, JobObjectBasicLimitInformation, &jobLimit, sizeof(jobLimit)) ) ...
- STARTUPINFO si = { sizeof(si) };
- PROCESS_INFORMATION pi;
- if(! CreateProcess(0, yourcommand, 0, 0, FALSE, CREATE_SUSPENDED | CREATE_BREAKAWAY_FROM_JOB , 0, 0, &si, &pi) ) ...
- if(! AssignProcessToJobObject(job, pi.hProcess) ) ...
- ResumeThread(pi.hThread);
- WaitForSingleObject(pi.hProcess, INFINITE); //Normally you would wait on the job, but since there can only be one process this is ok
- CloseHandle(pi.hProcess);
- CloseHandle(pi.hThread);
- CloseHandle(job);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement