gpt4 book ai didi

c - 在C中获取当前进程CPU使用率

转载 作者:太空宇宙 更新时间:2023-11-04 07:43:20 30 4
gpt4 key购买 nike

在 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 上做同样的事情?

最佳答案

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

关于c - 在C中获取当前进程CPU使用率,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29615/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com