Advertisement
NoamCohen123

Get_Process Running Time

Jul 17th, 2019
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.88 KB | None | 0 0
  1. // ConsoleApplication2.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5.  
  6.  
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <Windows.h>
  10.  
  11.  
  12. int _tmain(int argc, LPTSTR argv[])
  13. {
  14.     STARTUPINFO si;
  15.     PROCESS_INFORMATION pi;
  16.     FILETIME TIME_CREATION;
  17.     FILETIME EXIT_TIME;
  18.     FILETIME KERNEL_TIME;
  19.     FILETIME USER_TIME;
  20.     FILETIME TOTAL_TIME;
  21.  
  22.     ZeroMemory(&si, sizeof(si));
  23.     ZeroMemory(&pi, sizeof(pi));
  24.  
  25.    
  26.     CreateProcess(argv[1], argv[2], NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
  27.     int a = GetLastError();
  28.     //printf("%d", a);
  29.     if (!a)
  30.     {
  31.         WaitForSingleObject(pi.hProcess, INFINITE);
  32.  
  33.  
  34.         if (GetProcessTimes(pi.hProcess, &TIME_CREATION, &EXIT_TIME, &KERNEL_TIME, &USER_TIME))
  35.         {
  36.             int total_run_time = (*((ULONGLONG*)&EXIT_TIME) - *((ULONGLONG*)&TIME_CREATION)) / 10000;
  37.             printf("Run time %dms", total_run_time);
  38.         }
  39.  
  40.     }
  41.  
  42.     return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement