Advertisement
Savelyev_Vyacheslav

ANZH_master

May 15th, 2021
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.14 KB | None | 0 0
  1. // master.cpp : Этот файл содержит функцию "main". Здесь начинается и заканчивается выполнение программы.
  2. //
  3.  
  4. #define _CRT_SECURE_NO_WARNINGS
  5. #include <windows.h>
  6. #include <iostream>
  7. #include <thread>
  8. #include <cstdlib>
  9. #include <stdio.h>
  10. #include <string.h>
  11. #include <ctime>
  12. using namespace std;
  13.  
  14.  
  15. class GETtime
  16. {
  17.  
  18. public:
  19. int sec_t;
  20. int MSCostatok;
  21. int One_Step;
  22.  
  23. int min_t;
  24. int milisecTotal;
  25.  
  26. void strtT()
  27. {
  28. tStart = std::chrono::high_resolution_clock::now();
  29. chrono::duration<float> strtT = tStart - tStart;
  30. cout << "strtT: " << strtT.count() << endl;
  31. }
  32. void endT()
  33. {
  34. tEnd = std::chrono::high_resolution_clock::now();
  35. chrono::duration<float> duration = (tEnd - tStart) * 1000;
  36. GETtime::milisecTotal = duration.count();
  37. GETtime::min_t = (duration.count() / 1000 / 60);
  38. GETtime::sec_t = int(duration.count() / 1000) % 60;
  39. GETtime::MSCostatok = int(duration.count()) - min_t * 60 * 1000 - sec_t * 1000;
  40. chrono::duration<float> strtT = tStart - tStart;
  41. cout << "tEnd: " << duration.count() << endl;
  42. cout << "minut: " << GETtime::min_t << " sekund: " << GETtime::sec_t << " milisekund " << GETtime::MSCostatok << endl;
  43. }
  44. void print_Iteration() {
  45. cout << " Секунд за 1 итерацию: " << GETtime::milisecTotal / One_Step << endl;
  46.  
  47. }
  48. private:
  49. std::chrono::time_point<std::chrono::steady_clock> tStart, tEnd;
  50. };
  51.  
  52.  
  53.  
  54. LPWSTR FormatToWIN32(char in[], wchar_t format[128]) {
  55. mbstowcs(format, in, strlen(in) + 1);
  56. LPWSTR NewFormat = format;
  57. return NewFormat;
  58. }
  59. void titleSet(char a[]) {
  60. wchar_t wtext2[128];
  61. LPWSTR ptr2 = FormatToWIN32(a, wtext2);
  62. SetConsoleTitle(ptr2);
  63. }
  64.  
  65.  
  66. void InToCmd(char* cmd, char* arg) {
  67. sprintf(cmd + strlen(cmd), " %s", arg);
  68. }
  69.  
  70.  
  71.  
  72.  
  73. void prioryty1(char Process[128]) {
  74. //
  75. char cmd[128];
  76. strcpy(cmd, "sort.exe");
  77.  
  78. char Prioritet[128] = "IDLE_PRIORITY_CLASS";
  79.  
  80. char cmd2[128];
  81. wchar_t wtext2[128];
  82. strcpy(cmd2, cmd);
  83. InToCmd(cmd2, Process);
  84. InToCmd(cmd2, Prioritet);
  85. LPWSTR cmdPtr = FormatToWIN32(cmd2, wtext2);
  86.  
  87. STARTUPINFO info;
  88. memset(&info, 0, sizeof(info));
  89. info.cb = sizeof(info);
  90. //HANDLE hEvent;
  91. PROCESS_INFORMATION pinfo;
  92.  
  93.  
  94.  
  95. if (!CreateProcess(NULL, cmdPtr, NULL, NULL, FALSE, IDLE_PRIORITY_CLASS | CREATE_NEW_CONSOLE,
  96. NULL, NULL, &info, &pinfo)) {
  97. cout << "Master: Slave protsess ne zapushchen!!!!!!!!!!!!!\n";
  98. cout << "Master: проверьте правильность указания имени процесса в коммандной строке";
  99. }
  100.  
  101.  
  102. HANDLE process = OpenProcess(PROCESS_QUERY_INFORMATION | SYNCHRONIZE,
  103. FALSE, pinfo.dwProcessId);
  104. if (!process) cout << " Oshibka otkrytiay protsessa Sort\n";
  105. if (WaitForSingleObject(process, INFINITE) == STATUS_WAIT_0)
  106. {
  107. cout << Process << " ------------zavershil rabotu------------\n";
  108. //cin.get();
  109. }
  110. }
  111. void prioryty2(char Process[128]) {
  112. //
  113. char cmd[128];
  114. strcpy(cmd, "sort.exe");
  115.  
  116. char Prioritet[128] = "NORMAL_PRIORITY_CLASS";
  117.  
  118. char cmd2[128];
  119. wchar_t wtext2[128];
  120. strcpy(cmd2, cmd);
  121. InToCmd(cmd2, Process);
  122. InToCmd(cmd2, Prioritet);
  123. cout << "Master: Start ___ " << cmd2 << " ___" << "\n";
  124. LPWSTR cmdPtr = FormatToWIN32(cmd2, wtext2);
  125.  
  126. STARTUPINFO info;
  127. memset(&info, 0, sizeof(info));
  128. info.cb = sizeof(info);
  129. //HANDLE hEvent;
  130. PROCESS_INFORMATION pinfo;
  131.  
  132.  
  133.  
  134. if (!CreateProcess(NULL, cmdPtr, NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS | CREATE_NEW_CONSOLE,
  135. NULL, NULL, &info, &pinfo)) {
  136. cout << "Master: Slave protsess ne zapushchen!!!!!!!!!!!!!\n";
  137. cout << "Master: проверьте правильность указания имени процесса в коммандной строке";
  138. }
  139.  
  140.  
  141. HANDLE process = OpenProcess(PROCESS_QUERY_INFORMATION | SYNCHRONIZE,
  142. FALSE, pinfo.dwProcessId);
  143. if (!process) cout << " Oshibka otkrytiay protsessa Sort\n";
  144. if (WaitForSingleObject(process, INFINITE) == STATUS_WAIT_0)
  145. {
  146. cout << Process << " ------------zavershil rabotu------------\n";
  147. //cin.get();
  148. }
  149. }
  150. void prioryty3(char Process[128]) {
  151.  
  152. char cmd[128];
  153. strcpy(cmd, "sort.exe");
  154.  
  155. char Prioritet[128] = "HIGH_PRIORITY_CLASS";
  156.  
  157. char cmd2[128];
  158. wchar_t wtext2[128];
  159. strcpy(cmd2, cmd);
  160. InToCmd(cmd2, Process);
  161. InToCmd(cmd2, Prioritet);
  162. cout << "Master: Start ___ " << cmd2 << " ___" << "\n";
  163. LPWSTR cmdPtr = FormatToWIN32(cmd2, wtext2);
  164.  
  165. STARTUPINFO info;
  166. memset(&info, 0, sizeof(info));
  167. info.cb = sizeof(info);
  168. PROCESS_INFORMATION pinfo;
  169.  
  170.  
  171.  
  172. if (!CreateProcess(NULL, cmdPtr, NULL, NULL, FALSE, HIGH_PRIORITY_CLASS | CREATE_NEW_CONSOLE,
  173. NULL, NULL, &info, &pinfo)) {
  174. cout << "Master: Slave protsess ne zapushchen!!!!!!!!!!!!!\n";
  175. cout << "Master: проверьте правильность указания имени процесса в коммандной строке";
  176. }
  177.  
  178.  
  179. HANDLE process = OpenProcess(PROCESS_QUERY_INFORMATION | SYNCHRONIZE,
  180. FALSE, pinfo.dwProcessId);
  181. if (!process) cout << " Oshibka otkrytiay protsessa Sort\n";
  182. if (WaitForSingleObject(process, INFINITE) == STATUS_WAIT_0)
  183. {
  184. cout << Process << " ------------zavershil rabotu------------\n";
  185.  
  186. }
  187. }
  188.  
  189.  
  190. int main(int argc, char* argv[]) {
  191. char cmd[128];
  192. if (argc != 1) strcpy(cmd, argv[1]);
  193. else strcpy(cmd, "sort.exe");
  194.  
  195. char title[128] = "masterAnzh";
  196. wchar_t wtext2[128];
  197. LPWSTR pp = FormatToWIN32(title, wtext2);
  198. SetConsoleTitle(pp);
  199.  
  200.  
  201.  
  202. char Process1[128] = "Process1";
  203. char Process2[128] = "Process2";
  204.  
  205.  
  206. GETtime timeProcess;
  207. timeProcess.strtT();
  208. prioryty1(Process1);prioryty3(Process2);
  209. prioryty1(Process1); prioryty1(Process2);
  210. prioryty2(Process1); prioryty1(Process2);
  211.  
  212. timeProcess.endT();
  213.  
  214.  
  215. cout << "Master: Sleeping\n";
  216. Sleep(3000);
  217.  
  218.  
  219. cout << "Master: EXIT\n";
  220. cin.get();
  221. return 0;
  222. }
  223.  
  224. // Запуск программы: CTRL+F5 или меню "Отладка" > "Запуск без отладки"
  225. // Отладка программы: F5 или меню "Отладка" > "Запустить отладку"
  226.  
  227. // Советы по началу работы
  228. // 1. В окне обозревателя решений можно добавлять файлы и управлять ими.
  229. // 2. В окне Team Explorer можно подключиться к системе управления версиями.
  230. // 3. В окне "Выходные данные" можно просматривать выходные данные сборки и другие сообщения.
  231. // 4. В окне "Список ошибок" можно просматривать ошибки.
  232. // 5. Последовательно выберите пункты меню "Проект" > "Добавить новый элемент", чтобы создать файлы кода, или "Проект" > "Добавить существующий элемент", чтобы добавить в проект существующие файлы кода.
  233. // 6. Чтобы снова открыть этот проект позже, выберите пункты меню "Файл" > "Открыть" > "Проект" и выберите SLN-файл.
  234.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement