Advertisement
Guest User

Untitled

a guest
Feb 19th, 2020
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. #define _WIN32_WINNT 0x0400
  2.  
  3. #include <windows.h>
  4. #include <stdio.h>
  5.  
  6. #define _SECOND 10000000
  7.  
  8. #include <iostream>
  9. #include <time.h>
  10.  
  11. using namespace std;
  12.  
  13. static int lol;
  14.  
  15. struct ProcessAdditionalInfo {
  16. int id;
  17. int k;
  18. PROCESS_INFORMATION* pi;
  19. };
  20.  
  21. DWORD WINAPI waitAndClose(LPVOID argc) {
  22. HANDLE wTimer;
  23. wTimer = CreateWaitableTimer(NULL, FALSE, NULL);
  24. __int64 endTime;
  25. srand(lol);
  26. endTime = rand() % 10;
  27. lol = endTime;
  28. LARGE_INTEGER quitTime;
  29. quitTime.LowPart = (DWORD)(-endTime * _SECOND & 0xFFFFFFFF);
  30. quitTime.HighPart = (LONG)(-endTime * _SECOND >> 32);
  31. SetWaitableTimer(wTimer, &quitTime, 0, NULL, NULL, FALSE);
  32. SYSTEMTIME now;
  33. GetSystemTime(&now);
  34. ProcessAdditionalInfo* info = (ProcessAdditionalInfo*)argc;
  35. cout << "Before process " << info->id << ", timeout=" << endTime << " now:" << now.wSecond << endl;
  36. WaitForSingleObject(wTimer, info->k * _SECOND);
  37. GetSystemTime(&now);
  38. cout << "After process " << ((ProcessAdditionalInfo*)argc)->id << " " << now.wSecond << endl;
  39. CloseHandle(wTimer);
  40. TerminateProcess(info->pi->hProcess, 1);
  41. return NULL;
  42. }
  43.  
  44. int main(int acgc, char* argv[])
  45. {
  46. lol = time(NULL);
  47. srand(lol);
  48. int n = atoi(argv[1]);
  49. int k = atoi(argv[2]);
  50. STARTUPINFO cif;
  51. ZeroMemory(&cif, sizeof(STARTUPINFO));
  52. PROCESS_INFORMATION* pi = new PROCESS_INFORMATION;
  53. LPCWSTR name;
  54. for (int i = 0; i < n; i++) {
  55. if (CreateProcess(
  56. TEXT("C:\\windows\\system32\\calc.exe"),
  57. NULL,
  58. NULL,
  59. NULL,
  60. FALSE,
  61. NULL,
  62. NULL,
  63. NULL,
  64. &cif,
  65. pi
  66. )) {
  67. ProcessAdditionalInfo* info = new ProcessAdditionalInfo{i, k, pi};
  68. CreateThread(NULL, 128, waitAndClose, info, 0, NULL);
  69. Sleep(100);
  70. }
  71. }
  72. Sleep(k * 1000);
  73. return 0;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement