C++ Sending a simple signal in Windows

后端 未结 2 1266
臣服心动
臣服心动 2021-01-13 21:37

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

int kill(pid_t pid, int sig);

If not, would it be possible to test if a process i

2条回答
  •  被撕碎了的回忆
    2021-01-13 22:01

    Windows doesn't have signals in the unix sense.

    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;
    }
    

提交回复
热议问题