// OsProcess doesn't provide any thread info so this method returns
   // the number of threads running under the process given by PID.
   // FIXME: Only implemented for linux, always returns 1 otherwise.
   int getNumThreads( int PID )
   {
       int numThreads = 1;

#ifdef __linux__
       // /proc parsing stolen from OsProcessIteratorLinux.cpp
       OsStatus retval = OS_FAILED;
       char pidString[20];
       snprintf(pidString, 20, "%d", PID);

       OsPath fullProcName = "/proc/";
       fullProcName += pidString;
       fullProcName += "/status";
       OsFileLinux procFile(fullProcName);
       if (procFile.open(OsFile::READ_ONLY) == OS_SUCCESS)
       {
           long len = 5000; //since the length is always 0 for these files, lets try to read 5k
           char *buffer = new char[len+1];
           if (buffer)
           {
               unsigned long bytesRead;
               procFile.read((void *)buffer,(unsigned long)len,bytesRead);

               if (bytesRead)
               {
                   procFile.close();
                   //null-terminate the string
                   buffer[bytesRead] = 0;
                   //now parse the info we need
                   char *ptr = strtok(buffer,"\n");
                   while(ptr)
                   {
                       if (memcmp(ptr,"Threads:",8) == 0)
                       {
                           numThreads = atoi(ptr+8);
                       }

                       ptr = strtok(NULL,"\n");
                   }

                   //say we are successful
                   retval = OS_SUCCESS;
               }
               else
                   osPrintf("Couldn't read bytes in readProcFile\n");

               delete [] buffer;
           }

           procFile.close();
       }
#endif
       return numThreads;
   }
/**
 * file name walk callback.  Walk the contents of each file 
 * that is found.
 */
static TSK_WALK_RET_ENUM
dirAct(TskFsFile * fs_file, const char *path, void *ptr)
{
	fprintf(stdout,
               "file systems file name: %s\n", fs_file->getName()->getName());

    /* Ignore NTFS System files */
    if ((TSK_FS_TYPE_ISNTFS(fs_file->getFsInfo()->getFsType()))
        && (fs_file->getName()->getName()[0] == '$'))
        return TSK_WALK_CONT;

    /* If the name has corresponding metadata, then walk it */
    if (fs_file->getMeta()) {
        procFile(fs_file, path);
    }

    return TSK_WALK_CONT;
}
Beispiel #3
0
void CCPULoad::ReadFromFile(unsigned long long& dtotalUser,
                            unsigned long long& dtotalUserLow,
                            unsigned long long& dtotalSys,
                            unsigned long long& dtotalIdle,
                            unsigned long long& dtotalIowait,
                            unsigned long long& dtotalIrq,
                            unsigned long long& dtotalSoftIrq)
{
   std::ifstream procFile("/proc/stat");

   // This might broke if there are not 7 columns minimum in /proc/stat
   
   // 1 : user.
   // 2 : nice.
   // 3 : system.
   // 4 : idle.
   // 5 : iowait.
   // 6 : irq.
   // 7 : softIrq.
   
   // Only the first CPU is read. All cores are resumed in the cpu line. For each core you have a specific line cpu0, cpu1 ...
   
   boost::regex reg("[cpu ] (\\d+) (\\d+) (\\d+) (\\d+) (\\d+) (\\d+) (\\d+)");

   //each counters (64 bits) is incremented each time of the number of ticks corresponding. counters should be equal or greater at each reads. if not, it's the overflow of the counter.

   std::string line;
   while ( std::getline(procFile, line) ) 
   {
      boost::smatch match;
      if ( boost::regex_search( line, match, reg ) ) 
      {
          dtotalUser    = boost::lexical_cast<long long>(match[1]);
          dtotalUserLow = boost::lexical_cast<long long>(match[2]);
          dtotalSys     = boost::lexical_cast<long long>(match[3]);
          dtotalIdle    = boost::lexical_cast<long long>(match[4]);
          dtotalIowait  = boost::lexical_cast<long long>(match[5]);
          dtotalIrq     = boost::lexical_cast<long long>(match[6]);
          dtotalSoftIrq = boost::lexical_cast<long long>(match[7]);
      }
   }

   procFile.close();
}
Beispiel #4
0
 odomVideo_t::odomVideo_t( 
    int                fdDsp,
    int                fdYUV,
    char const        *fileName,
    rectangle_t const &outRect )
    : fIn_( procFile(cmdLine_,sizeof(cmdLine_), fileName ) )
    , stream_( fileno(fIn_) )
    , outQueue_( fdDsp,
                 fdYUV,
                 2000,
                 outRect )
    , outRect_( outRect )
    , bytesPerPicture_( 0 )
    , firstPTS_( 0LL )
    , lastPTS_( 0LL )
    , start_( 0LL )
 {
    if( 0 == fIn_ )fprintf( stderr, "%s: %m", fileName );
    TRACEINCR(traceVideo);
 }