如何知道.exe是否在c ++中运行? [英] How do I find out if a .exe is running in c++?

查看:102
本文介绍了如何知道.exe是否在c ++中运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何知道一个可执行文件是否正在Windows上运行,给定进程名称,例如。 program.exe?

How can you find out if an executable is running on Windows given the process name, e.g. program.exe?

推荐答案

C ++标准库没有这样的支持。您需要一个操作系统API来执行此操作。如果这是Windows,那么你将使用CreateToolhelp32Snapshot(),其次是Process32First和Process32Next来迭代正在运行的进程。注意不可避免的竞争条件,这个过程可能会在你找到它的时候退出。

The C++ standard library has no such support. You need an operating system API to do this. If this is Windows then you'd use CreateToolhelp32Snapshot(), followed by Process32First and Process32Next to iterate the running processes. Beware of the inevitable race condition, the process could have exited by the time you found it.

这篇关于如何知道.exe是否在c ++中运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆