Return Type | Function name | Arguments |
---|---|---|
hzEcode | ListProcesses | (hzMapS<unsigned int,hzProginfo*>&,) |
Declared in file: hzUnixacc.h
Defined in file : hzProcess.cpp
Function Logic:
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 ; }