home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / os2db2.zip / PROCESS.CPP < prev    next >
Text File  |  1994-09-03  |  4KB  |  114 lines

  1.  /******************************************************
  2. *  PROCESS.CPP - if process is active                   *
  3.  ******************************************************/
  4.  
  5. #include "defines.hpp"                                // type defines
  6. #include "process.hpp"                                // process class
  7.  
  8. CHAR      PROCESS::queryBuffer[BUFFER_SIZE];          // query buffer
  9.  
  10.  /******************************************************
  11. *  PROCESS::queryStatus - query status                  *
  12.  ******************************************************/
  13.  
  14. NOLINE BOOL PROCESS::queryStatus(PVOID statusBuffer, USHORT bufferSize)
  15.  
  16. {
  17.      BOOL   returnCode;                               // return code
  18.  
  19.      returnCode = ((::DosQProcStatus(statusBuffer, bufferSize) != 0) ? FALSE : TRUE);
  20.  
  21.      return returnCode;                               // return code
  22. }
  23.  
  24.  /******************************************************
  25. *  PROCESS::listProcess - list process                  *
  26.  ******************************************************/
  27.  
  28. NOLINE BOOL PROCESS::listProcess(PHEADERINFO headerInfo)
  29.  
  30. {
  31.      PMODULEINFO  moduleInfo  = NULL;                 // module info
  32.  
  33.      PPROCESSINFO processInfo = headerInfo->processInfo;
  34.  
  35.      if (processInfo != NULL) {                       // process info
  36.  
  37.           while (processInfo->endIndicator != END_PROCESS) {
  38.  
  39.                moduleInfo = headerInfo->moduleInfo;   // module info
  40.  
  41.                if (moduleInfo != NULL) {              // module info
  42.  
  43.                     printModule(moduleInfo, processInfo);
  44.                }
  45.                // assume next PROCESSINFO structure is found by taking
  46.                // the address of the first THREADINFO structure of the
  47.                // current PROCESSINFO structure and adding the size of
  48.                // the THREADINFO structure times the number of threads
  49.  
  50.                processInfo = (PPROCESSINFO)           // process info
  51.  
  52.               (processInfo->threadInfo + processInfo->threadCount);
  53.           }
  54.      }
  55.      return TRUE;                                     // return code
  56. }
  57.  
  58.  /******************************************************
  59. *  PROCESS::printModule - print module                  *
  60.  ******************************************************/
  61.  
  62. NOLINE VOID PROCESS::printModule(PMODULEINFO moduleInfo, PPROCESSINFO processInfo)
  63.  
  64. {
  65.      while (moduleInfo != NULL) {                     // module info
  66.  
  67.           if (moduleInfo->moduleRef == processInfo->moduleRef) {
  68.  
  69.                printf(" %5lu   %5lu   %5lu   %5lu   %s\n",
  70.  
  71.                (ULONG) processInfo->processID,        // process ID
  72.  
  73.                (ULONG) processInfo->parentPID,        // parent PID
  74.  
  75.                (ULONG) processInfo->sessionID,        // session ID
  76.  
  77.                (ULONG) processInfo->threadCount,      // thread count
  78.  
  79.                moduleInfo->moduleName);               // module name
  80.  
  81.                break;                                 // done printing
  82.           }
  83.           moduleInfo = moduleInfo->nextModule;        // next module
  84.      }
  85. }
  86.  
  87.  /******************************************************
  88. *  PROCESS::listRunning - list running                  *
  89.  ******************************************************/
  90.  
  91. NOLINE BOOL PROCESS::listRunning(VOID)
  92.  
  93. {
  94.      BOOL   returnCode;                               // return code
  95.  
  96.      printf("PROCESS PARENT  SESSION  # OF    MODULE \n");
  97.      printf("  ID      ID      ID    THREADS   NAME  \n");
  98.      printf("------- ------- ------- -------  --------------------------------------------\n");
  99.  
  100.      returnCode = queryStatus(queryBuffer, BUFFER_SIZE);
  101.  
  102.      if (returnCode == TRUE) {                        // return code
  103.  
  104.           PHEADERINFO headerInfo = (PHEADERINFO) queryBuffer;
  105.  
  106.           if (headerInfo != NULL) {                   // header info
  107.  
  108.                returnCode = listProcess(headerInfo);  // list process
  109.           }
  110.      }
  111.      return returnCode;                               // return code
  112. }
  113.  
  114.