diff --git a/src/xpdev/genwrap.c b/src/xpdev/genwrap.c index 00df06ddadc2eb5b3174998b15f19e789149c498..99a82adfb6f09bbf9d0e73e7ba433d54395adde4 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 6e0182ebf4ae9fddfc40db3493b8e1ca8d78cbcb..78ca447b6fcf3eb74a2bd55bc28e28073d7eaf13 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