C++,如何确定 Windows 进程是否正在运行?

2022-01-02 00:00:00 process windows c++

这与 Windows XP 进程有关.

This is concerning Windows XP processes.

我有一个进程正在运行,我们称之为 Process1.Process1 创建一个新进程 Process2,并保存其 id.

I have a process running, let's call it Process1. Process1 creates a new process, Process2, and saves its id.

现在,在某些时候 Process1 希望 Process2 做某事,所以它首先需要确保 Process2 仍然活着并且用户没有杀死它.

Now, at some point Process1 wants Process2 to do something, so it first needs to make sure that Process2 is still alive and that the user has not not killed it.

如何检查此进程是否仍在运行?因为我创建了它,所以我有进程 ID,我认为有一些库函数与 IsProcessIDValid( id ) 类似,但我在 MSDN 上找不到它

How can I check that this process is still running? Since I created it, I have the Process ID, I would think there is some library function along the lines of IsProcessIDValid( id ) but I can't find it on MSDN

推荐答案

您可以使用 GetExitCodeProcess.如果进程仍在运行(或者它碰巧以该退出代码退出:(),它将返回 STILL_ACTIVE (259).

相关文章