检查时间

时间:2013-01-07 21:40:43

标签: c time

我想查看进程是否仍在运行 - 如果是这样更新当前时间 - 如果没有返回功能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

1 个答案:

答案 0 :(得分:3)

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

应该是

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

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