WCTwait chain traveralWord格式文档下载.docx
- 文档编号:16105115
- 上传时间:2022-11-20
- 格式:DOCX
- 页数:34
- 大小:27.01KB
WCTwait chain traveralWord格式文档下载.docx
《WCTwait chain traveralWord格式文档下载.docx》由会员分享,可在线阅读,更多相关《WCTwait chain traveralWord格式文档下载.docx(34页珍藏版)》请在冰豆网上搜索。
Forasynchronoussessions,thecallercanspecifyapointertoacontextdatastructurethroughGetThreadWaitChain.Thesamepointerispassedtothecallbackfunction.Thiscontextdatastructureisuser-definedandopaquetoWCT.ItcanbeusedbytheapplicationtocommunicatecontextbetweenaWCTqueryandacallbackfunction.Acommonapproachistopassaneventhandlethroughthisstructure;
whenthecallbackisexecuted,itsignalsthiseventandinformssomemonitoringthreadthatthequeryhasbeencompleted.
Relatedtopics
UsingWCT
WCTReference
ThefollowingsamplecodedemonstratestheuseofthewaitchaintraversalAPI.Itenumeratesallthreadsinthesystemandprintsthewaitchainforeachthread.
Toenumerateallthreadsinthesystem,runthesamplewithnoparameters.Toenumerateonlythethreadsfromaspecifiedprocess,runthesampleandpasstheprocessidentifierasaparameter.Thesampleperformsthefollowingsteps:
1.CallstheRegisterWaitChainCOMCallbackfunctiontoregistertheCOMcallbackfunctions.
2.CallstheOpenThreadWaitChainSessionfunctiontocreatethewaitchainsession.
3.CallstheAdjustTokenPrivilegesfunctiontoenabletheSE_DEBUG_NAMEprivilege.
4.CallstheEnumProcessesandCreateToolhelp32Snapshotfunctionstoenumeratethespecifiedthreads.
5.CallstheGetThreadWaitChaintoretrieveanarrayofWAITCHAIN_NODE_INFOstructuresthatcontainthenodesofthewaitchain.
6.Printsinformationfromthewaitchain.
7.CallstheCloseThreadWaitChainSessionfunctiontocleanupthewaitchain.
Copy
//Copyright(C)Microsoft.Allrightsreserved.
/*
*SamplecodefortheWaitChainTraversal(WCT)API.
*
*Thisprogramenumeratesallthreadsinthesystemandprintsthe
*waitchainforeachofthem.Itshouldberunfromanelevated
*commandprompttogetresultsforservices.
*/
#ifndefUNICODE
#defineUNICODE
#endif
#include<
windows.h>
wct.h>
psapi.h>
tlhelp32.h>
wchar.h>
stdio.h>
stdlib.h>
#pragmacomment(lib,"
Psapi.lib"
)
Advapi32.lib"
typedefstruct_STR_ARRAY
{
CHARDesc[32];
}STR_ARRAY;
//Human-readablenamesforthedifferentsynchronizationtypes.
STR_ARRAYSTR_OBJECT_TYPE[]=
{"
CriticalSection"
},
SendMessage"
Mutex"
Alpc"
Com"
ThreadWait"
ProcWait"
Thread"
ComActivation"
Unknown"
Max"
}
};
//GlobalvariabletostoretheWCTsessionhandle
HWCTg_WctHandle=NULL;
//GlobalvariabletostoreOLE32.DLLmodulehandle.
HMODULEg_Ole32Hnd=NULL;
//
//Functionprototypes
void
PrintWaitChain(
__inDWORDThreadId
);
BOOL
GrantDebugPrivilege()
/*++
RoutineDescription:
Enablesthedebugprivilege(SE_DEBUG_NAME)forthisprocess.
Thisisnecessaryifwewanttoretrievewaitchainsforprocesses
notownedbythecurrentuser.
Arguments:
None.
ReturnValue:
TRUEifthisprivilegecouldbeenabled;
FALSEotherwise.
--*/
BOOLfSuccess=FALSE;
HANDLETokenHandle=NULL;
TOKEN_PRIVILEGESTokenPrivileges;
if(!
OpenProcessToken(GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES|TOKEN_QUERY,
&
TokenHandle))
{
printf("
Couldnotgettheprocesstoken"
);
gotoCleanup;
}
TokenPrivileges.PrivilegeCount=1;
LookupPrivilegeValue(NULL,
SE_DEBUG_NAME,
TokenPrivileges.Privileges[0].Luid))
p
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- WCTwait chain traveral
![提示](https://static.bdocx.com/images/bang_tan.gif)