diff --git a/lib/base/application.cpp b/lib/base/application.cpp index 66a337b17..fc36f4605 100644 --- a/lib/base/application.cpp +++ b/lib/base/application.cpp @@ -347,13 +347,7 @@ void Application::UpdatePidFile(const String& filename) } #endif /* _WIN32 */ -#ifndef _WIN32 - pid_t pid = getpid(); -#else /* _WIN32 */ - DWORD pid = GetCurrentProcessId(); -#endif /* _WIN32 */ - - fprintf(m_PidFile, "%d", pid); + fprintf(m_PidFile, "%d", Utility::GetPid()); fflush(m_PidFile); } diff --git a/lib/base/utility.cpp b/lib/base/utility.cpp index b64e6b145..a34512e4d 100644 --- a/lib/base/utility.cpp +++ b/lib/base/utility.cpp @@ -289,3 +289,17 @@ double Utility::GetTime(void) return tv.tv_sec + tv.tv_usec / 1000000.0; #endif /* _WIN32 */ } + +/** + * Returns the ID of the current process. + * + * @returns The PID. + */ +pid_t Utility::GetPid(void) +{ +#ifndef _WIN32 + return getpid(); +#else /* _WIN32 */ + return GetCurrentProcessId(); +#endif /* _WIN32 */ +} diff --git a/lib/base/utility.h b/lib/base/utility.h index 7ff9a2ab2..96c914a37 100644 --- a/lib/base/utility.h +++ b/lib/base/utility.h @@ -48,6 +48,8 @@ public: static double GetTime(void); + static pid_t GetPid(void); + private: static bool m_SSLInitialized; diff --git a/lib/base/win32.h b/lib/base/win32.h index fea3d795d..a6fc28d9c 100644 --- a/lib/base/win32.h +++ b/lib/base/win32.h @@ -35,6 +35,7 @@ #endif /* __MINGW32__ */ typedef int socklen_t; +typedef DWORD pid_t; #define MAXPATHLEN MAX_PATH