Commit 75bf02a2 authored by rswindell's avatar rswindell
Browse files

Created check_pid() and terminate_pid() wrapper functions.

parent 0b053ef3
......@@ -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
}
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment