《Windows核心程式設計》第五章 作業

2022-03-22 16:45:34 字數 2491 閱讀 3939

#include #include

#include

using

namespace

std;

typedef

struct

threadparam*pthreadparam;

void

monitorcompleteport(lpvoid lpparam)

}printf(

"end thread success.\n");

}void

main()

handle hjob = createjobobject(null, _t("

wintellect_restrictedprocessjob

"));

//add some basic restrictions.

jobobject_basic_limit_information jobli = ;

jobli.priorityclass =idle_priority_class;

jobli.perjobusertimelimit.quadpart = 10000

; jobli.limitflags = job_object_limit_priority_class |job_object_limit_job_time;

setinformationjobobject(hjob, jobobjectbasiclimitinformation, &jobli, sizeof

(jobli));

jobobject_basic_ui_restrictions jobuir;

jobuir.uirestrictionsclass =job_object_uilimit_none;

jobuir.uirestrictionsclass |=job_object_uilimit_exitwindows;

jobuir.uirestrictionsclass |=job_object_uilimit_handles;

setinformationjobobject(hjob, jobobjectbasicuirestrictions, &jobuir, sizeof

(jobuir));

//create a process object

startupinfo si = ; process_information pi;

bool bresult = createprocess("

c:\\windows\\system32\\notepad.exe

", null, null, null, false, create_suspended | create_new_console, null, null, &si, &pi);

assignprocesstojobobject(hjob, pi.hprocess);

//create io completion port.

handle hiocp = createiocompletionport(invalid_handle_value, null, 0, 3

); jobobject_associate_completion_port joacp; joacp.completionkey = (pvoid)1

; joacp.completionport =hiocp;

setinformationjobobject(hjob, jobobjectassociatecompletionportinformation, &joacp, sizeof

(joacp));

//create a thread to monitor the job.

dword dwnumbytestransferred = 0

; ulong lcompletionkey = 0

5000

); resumethread(pi.hthread); closehandle(pi.hthread);

waitforsingleobject(hthread, infinite);

//naution:if use while(true) in the thread, the thread will never return. if use inifinite as param

//of function waitforsingleobject, the main thread will never return.

closehandle(hthread); getchar(); }

第一次執行getqueuedcompletionstatus返回6(job_object_msg_new_process),表示將乙個程序新增進乙個作業;第二次執行getqueuedcompletionstatus返回1(job_object_msg_end_of_job_time),表示作業超時;第二次執行getqueuedcompletionstatus返回1(job_object_msg_active_process_zero),表示作業中程序的數量降至0.

第五章 Windows程式設計 筆記

1.windows 應用程式執行機制 include include lresult callback winexample1proc 對視窗過程函式進行宣告 hwnd hwnd,uint umsg,wparam wparam,lparam lparam int winapi winmain win...

Python核心程式設計 第五章 數字

2011年 03月 06日 星期日 17 12 39 cst 1.數字提供了標量儲存和直接訪問。它是不可更改型別,也就是說變更數字的值會生成新的物件。2.python支援多種數字型別 整型 長整型 布林型 雙精度浮點型 十進位制浮點型和複數。3.python的長整型型別能表達的數值僅僅與你的機器支援...

程式設計珠璣第五章

直接來習題吧 1 第一題可以看一下林銳的高質量c c 程式設計 2 3 4 5 第五題很明顯不應該每次都用 for i 0 i n 1 i assert a i a i 1 如何利用二分的性質來進行處理還是乙個問題。一種辦法是 int bs int a,int b,int e,int v retur...