0

我想检查一个进程是否仍在运行 - 如果是,请更新当前时间 - 如果没有返回函数 bc 进程已经死亡......如果进程没有死亡并且停止限制已经过去,那么你退出循环但似乎 currTime 没有更新......

int g_iStopLimit = 30; //declared globally


/////process gets signaled to be killed but may take a while to close cleanly...

time_t startTime, currTime;
time(&startTime);
currTime = time(NULL);

do //check to see if process gets killed
{
    if (kill(g_StatusInstance[i].pid, 0) == 0)  //some global array
    {
        currTime = time(NULL);
    }
    else
    {
        return;
    }

}while(currTime >= (startTime + g_iStopLimit));


////send a stronger signal and call kill - use recursion and call function over until it kills it
4

1 回答 1

3
while(currTime >= (startTime + g_iStopLimit));

应该

while(currTime <= (startTime + g_iStopLimit));

最初,startTime并且currTime几乎相同,因此除非kill花费不寻常的时间,否则循环在第一次迭代后结束。

于 2013-01-07T21:44:02.497 回答