Added Utility::GetPid() helper function.

This commit is contained in:
Gunnar Beutner 2012-09-19 13:00:48 +02:00
parent d98ceb7b79
commit 852ad5d964
4 changed files with 18 additions and 7 deletions

View File

@ -347,13 +347,7 @@ void Application::UpdatePidFile(const String& filename)
} }
#endif /* _WIN32 */ #endif /* _WIN32 */
#ifndef _WIN32 fprintf(m_PidFile, "%d", Utility::GetPid());
pid_t pid = getpid();
#else /* _WIN32 */
DWORD pid = GetCurrentProcessId();
#endif /* _WIN32 */
fprintf(m_PidFile, "%d", pid);
fflush(m_PidFile); fflush(m_PidFile);
} }

View File

@ -289,3 +289,17 @@ double Utility::GetTime(void)
return tv.tv_sec + tv.tv_usec / 1000000.0; return tv.tv_sec + tv.tv_usec / 1000000.0;
#endif /* _WIN32 */ #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 */
}

View File

@ -48,6 +48,8 @@ public:
static double GetTime(void); static double GetTime(void);
static pid_t GetPid(void);
private: private:
static bool m_SSLInitialized; static bool m_SSLInitialized;

View File

@ -35,6 +35,7 @@
#endif /* __MINGW32__ */ #endif /* __MINGW32__ */
typedef int socklen_t; typedef int socklen_t;
typedef DWORD pid_t;
#define MAXPATHLEN MAX_PATH #define MAXPATHLEN MAX_PATH