C ++ Sending a simple signal in Windows

is there an equivalent to the kill () function on windows?

int kill(pid_t pid, int sig); 

If not, is it possible to check if a process is running based on its PID?

thanks

+4
source share
2 answers

Windows has no signals in the sense of unix.

You can use OpenProcess to check if a process exists. If it succeeds or fails with an access error, then the process exists.

 bool processExists(DWORD ProcessID) { HANDLE hProcess = OpenProcess(SYNCHRONIZE, FALSE, ProcessID); if (hProcess != NULL) { CloseHandle(hProcess); return true; } // If the error code is access denied, the process exists but we don't have access to open a handle to it. return GetLastError() == ERROR_ACCESS_DENIED; } 
+2
source

There are no signals in Windows. If true kill is expected, use TerminateProcess (). You need a process descriptor, get it from OpenProcess (). You will need to request the PROCESS_TERMINATE permission. CloseHandle () to close the handle.

+1
source

Source: https://habr.com/ru/post/1343526/


All Articles