Mass++ Common Libraries v2.7.5
 All Classes Namespaces Files Functions Variables Enumerations Macros
ProcessFunctions.cpp
Go to the documentation of this file.
1 
12 #include "stdafx.h"
13 
14 #ifdef _MSC_VER
15  #include <process.h>
16 #else
17  #include <sys/types.h>
18  #include <unistd.h>
19  #include <signal.h>
20 #endif // _MSC_VER
21 
22 
23 // get process ID
24 unsigned int getprocessid() {
25 
26 #ifdef _MSC_VER
27  const unsigned int pid = _getpid();
28 #else
29  const unsigned int pid = getpid();
30 #endif // _MSC_VER
31 
32  return pid;
33 }
34 
35 
36 // judges whether specified process exists or not
37 bool processexists( const unsigned int pid ) {
38  bool ret = false;
39 
40 #ifdef _MSC_VER
41  HANDLE handle = OpenProcess(
42  SYNCHRONIZE,
43  FALSE,
44  (DWORD)pid
45  );
46 // >>>>>> @Date:2013/10/03 <Modified> A.Ozaki
47  if ( (HANDLE)NULL != handle )
48  {
49  ret = true;
50  }
51  if ( GetLastError( ) == ERROR_ACCESS_DENIED )
52  {
53  ret = true;
54  }
55 // <<<<<< @Date:2013/10/03 <Modified> A.Ozaki
56 
57  if( handle != NULL ) {
58  CloseHandle( handle );
59  }
60 
61 #else
62  if( kill( pid, 0 ) == 0 ) {
63  ret = true;
64  }
65 #endif // _MSC_VER
66 
67  return ret;
68 }
#define NULL
Definition: CoreMacros.h:18
bool processexists(const unsigned int pid)
judges whether specified process is exists or not.
unsigned int getprocessid()
gets procsess ID