getpid.cpp 846 B

12345678910111213141516171819202122
  1. #include "getpid.h"
  2. #ifdef _win_
  3. // The include file should be Windows.h for Windows <=7, Processthreadsapi.h for Windows >=8 and Server 2012,
  4. // see http://msdn.microsoft.com/en-us/library/windows/desktop/ms683180%28v=vs.85%29.aspx
  5. // The way to determine windows version is described in http://msdn.microsoft.com/en-us/library/windows/desktop/aa383745%28v=vs.85%29.aspx
  6. // with additions about Windows Server 2012 in https://social.msdn.microsoft.com/forums/vstudio/en-US/8d76d1d7-d078-4c55-963b-77e060845d0c/what-is-ntddiversion-value-for-ws-2012
  7. #include <Windows.h>
  8. #if defined(NTDDI_WIN8) && (NTDDI_VERSION >= NTDDI_WIN8)
  9. #include <processthreadsapi.h>
  10. #endif
  11. #else
  12. #include <unistd.h>
  13. #endif
  14. TProcessId GetPID() {
  15. #ifdef _win_
  16. return GetCurrentProcessId();
  17. #else
  18. return getpid();
  19. #endif
  20. }