Return TypeFunction nameArguments
voidSingleProc(void)

Declared in file: hzProcess.h
Defined in file : hzProcess.cpp

Function Logic:

0:START 1:getpid cpid sprintf 2:lstat(buf,&fs)==-1 3:items exit 4:ino opendir pDir 5:!pDir 6:items exit 7:pDE=readdir(pDir); 8:pDE->d_name[0]=='.' 9:!IsAllDigits(pDE->d_name) 10:atoi xpid 11:xpid==cpid 12:sprintf 13:lstat(buf,&fs)==-1 14:items 15:fs.st_ino==ino 16:items items exit 17:closedir 18: No text

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) ;
}