Return TypeFunction nameArguments
hzEcodeListProcesses(hzMapS<unsigned int,hzProginfo*>&,)

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

Function Logic:

0:START 1:nIndex 2:nIndex 3:hzMapS::GetObj pPI pPI 4:hzMapS::Clear opendir pDir 5:!pDir 6:Return E_CORRUPT 7:pDE=readdir(pDir); 8:pDE->d_name[0]=='.' 9:!IsAllDigits(pDE->d_name) 10:atoi xpid pPI 11:pPI 12:Return E_SETONCE 13:pPI pPI sprintf 14:lstat(buf,&fs)==-1 15:items 16:fs.st_ino==ino 17:items items exit 18:hzMapS::Insert 19:closedir 20:Return E_OK

Function body:

hzEcode ListProcesses (hzMapS<unsigned int,hzProginfo*>& procs)
{
   _hzfunc("ListProcesses") ;
   hzProginfo* pPI ;
   FSTAT       fs ;
   dirent*     pDE ;
   DIR*        pDir ;
   uint32_t    ino ;
   uint32_t    cpid ;
   uint32_t    xpid ;
   uint32_t    nIndex ;
   char        buf [512];
   /*
   **  ** Obtain current executable
   **      */
   for (nIndex = 0; nIndex < procs.Count() ; nIndex++)
   {
       pPI = procs.GetObj(nIndex) ;
       delete pPI ;
   }
   procs.Clear() ;
   pDir = opendir("/proc") ;
   if (!pDir)
   {
       hzerr(E_CORRUPT, "Could not open the /proc directory") ;
       return E_CORRUPT ;
   }
   for (; pDE = readdir(pDir) ;)
   {
       if (pDE->d_name[0]== ''.'')
           continue ;
       if (!IsAllDigits(pDE->d_name))
           continue ;
       xpid = atoi(pDE->d_name) ;
       pPI = procs[xpid] ;
       if (pPI)
       {
           hzerr(E_SETONCE, "We already have process %d in the process list", xpid) ;
           return E_SETONCE ;
       }
       pPI = new hzProginfo() ;
       pPI->m_PID = xpid ;
       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);
           }
       }
       procs.Insert(pPI->m_PID, pPI) ;
   }
   closedir(pDir) ;
   return E_OK ;
}