在 c++/windows 中获取线程状态

发布于 2024-10-10 09:17:16 字数 312 浏览 0 评论 0原文


系统中必须有一个函数来获取当前线程的状态,因为
有这个应用程序: 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

残花月 2024-10-17 09:17:16

这是通过 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

一袭水袖舞倾城 2024-10-17 09:17:16

您可以使用以下示例来获取正在运行的进程,如果您有进程 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 is STILL_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.

讽刺将军 2024-10-17 09:17:16

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文