Mass++ Common Libraries v2.7.5
 All Classes Namespaces Files Functions Variables Enumerations Macros
Functions
ProcessFunctions.cpp File Reference

implements of function which deals with process More...

#include "stdafx.h"
#include <sys/types.h>
#include <unistd.h>
#include <signal.h>
Include dependency graph for ProcessFunctions.cpp:

Go to the source code of this file.

Functions

unsigned int getprocessid ()
 gets procsess ID More...
 
bool processexists (const unsigned int pid)
 judges whether specified process is exists or not. More...
 

Detailed Description

implements of function which deals with process

Author
S.Tanaka
Date
2009.08.27

Copyright(C) 2006-2014 Eisai Co., Ltd. All rights reserved.

Definition in file ProcessFunctions.cpp.

Function Documentation

unsigned int getprocessid ( )

gets procsess ID

Returns
process ID

Definition at line 24 of file ProcessFunctions.cpp.

24  {
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 }
bool processexists ( const unsigned int  pid)

judges whether specified process is exists or not.

Parameters
[in]pidprocess ID
Returns
If true, specified process exists.

Definition at line 37 of file ProcessFunctions.cpp.

37  {
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