windows 如何从C++中的PID中获取进程名称?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7784743/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 18:16:56  来源:igfitidea点击:

how to get the process name from the PID in C++?

c++windowsprocessposixpid

提问by MoShe

Possible Duplicate:
How to get Process Name in C++

可能的重复:
如何在 C++ 中获取进程名称

I am looking for a way to to get the process name from the PID?

我正在寻找一种从 PID 获取进程名称的方法?

I need to translate process id (PID) to process name

我需要将进程 ID (PID) 转换为进程名称

any idea?

任何的想法?

回答by thomas

it depends on the used platform like Yahia mentioned in his comment.

这取决于他在评论中提到的 Yahia 等使用的平台。

on linux: you can get the command-line by reading that file: /proc/[PID]/cmdline

在 linux 上:您可以通过读取该文件来获取命令行: /proc/[PID]/cmdline

on windows: I've found this: get process name from process id (win32)

在 Windows 上:我发现了这一点:从进程 ID (win32) 中获取进程名称

回答by Norbert Willhelm

On Windows you can open the process using OpenProcessin order to get a handle to the process. After that you can get the process name with GetProcessImageFileNameand close the handle (CloseHandle).

在 Windows 上,您可以使用OpenProcess打开进程以获得进程的句柄。之后,您可以使用GetProcessImageFileName获取进程名称并关闭句柄(CloseHandle)。