void SetProcessPriority(int aPid, ProcessPriority aPriority, uint32_t aLRU) { // n.b. The sandboxed implementation crashes; SetProcessPriority works only // from the main process. PROXY_IF_SANDBOXED(SetProcessPriority(aPid, aPriority, aLRU)); }
bool CServerSession::OnRunImage( CNcpMessage* pMsg, int nSize ) { char path[MAXPATH]; //parse the parameters bool bSync = (bool)pMsg->GetRet(); string strImageName = (char*)(pMsg->GetData()); if( !IsAbsDir( strImageName.c_str() ) ) { strcpy( path, m_strCurDir.c_str() ); CatDir( path, strImageName.c_str(), path, ELEMENTS(path) ); } else { strcpy( path, strImageName.c_str() ); } BOOL bOk; int nPriority = m_pServApp->GetPriority(); DWORD dwExitCode = 0; if( bSync ) { //synchronize running, register the handle and wait the process HANDLE hProcess; //bOk = CreateProcess( path, m_strCurDir.c_str(), nPriority, &hProcess ); bOk = CreateProcess( path, m_strCurDir.c_str(), &hProcess ); SetProcessPriority( hProcess, nPriority ); m_pServApp->RegistProc( hProcess ); WaitForProcess( hProcess, &dwExitCode ); m_pServApp->UnregistProc( hProcess ); //CloseProcessHandle( hProcess ); CloseHandle( hProcess ); } else { //just run the process and return. bOk = CreateProcess( path, m_strCurDir.c_str(), NULL ); //bOk = CreateProcess( path, m_strCurDir.c_str(), nPriority, NULL ); //SetProcessPriority( hProcess, nPriority ); } #ifdef _WIN32 printf( "windows process exit code:%d\n", dwExitCode ); #else int status = dwExitCode; if( WIFEXITED(status) )printf( "normal termination, exit status=%d\n", WEXITSTATUS(status) ); else if( WIFSIGNALED(status) )printf( "abnormal termination, signal number=%d\n", WTERMSIG(status) ); else if( WIFSTOPPED(status) )printf( "child stopped, signal number=%d\n", WSTOPSIG(status) ); #endif //send back the return code. pMsg->Init( CM_ACK ); if( !bOk ) { pMsg->SetRet( E_NOEXEC ); } else { pMsg->SetRet( dwExitCode ); } pMsg->Send( m_sock ); return bOk; }
void ScriptSetProcessPriority(ScriptValue &s, ScriptValue *args) { int p = args[1].i32; if (p >= 0 && p < 6) { p = priority[p]; CreateIntValue(s, SetProcessPriority(args[0].i32, p)); } else { CreateIntValue(s, 0); } }
void SetProcessPriority(int aPid, ProcessPriority aPriority, ProcessCPUPriority aCPUPriority, uint32_t aBackgroundLRU) { // n.b. The sandboxed implementation crashes; SetProcessPriority works only // from the main process. MOZ_ASSERT(aBackgroundLRU == 0 || aPriority == PROCESS_PRIORITY_BACKGROUND); PROXY_IF_SANDBOXED(SetProcessPriority(aPid, aPriority, aCPUPriority, aBackgroundLRU)); }
int main(void) { InitializeScreen(); /* Redirect all of std::cout to a curses complaint window */ toolbox::ncurses_stream redirector_cout(std::cout); #ifdef RT_PRIORITY SetProcessPriority(RT_PRIORITY); #endif /* Please check RoboticArtm_Config.h for number of joints*/ RoboArm = new RoboticArm(); /* Register a signal handler to exit gracefully */ signal(SIGINT, _cleanup); RoboArm->Init(); logger << "I: Press the arrow keys to control the robotic arm!" << std::endl << std::endl; for(;;) { /* Used for single line message */ char buffer[80]; /* First obtain the actual coordinates of the robot, to move it at will */ RoboArm->GetPosition(coordinates); /* Arrows will increase position by 1% increments in a x,y plane, uses curses library */ WaitKeyPress(coordinates); /* Command the robot to a new position once that coordinates was updated */ RoboArm->SetPosition(coordinates); sprintf(buffer, " x= %+3.4f | y= %+3.4f | z= %+3.4f", coordinates.x, coordinates.y, coordinates.z); logger << "I: Computed - " << buffer << std::endl; /* Updated coordinates and print it out */ RoboArm->GetPosition(coordinates); sprintf(buffer, " x= %+3.4f | y= %+3.4f | z= %+3.4f", coordinates.x, coordinates.y, coordinates.z); logger << "I: Measured - " << buffer << std::endl; } return EXIT_SUCCESS; }
void SetProcessPriority(int aPid, ProcessPriority aPriority) { PROXY_IF_SANDBOXED(SetProcessPriority(aPid, aPriority)); }
/* * Launch an OpenVPN process and the accompanying thread to monitor it */ BOOL StartOpenVPN(connection_t *c) { TCHAR cmdline[1024]; TCHAR *options = cmdline + 8; TCHAR exit_event_name[17]; HANDLE hStdInRead = NULL, hStdInWrite = NULL; HANDLE hNul = NULL, hThread = NULL; DWORD written; BOOL retval = FALSE; CLEAR(c->ip); if (c->hwndStatus) { PrintDebug(L"Connection request when previous status window is still open -- ignored"); WriteStatusLog(c, L"OpenVPN GUI> ", L"Complete the pending dialog before starting a new connection", false); SetForegroundWindow(c->hwndStatus); return FALSE; } RunPreconnectScript(c); /* Create thread to show the connection's status dialog */ hThread = CreateThread(NULL, 0, ThreadOpenVPNStatus, c, CREATE_SUSPENDED, &c->threadId); if (hThread == NULL) { ShowLocalizedMsg(IDS_ERR_CREATE_THREAD_STATUS); goto out; } /* Create an event object to signal OpenVPN to exit */ _sntprintf_0(exit_event_name, _T("%x%08x"), GetCurrentProcessId(), c->threadId); c->exit_event = CreateEvent(NULL, TRUE, FALSE, exit_event_name); if (c->exit_event == NULL) { ShowLocalizedMsg(IDS_ERR_CREATE_EVENT, exit_event_name); goto out; } /* Create a management interface password */ GetRandomPassword(c->manage.password, sizeof(c->manage.password) - 1); /* Construct command line -- put log first */ _sntprintf_0(cmdline, _T("openvpn --log%s \"%s\" --config \"%s\" " "--setenv IV_GUI_VER \"%S\" --service %s 0 --auth-retry interact " "--management %S %hd stdin --management-query-passwords %s" "--management-hold"), (o.log_append ? _T("-append") : _T("")), c->log_path, c->config_file, PACKAGE_STRING, exit_event_name, inet_ntoa(c->manage.skaddr.sin_addr), ntohs(c->manage.skaddr.sin_port), (o.proxy_source != config ? _T("--management-query-proxy ") : _T(""))); /* Try to open the service pipe */ if (!IsUserAdmin() && InitServiceIO (&c->iserv)) { DWORD size = _tcslen(c->config_dir) + _tcslen(options) + sizeof(c->manage.password) + 3; TCHAR startup_info[1024]; if ( !AuthorizeConfig(c)) { CloseHandle(c->exit_event); goto out; } c->hProcess = NULL; c->manage.password[sizeof(c->manage.password) - 1] = '\n'; _sntprintf_0(startup_info, _T("%s%c%s%c%.*S"), c->config_dir, _T('\0'), options, _T('\0'), sizeof(c->manage.password), c->manage.password); c->manage.password[sizeof(c->manage.password) - 1] = '\0'; if (!WritePipe(c->iserv.pipe, startup_info, size * sizeof (TCHAR))) { ShowLocalizedMsg (IDS_ERR_WRITE_SERVICE_PIPE); CloseHandle(c->exit_event); CloseServiceIO(&c->iserv); goto out; } } else { /* Start OpenVPN directly */ DWORD priority; STARTUPINFO si; PROCESS_INFORMATION pi; SECURITY_DESCRIPTOR sd; /* Make I/O handles inheritable and accessible by all */ SECURITY_ATTRIBUTES sa = { .nLength = sizeof(sa), .lpSecurityDescriptor = &sd, .bInheritHandle = TRUE }; if (!InitializeSecurityDescriptor(&sd, SECURITY_DESCRIPTOR_REVISION)) { ShowLocalizedMsg(IDS_ERR_INIT_SEC_DESC); CloseHandle(c->exit_event); return FALSE; } if (!SetSecurityDescriptorDacl(&sd, TRUE, NULL, FALSE)) { ShowLocalizedMsg(IDS_ERR_SET_SEC_DESC_ACL); CloseHandle(c->exit_event); return FALSE; } /* Set process priority */ if (!SetProcessPriority(&priority)) { CloseHandle(c->exit_event); return FALSE; } /* Get a handle of the NUL device */ hNul = CreateFile(_T("NUL"), GENERIC_WRITE, FILE_SHARE_WRITE, &sa, OPEN_EXISTING, 0, NULL); if (hNul == INVALID_HANDLE_VALUE) { CloseHandle(c->exit_event); return FALSE; } /* Create the pipe for STDIN with only the read end inheritable */ if (!CreatePipe(&hStdInRead, &hStdInWrite, &sa, 0)) { ShowLocalizedMsg(IDS_ERR_CREATE_PIPE_IN_READ); CloseHandle(c->exit_event); goto out; } if (!SetHandleInformation(hStdInWrite, HANDLE_FLAG_INHERIT, 0)) { ShowLocalizedMsg(IDS_ERR_DUP_HANDLE_IN_WRITE); CloseHandle(c->exit_event); goto out; } /* Fill in STARTUPINFO struct */ GetStartupInfo(&si); si.cb = sizeof(si); si.dwFlags = STARTF_USESTDHANDLES; si.hStdInput = hStdInRead; si.hStdOutput = hNul; si.hStdError = hNul; /* Create an OpenVPN process for the connection */ if (!CreateProcess(o.exe_path, cmdline, NULL, NULL, TRUE, priority | CREATE_NO_WINDOW, NULL, c->config_dir, &si, &pi)) { ShowLocalizedMsg(IDS_ERR_CREATE_PROCESS, o.exe_path, cmdline, c->config_dir); CloseHandle(c->exit_event); goto out; } /* Pass management password to OpenVPN process */ c->manage.password[sizeof(c->manage.password) - 1] = '\n'; WriteFile(hStdInWrite, c->manage.password, sizeof(c->manage.password), &written, NULL); c->manage.password[sizeof(c->manage.password) - 1] = '\0'; c->hProcess = pi.hProcess; /* Will be closed in the event loop on exit */ CloseHandle(pi.hThread); } /* Start the status dialog thread */ ResumeThread(hThread); retval = TRUE; out: if (hThread && hThread != INVALID_HANDLE_VALUE) CloseHandle(hThread); if (hStdInWrite && hStdInWrite != INVALID_HANDLE_VALUE) CloseHandle(hStdInWrite); if (hStdInRead && hStdInRead != INVALID_HANDLE_VALUE) CloseHandle(hStdInRead); if (hNul && hNul != INVALID_HANDLE_VALUE) CloseHandle(hNul); return retval; } void StopOpenVPN(connection_t *c) { PostMessage(c->hwndStatus, WM_OVPN_STOP, 0, 0); }
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_COMMAND: switch (LOWORD(wParam)) { case ID_PM_REALTIME: SetProcessPriority(REALTIME_PRIORITY_CLASS); break; case ID_PM_HIGH: SetProcessPriority(HIGH_PRIORITY_CLASS); break; case ID_PM_ABOVE_NORMAL: SetProcessPriority(ABOVE_NORMAL_PRIORITY_CLASS); break; case ID_PM_NORMAL: SetProcessPriority(NORMAL_PRIORITY_CLASS); break; case ID_PM_BELOW_NORMAL: SetProcessPriority(BELOW_NORMAL_PRIORITY_CLASS); break; case ID_PM_IDLE: SetProcessPriority(IDLE_PRIORITY_CLASS); break; } switch (HIWORD(wParam)) { case 1: { if (lParam == (LPARAM)ListBoxProcess) ShowModule(); } break; default: return DefWindowProc(hWnd, message, wParam, lParam); break; } break; case WM_CONTEXTMENU: if (SendMessage(ListBoxProcess, LB_GETCURSEL, 0, 0) != LB_ERR) { POINT cursorPosition; GetCursorPos(&cursorPosition); TrackPopupMenu(PopupMenu, TPM_BOTTOMALIGN | TPM_LEFTALIGN, cursorPosition.x, cursorPosition.y, 0, hWnd, NULL); } break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); break; } return 0; }
// // ‘”Ќ ÷»я: WndProc(HWND, UINT, WPARAM, LPARAM) // // Ќј«Ќј„≈Ќ»≈: обрабатывает сообщени¤ в главном окне. // // WM_COMMAND - обработка меню приложени¤ // WM_PAINT -«акрасить главное окно // WM_DESTROY - ввести сообщение о выходе и вернутьс¤. // // LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { int wmId, wmEvent; PAINTSTRUCT ps; HDC hdc; switch (message) { case WM_CREATE: hWndListL = CreateWindowEx(NULL, TEXT("LISTBOX"), NULL, WS_BORDER | WS_CHILD | WS_VISIBLE | ES_AUTOVSCROLL | LBS_NOTIFY | LBS_STANDARD, 10, 10, 200, 280, hWnd, (HMENU)IDC_LEFT_LIST, hInst, NULL); hWndListR = CreateWindowEx(NULL, TEXT("LISTBOX"), NULL, WS_BORDER | WS_CHILD | WS_VISIBLE | ES_AUTOVSCROLL | LBS_NOTIFY | LBS_STANDARD, 220, 10, 500, 280, hWnd, (HMENU)IDC_RIGHT_LIST, hInst, NULL); hWndButtonScanner = CreateWindowEx(NULL, TEXT("BUTTON"), TEXT("Scanner"), WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, 10, 290, 120, 30, hWnd, (HMENU)IDC_BUTTON_SCANNER, hInst, NULL); break; case WM_COMMAND: wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); // –азобрать выбор в меню: switch (wmId) { case IDC_BUTTON_SCANNER: { SendMessage(hWndListL, LB_RESETCONTENT, NULL, NULL); ProcessScannerAndPrintHisName(hWndListL); break; } case IDC_LEFT_LIST: { if (wmEvent == LBN_DBLCLK) { SendMessage(hWndListR, LB_RESETCONTENT, NULL, NULL); auto processID = GetSelectProccesID(hWndListL); PrintModulesName(hWndListR, processID); } break; } case WM_RBUTTONUP: break; case IDM_ABOUT: DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About); break; case IDM_EXIT: DestroyWindow(hWnd); break; default: if (IsValidPriorityID(wmId)) SetProcessPriority(saveProcessID, wmId); return DefWindowProc(hWnd, message, wParam, lParam); } break; case WM_CONTEXTMENU: if ((HWND)wParam == hWndListL) { auto processID = GetSelectProccesID(hWndListL); ShowMenuProcessPriority(hWnd, processID); } break; case WM_PAINT: hdc = BeginPaint(hWnd, &ps); // TODO: добавьте любой код отрисовки... EndPaint(hWnd, &ps); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; }