Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // MasterL2.cpp : Этот файл содержит функцию "main". Здесь начинается и заканчивается выполнение программы.
- //
- #define _CRT_SECURE_NO_WARNINGS
- #include <iostream>
- #include <thread>
- #include <ctime>
- #include <cstdlib>
- #include <windows.h>
- #include <stdio.h>
- #include <string.h>
- using namespace std;
- class LiveTimer
- {
- public:
- int iteration_;
- int DurationMilliSEC_;
- int fMIN_;
- int fSEC_;
- int fMilliSEC_;
- void Tstrt()
- {
- T_strt = std::chrono::high_resolution_clock::now();
- chrono::duration<float> Tstrt = T_strt - T_strt;
- cout << "Tstrt: " << Tstrt.count() << endl;
- }
- void Tend()
- {
- T_end = std::chrono::high_resolution_clock::now();
- chrono::duration<float> duration = (T_end - T_strt) * 1000;
- LiveTimer::DurationMilliSEC_ = duration.count();
- LiveTimer::fMIN_ = (duration.count() / 1000 / 60);
- LiveTimer::fSEC_ = int(duration.count() / 1000) % 60;
- LiveTimer::fMilliSEC_ = int(duration.count()) - fMIN_ * 60 * 1000 - fSEC_ * 1000;
- chrono::duration<float> Tstrt = T_strt - T_strt;
- cout << "Tend: " << duration.count() << endl;
- }
- void printT() {
- cout << " MilliSEC/iteration: " << LiveTimer::DurationMilliSEC_ / iteration_ << endl;
- cout << "MIN: " << LiveTimer::fMIN_ << " SEC: " << LiveTimer::fSEC_ << " MilliSEC: " << LiveTimer::fMilliSEC_ << endl;
- }
- private:
- std::chrono::time_point<std::chrono::steady_clock> T_strt, T_end;
- };
- LPWSTR winApiFormat(char text[], wchar_t wtext2[128]) {
- mbstowcs(wtext2, text, strlen(text) + 1);//Plus null
- LPWSTR ptr = wtext2;
- return ptr;
- }
- void titleSet(char a[]) {
- wchar_t wtext2[128];
- LPWSTR ptr2 = winApiFormat(a, wtext2);
- SetConsoleTitle(ptr2);
- }
- void setIntArg(char* cmd, int pid) {
- sprintf(cmd + strlen(cmd), " %d", pid);
- }
- void setCharArg(char* cmd, char* arg) {
- sprintf(cmd + strlen(cmd), " %s", arg);
- }
- void pr(char cmd[128], char Process[128], char Prioritet[128]) {
- /// ///////////////////////
- char cmd2[128];
- wchar_t wtext2[128];
- strcpy(cmd2, cmd);
- setCharArg(cmd2, Process);
- setCharArg(cmd2, Prioritet);
- cout << "Master: Start ___ " << cmd2 << " ___" << "\n";
- LPWSTR cmdPtr = winApiFormat(cmd2, wtext2);
- STARTUPINFO info;
- memset(&info, 0, sizeof(info));
- info.cb = sizeof(info);
- //HANDLE hEvent;
- PROCESS_INFORMATION pinfo;
- if (Prioritet[0] == 'I') {
- cout << "------------------------------------\n";
- bool b = CreateProcess(NULL, cmdPtr, NULL, NULL, FALSE, IDLE_PRIORITY_CLASS | CREATE_NEW_CONSOLE,
- NULL, NULL, &info, &pinfo);
- if (!b) {
- cout << "Master: Slave protsess ne zapushchen!!!!!!!!!!!!!\n";
- cout << "Master: проверьте правильность указания имени процесса в коммандной строке";
- }
- }
- if (Prioritet[0] == 'N') {
- cout << "++++++++++++++++++++++++++++++++++++++\n";
- bool b = CreateProcess(NULL, cmdPtr, NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS | CREATE_NEW_CONSOLE,
- NULL, NULL, &info, &pinfo);
- if (!b) {
- cout << "Master: Slave protsess ne zapushchen!!!!!!!!!!!!!\n";
- cout << "Master: проверьте правильность указания имени процесса в коммандной строке";
- }
- }
- if (Prioritet[0] == 'H') {
- cout << "***************************************\n";
- bool b = CreateProcess(NULL, cmdPtr, NULL, NULL, FALSE, HIGH_PRIORITY_CLASS | CREATE_NEW_CONSOLE,
- NULL, NULL, &info, &pinfo);
- if (!b) {
- cout << "Master: Slave protsess ne zapushchen!!!!!!!!!!!!!\n";
- cout << "Master: проверьте правильность указания имени процесса в коммандной строке";
- }
- }
- HANDLE process = OpenProcess(PROCESS_QUERY_INFORMATION | SYNCHRONIZE,
- FALSE, pinfo.dwProcessId);
- if (!process) cout << " Oshibka otkrytiay protsessa Sort\n";
- if (WaitForSingleObject(process, INFINITE) == STATUS_WAIT_0)
- {
- cout << Process << " ------------zavershil rabotu------------\n";
- //cin.get();
- }
- }
- // MasterL2.exe
- int main(int argc, char* argv[]) {
- char cmd[128];
- if (argc != 1) strcpy(cmd, argv[1]);
- else strcpy(cmd, "Sort.exe");
- char title[128] = "MasterL2";
- titleSet(title);
- int pid = GetCurrentProcessId();////////////////////////////////////
- char Process1[128] = "Process1";
- char Process2[128] = "Process2";
- char Prioritet1[128] = "IDLE_PRIORITY_CLASS";
- char Prioritet2[128] = "NORMAL_PRIORITY_CLASS";
- char Prioritet3[128] = "HIGH_PRIORITY_CLASS";
- setIntArg(cmd, pid);
- LiveTimer timeProcess;
- timeProcess.Tstrt();
- pr(cmd, Process1, Prioritet1);
- pr(cmd, Process2, Prioritet2);
- pr(cmd, Process1, Prioritet1);
- pr(cmd, Process2, Prioritet3);
- pr(cmd, Process1, Prioritet2);
- pr(cmd, Process2, Prioritet2);
- timeProcess.Tend();
- cout << "Master: Sleeping\n";
- Sleep(3000);
- //exit(0);
- cout << "Master: EXIT\n";
- cin.get();
- return 0;
- }
- // Запуск программы: CTRL+F5 или меню "Отладка" > "Запуск без отладки"
- // Отладка программы: F5 или меню "Отладка" > "Запустить отладку"
- // Советы по началу работы
- // 1. В окне обозревателя решений можно добавлять файлы и управлять ими.
- // 2. В окне Team Explorer можно подключиться к системе управления версиями.
- // 3. В окне "Выходные данные" можно просматривать выходные данные сборки и другие сообщения.
- // 4. В окне "Список ошибок" можно просматривать ошибки.
- // 5. Последовательно выберите пункты меню "Проект" > "Добавить новый элемент", чтобы создать файлы кода, или "Проект" > "Добавить существующий элемент", чтобы добавить в проект существующие файлы кода.
- // 6. Чтобы снова открыть этот проект позже, выберите пункты меню "Файл" > "Открыть" > "Проект" и выберите SLN-файл.
Add Comment
Please, Sign In to add comment