【问题标题】:Get current process CPU usage in C在 C 中获取当前进程的 CPU 使用率
【发布时间】:2010-09-06 23:24:04
【问题描述】:

在 Windows 上我可以做到:

HANDLE hProcess = GetCurrentProcess();

FILETIME ftCreation, ftExit, ftKernel, ftUser;

GetProcessTimes(hProcess, &ftCreation, &ftExit, &ftKernel, &ftUser);

SYSTEMTIME stKernel;
FileTimeToSystemTime(&ftKernel, &stKernel);

SYSTEMTIME stUser;
FileTimeToSystemTime(&ftUser, &stUser);

printf("Time in kernel mode = %uh %um %us %ums", stKernel.wHour,
           stKernel.wMinute, stKernel.wSecond, stKernel.wMilliseconds));
printf("Time in user mode = %uh %um %us %ums", stUser.wHour,
           stUser.wMinute, stUser.wSecond, stUser.wMilliseconds));

我怎样才能在 *nix 上做同样的事情?

【问题讨论】:

    标签: c unix cross-platform process-management


    【解决方案1】:

    检查getrusage,我认为这应该可以解决您的问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-02-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-16
      • 2011-10-04
      • 1970-01-01
      相关资源
      最近更新 更多