MCPcopy Create free account
hub / github.com/danoon2/Boxedwine / kill

Method kill

lib/tiny-process/process_win.cpp:371–394  ·  view source on GitHub ↗

Based on http://stackoverflow.com/a/1173396

Source from the content-addressed store, hash-verified

369
370// Based on http://stackoverflow.com/a/1173396
371void Process::kill(bool /*force*/) noexcept {
372 std::lock_guard<std::mutex> lock(close_mutex);
373 if(data.id > 0 && !closed) {
374 HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
375 if(snapshot) {
376 PROCESSENTRY32 process;
377 ZeroMemory(&process, sizeof(process));
378 process.dwSize = sizeof(process);
379 if(Process32First(snapshot, &process)) {
380 do {
381 if(process.th32ParentProcessID == data.id) {
382 HANDLE process_handle = OpenProcess(PROCESS_TERMINATE, FALSE, process.th32ProcessID);
383 if(process_handle) {
384 TerminateProcess(process_handle, 2);
385 CloseHandle(process_handle);
386 }
387 }
388 } while(Process32Next(snapshot, &process));
389 }
390 CloseHandle(snapshot);
391 }
392 TerminateProcess(data.handle, 2);
393 }
394}
395
396// Based on http://stackoverflow.com/a/1173396
397void Process::kill(id_type id, bool /*force*/) noexcept {

Callers 1

mainFunction · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected