Advertisement
Guest User

Untitled

a guest
Jan 21st, 2012
587
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.75 KB | None | 0 0
  1. HANDLE job = CreateJobObject(NULL, NULL);
  2. if (!job) ...
  3. JOBOBJECT_BASIC_LIMIT_INFORMATION jobLimit = { };
  4. jobLimit.LimitFlags = JOB_OBJECT_LIMIT_ACTIVE_PROCESS;
  5. jobLimit.ActiveProcessLimit = 1;
  6. if(! SetInformationJobObject(job, JobObjectBasicLimitInformation, &jobLimit, sizeof(jobLimit)) ) ...
  7. STARTUPINFO si = { sizeof(si) };
  8. PROCESS_INFORMATION pi;
  9. if(! CreateProcess(0, yourcommand, 0, 0, FALSE, CREATE_SUSPENDED | CREATE_BREAKAWAY_FROM_JOB , 0, 0, &si, &pi) ) ...
  10. if(! AssignProcessToJobObject(job, pi.hProcess) ) ...
  11. ResumeThread(pi.hThread);
  12. WaitForSingleObject(pi.hProcess, INFINITE); //Normally you would wait on the job, but since there can only be one process this is ok
  13.  
  14. CloseHandle(pi.hProcess);
  15. CloseHandle(pi.hThread);
  16. CloseHandle(job);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement