version 1.2, 2007/05/25 18:35:07
|
version 1.3, 2007/06/12 18:19:46
|
|
|
#else | #else |
# error "not implemented on this platform." | # error "not implemented on this platform." |
#endif /* PEGASUS_PLATFORM_LINUX_GENERIC_GNU */ | #endif /* PEGASUS_PLATFORM_LINUX_GENERIC_GNU */ |
|
|
|
/* |
|
**============================================================================== |
|
** |
|
** ReadPidFile() |
|
** |
|
**============================================================================== |
|
*/ |
|
|
|
int ReadPidFile(const char* pidFilePath, int* pid) |
|
{ |
|
FILE* is = fopen(pidFilePath, "r"); |
|
|
|
if (!is) |
|
return -1; |
|
|
|
*pid = 0; |
|
|
|
fscanf(is, "%d\n", pid); |
|
fclose(is); |
|
|
|
if (*pid == 0) |
|
return -1; |
|
|
|
return 0; |
|
} |
|
|
|
/* |
|
**============================================================================== |
|
** |
|
** TestProcessRunning() |
|
** |
|
** Returns 0 if a process is running with the ID in the specified PID file |
|
** and with the specified process name. |
|
** |
|
**============================================================================== |
|
*/ |
|
|
|
int TestProcessRunning( |
|
const char* pidFilePath, |
|
const char* processName) |
|
{ |
|
int pid; |
|
char name[EXECUTOR_BUFFER_SIZE]; |
|
|
|
if (ReadPidFile(pidFilePath, &pid) != 0) |
|
return -1; |
|
|
|
if (GetProcessName(pid, name) != 0 || strcmp(name, processName) != 0) |
|
return -1; |
|
|
|
return 0; |
|
} |