Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <Windows.h>
- #include <iostream>
- #include <iomanip>
- #include <vector>
- using namespace std;
- void generateProcess() {
- }
- DWORD WINAPI TheadFunc(LPVOID) {
- generateProcess();
- int i= 0;
- DWORD word = i;
- ++i;
- return word;
- }
- int main(int argc, char* argv[])
- {
- int k = atoi(argv[1]);
- int N = atoi(argv[2]);
- const int nTimerUnitsPerSecond = 10000000;
- LARGE_INTEGER li;
- li.QuadPart = -(k * nTimerUnitsPerSecond);
- int theArg = 5;
- DWORD targetThreadId ;
- HANDLE hTimer = CreateWaitableTimer(NULL, FALSE, NULL);
- if (SetWaitableTimer(hTimer, &li, 1000, NULL, NULL, FALSE))
- {
- cout << "Waiting : " << k << " se conds " << endl;
- vector<PROCESS_INFORMATION> threads;
- for (int i = 0; i < N; ++i) {
- TCHAR lpCommandLine[] = L"X:\\3530904_80021\\Rusanov\\OS\\lab2\\lab2\\Debug\\ConsoleApplication1.exe";
- STARTUPINFO startupInfo;
- PROCESS_INFORMATION processInfo;
- ZeroMemory(&startupInfo, sizeof(STARTUPINFO));
- startupInfo.cb = sizeof(startupInfo);
- int r = CreateProcess(NULL, lpCommandLine, NULL, NULL, FALSE, HIGH_PRIORITY_CLASS | CREATE_NEW_CONSOLE,
- NULL, NULL, &startupInfo, &processInfo);
- if (!r)
- {
- fprintf(stderr, "CreateProcess failed on error % d\n", GetLastError());
- ExitProcess(1);
- }
- threads.push_back( processInfo);
- }
- WaitForSingleObject(hTimer, INFINITE);
- for (int i = 0; i < N; ++i) {
- TerminateProcess(threads.at(i).hProcess,0);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement