| Return Type | Function name | Arguments |
|---|---|---|
| void | SingleProc | (void) |
Declared in file: hzProcess.h
Defined in file : hzProcess.cpp
Function Logic:
Function body:
void SingleProc (void)
{
FSTAT fs ;
dirent* pDE ;
DIR* pDir ;
uint32_t ino ;
uint32_t cpid ;
uint32_t xpid ;
char buf [512];
/*
** ** Obtain current executable
** */
cpid = getpid() ;
sprintf(buf, "/proc/%d/exe", cpid) ;
if (lstat(buf, &fs) == -1)
{
std::cerr << "Could not stat " << buf << std::endl ;
exit(-1);
}
ino = fs.st_ino ;
/*
** ** Open the /proc directory and read it.
** */
pDir = opendir("/proc") ;
if (!pDir)
{
std::cerr << "Cannot examine processes" << std::endl ;
exit(-3);
}
for (; pDE = readdir(pDir) ;)
{
if (pDE->d_name[0]== ''.'')
continue ;
if (!IsAllDigits(pDE->d_name))
continue ;
xpid = atoi(pDE->d_name) ;
if (xpid == cpid)
continue ;
sprintf(buf, "/proc/%d/exe", xpid) ;
if (lstat(buf, &fs) == -1)
std::cout << "Could not stat " << buf << std::endl ;
else
{
if (fs.st_ino == ino)
{
std::cout << "pid: " << cpid << " - Have located an existing process of " << xpid << std::endl ;
std::cerr << "Both the existing and current process involve executable with inode of " << ino << std::endl ;
exit(-4);
}
}
}
closedir(pDir) ;
}