Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _WIN32_WINNT 0x0400
- #include <windows.h>
- #include <stdio.h>
- #define _SECOND 10000000
- #include <iostream>
- #include <time.h>
- using namespace std;
- static int lol;
- struct ProcessAdditionalInfo {
- int id;
- int k;
- PROCESS_INFORMATION* pi;
- };
- DWORD WINAPI waitAndClose(LPVOID argc) {
- HANDLE wTimer;
- wTimer = CreateWaitableTimer(NULL, FALSE, NULL);
- __int64 endTime;
- srand(lol);
- endTime = rand() % 10;
- lol = endTime;
- LARGE_INTEGER quitTime;
- quitTime.LowPart = (DWORD)(-endTime * _SECOND & 0xFFFFFFFF);
- quitTime.HighPart = (LONG)(-endTime * _SECOND >> 32);
- SetWaitableTimer(wTimer, &quitTime, 0, NULL, NULL, FALSE);
- SYSTEMTIME now;
- GetSystemTime(&now);
- ProcessAdditionalInfo* info = (ProcessAdditionalInfo*)argc;
- cout << "Before process " << info->id << ", timeout=" << endTime << " now:" << now.wSecond << endl;
- WaitForSingleObject(wTimer, info->k * _SECOND);
- GetSystemTime(&now);
- cout << "After process " << ((ProcessAdditionalInfo*)argc)->id << " " << now.wSecond << endl;
- CloseHandle(wTimer);
- TerminateProcess(info->pi->hProcess, 1);
- return NULL;
- }
- int main(int acgc, char* argv[])
- {
- lol = time(NULL);
- srand(lol);
- int n = atoi(argv[1]);
- int k = atoi(argv[2]);
- STARTUPINFO cif;
- ZeroMemory(&cif, sizeof(STARTUPINFO));
- PROCESS_INFORMATION* pi = new PROCESS_INFORMATION;
- LPCWSTR name;
- for (int i = 0; i < n; i++) {
- if (CreateProcess(
- TEXT("C:\\windows\\system32\\calc.exe"),
- NULL,
- NULL,
- NULL,
- FALSE,
- NULL,
- NULL,
- NULL,
- &cif,
- pi
- )) {
- ProcessAdditionalInfo* info = new ProcessAdditionalInfo{i, k, pi};
- CreateThread(NULL, 128, waitAndClose, info, 0, NULL);
- Sleep(100);
- }
- }
- Sleep(k * 1000);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement