本文介绍了检测进程是否仍在运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要检查具有给定HANDLE的进程是否仍在运行,我尝试使用以下代码进行操作,但是即使该进程正在运行,它也总是在第二个return false处返回。

I need to check if a process with a given HANDLE is still running, I tried to do it using the following code however it always returns at the second return false, even if the process is running.

bool isProcessRunning(HANDLE process)
{
    if(process == INVALID_HANDLE_VALUE)return false;

    DWORD exitCode;
    if(GetExitCodeProcess(process, &exitCode) != 0)
        return false;//always returns here

    return GetLastError() == STILL_ACTIVE;//still running
}


推荐答案

您可以测试过程寿命通过使用

You can test the process life by using

bool isProcessRunning(HANDLE process)
{
   return WaitForSingleObject( process, 0 ) == WAIT_TIMEOUT;
}

这篇关于检测进程是否仍在运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-28 10:29
查看更多