1

On Windows I can do:

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));

How can I do the same thing on *nix?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
thelsdj
  • 9,034
  • 10
  • 45
  • 58

1 Answers1

3

Check getrusage, I think that should solve your problem.

Magnus Westin
  • 861
  • 7
  • 12