在 c++/windows 中获取线程状态
系统中必须有一个函数来获取当前线程的状态,因为
有这个应用程序: http://www.softwareverify.com/cpp/ thread-status-monitor/index.html
它必须使用某种 API 函数或其他东西...... 如何在 C++/Windows 中自己获取线程状态?
谢谢:)
(这是我今天的最后一个问题。我保证:))
There must be a function that gets the current status of a thread in the system because
there is this application: http://www.softwareverify.com/cpp/thread-status-monitor/index.html
It must be using some sort of API function or something...
How can I get a thread state myself in C++/Windows?
thanks :)
(this is my last question for today. I promise :))
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是通过 Toolhelp 库完成的,请在 MSDN 上查看信息: http://msdn.microsoft.com/en-us/library/ms686780%28v=VS.85%29.aspx
That's done via Toolhelp library, check information at MSDN : http://msdn.microsoft.com/en-us/library/ms686780%28v=VS.85%29.aspx
您可以使用以下示例来获取正在运行的进程,如果您有进程 ID,还可以获取线程。
拍摄快照并查看进程
< a href="http://msdn.microsoft.com/en-us/library/ms686852(v=vs.85).aspx" rel="nofollow noreferrer">遍历线程列表
编辑:获取您感兴趣的线程的句柄后,您可以调用
GetExitCodeThread
,但这只会告诉您线程是否处于STILL_ACTIVE
,直到它当您可以找到退出代码时结束。在搜索您的评论的附加信息时,我还遇到了 此线程 on SO,您可能会感兴趣。
You can use the following examples to get the running processes and, when you have a process ID, the threads.
Taking a Snapshot and Viewing Processes
Traversing the Thread List
EDIT: After getting the handle to the thread(s) you are interested in you can call
GetExitCodeThread
but that will only tell you if the thread isSTILL_ACTIVE
until it ends, when you can find the exit code.While searching for the additional information for your comment I also came across this thread on SO which might be of interest to you.
您可以从 WMI Win32_Thread 类。链接的文章包含您需要的 C++ 代码的链接。使用 WMI Code Creator 工具进行实验。
You get the most bang out of WMI, Win32_Thread class. The linked article has a link to the C++ code you need. Experiment with the WMI Code Creator tool.