Advertisement
Guest User

Untitled

a guest
Feb 17th, 2020
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.50 KB | None | 0 0
  1. #include <cstdio>
  2. #include <Windows.h>
  3. #include <iostream>
  4. #include <iomanip>
  5. #include <vector>
  6.  
  7. using namespace std;
  8.  
  9.  
  10. void generateProcess() {
  11.  
  12. }
  13.  
  14. DWORD WINAPI TheadFunc(LPVOID) {
  15.     generateProcess();
  16.     int  i= 0;
  17.     DWORD word = i;
  18.     ++i;
  19.     return word;
  20.  
  21. }
  22.  
  23.  
  24. int main(int argc, char* argv[])
  25. {
  26.  
  27.     int k = atoi(argv[1]);
  28.     int N = atoi(argv[2]);
  29.  
  30.     const int nTimerUnitsPerSecond = 10000000;
  31.     LARGE_INTEGER li;
  32.     li.QuadPart = -(k * nTimerUnitsPerSecond);
  33.    
  34.     int theArg = 5;
  35.  
  36.     DWORD targetThreadId ;
  37.  
  38.  
  39.     HANDLE hTimer = CreateWaitableTimer(NULL, FALSE, NULL);
  40.     if (SetWaitableTimer(hTimer, &li, 1000, NULL, NULL, FALSE))
  41.     {
  42.  
  43.         cout << "Waiting : " << k << " se   conds " << endl;
  44.         vector<PROCESS_INFORMATION> threads;
  45.         for (int i = 0; i < N; ++i) {
  46.  
  47.             TCHAR lpCommandLine[] = L"X:\\3530904_80021\\Rusanov\\OS\\lab2\\lab2\\Debug\\ConsoleApplication1.exe";
  48.             STARTUPINFO startupInfo;
  49.             PROCESS_INFORMATION processInfo;
  50.             ZeroMemory(&startupInfo, sizeof(STARTUPINFO));
  51.             startupInfo.cb = sizeof(startupInfo);
  52.             int r = CreateProcess(NULL, lpCommandLine, NULL, NULL, FALSE, HIGH_PRIORITY_CLASS | CREATE_NEW_CONSOLE,
  53.                 NULL, NULL, &startupInfo, &processInfo);
  54.             if (!r)
  55.             {
  56.                 fprintf(stderr, "CreateProcess failed on error % d\n", GetLastError());
  57.                 ExitProcess(1);
  58.  
  59.             }
  60.            
  61.             threads.push_back( processInfo);
  62.  
  63.         }
  64.         WaitForSingleObject(hTimer, INFINITE);
  65.         for (int i = 0; i < N; ++i) {
  66.             TerminateProcess(threads.at(i).hProcess,0);
  67.         }
  68.     }
  69.     return 0;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement