From 75bf02a2f721bb62c55ca116fa41e69f06e1c171 Mon Sep 17 00:00:00 2001 From: rswindell <> Date: Thu, 3 Jun 2010 01:34:41 +0000 Subject: [PATCH] Created check_pid() and terminate_pid() wrapper functions. --- src/xpdev/genwrap.c | 42 ++++++++++++++++++++++++++++++++++++++++++ src/xpdev/genwrap.h | 4 ++++ 2 files changed, 46 insertions(+) diff --git a/src/xpdev/genwrap.c b/src/xpdev/genwrap.c index 00df06ddad..99a82adfb6 100644 --- a/src/xpdev/genwrap.c +++ b/src/xpdev/genwrap.c @@ -560,3 +560,45 @@ long double DLLCALL xp_timer(void) #endif return(ret); } + +/* Returns TRUE if specified process is running */ +BOOL DLLCALL check_pid(pid_t pid) +{ +#if defined(__unix__) + return(kill(pid,0)==0); +#elif defined(_WIN32) + HANDLE h; + BOOL result=FALSE; + + if((h=OpenProcess(PROCESS_QUERY_INFORMATION,/* inheritable: */FALSE, pid)) != NULL) { + DWORD code; + if(GetExitCodeProcess(h,&code)==TRUE && code==STILL_ACTIVE) + result=TRUE; + CloseHandle(h); + } + return result; +#else + return FALSE; /* Need check_pid() definition! */ +#endif +} + +/* Terminate (unconditionally) the specified process */ +BOOL DLLCALL terminate_pid(pid_t pid) +{ +#if defined(__unix__) + return(kill(pid,SIGKILL)==0); +#elif defined(_WIN32) + HANDLE h; + BOOL result=FALSE; + + if((h=OpenProcess(PROCESS_TERMINATE,/* inheritable: */FALSE, pid)) != NULL) { + if(TerminateProcess(h,255)) + result=TRUE; + CloseHandle(h); + } + return result; +#else + return FALSE; /* Need check_pid() definition! */ +#endif +} + diff --git a/src/xpdev/genwrap.h b/src/xpdev/genwrap.h index 6e0182ebf4..78ca447b6f 100644 --- a/src/xpdev/genwrap.h +++ b/src/xpdev/genwrap.h @@ -60,6 +60,7 @@ #endif #elif defined(_WIN32) #include <process.h> /* getpid() */ + typedef DWORD pid_t; #endif #if !defined(_WIN32) @@ -348,6 +349,9 @@ typedef clock_t msclock_t; msclock_t msclock(void); #endif +DLLEXPORT BOOL DLLCALL check_pid(pid_t); +DLLEXPORT BOOL DLLCALL terminate_pid(pid_t); + #if defined(__cplusplus) } #endif -- GitLab