home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: WPS_PM / WPS_PM.zip / xfld085s.zip / helpers / procstat.h < prev    next >
C/C++ Source or Header  |  1999-01-17  |  9KB  |  282 lines

  1.  
  2. /*
  3.  * procstat.h:
  4.  *      header file for procstat.h (querying process information).
  5.  *
  6.  *      Function prefixes (new with V0.81):
  7.  *      --  prc*   Query Process helper functions
  8.  *
  9.  *      Based on Kai Uwe Rommel's "dosqproc" package
  10.  *      available at Hobbes:
  11.  *      Kai Uwe Rommel - Wed 25-Mar-1992
  12.  *                       Sat 13-Aug-1994
  13.  *
  14.  *      Required #include's before including this header:
  15.  *      --  OS2.H with INCL_DOS and INCL_WIN.
  16.  *
  17.  *      This modified version Copyright (C) 1997-99 Ulrich Möller.
  18.  *      This file is part of the XFolder source package.
  19.  *      XFolder is free software; you can redistribute it and/or modify
  20.  *      it under the terms of the GNU General Public License as published
  21.  *      by the Free Software Foundation, in version 2 as it comes in the
  22.  *      "COPYING" file of the XFolder main distribution.
  23.  *      This program is distributed in the hope that it will be useful,
  24.  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
  25.  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  26.  *      GNU General Public License for more details.
  27.  */
  28.  
  29. #if __cplusplus
  30. extern "C" {
  31. #endif
  32.  
  33. #ifndef PROCSTAT_HEADER_INCLUDED
  34.     #define PROCSTAT_HEADER_INCLUDED
  35.  
  36.     #define PTR(ptr, ofs)  ((void *) ((char *) (ptr) + (ofs)))
  37.  
  38.     /* DosQProcStatus() = DOSCALLS.154 */
  39.     USHORT APIENTRY16 DosQProcStatus(PVOID pBuf, USHORT cbBuf);
  40.     /* DosGetPrty = DOSCALLS.9 */
  41.     USHORT APIENTRY16 DosGetPrty(USHORT usScope, PUSHORT pusPriority, USHORT pid);
  42.  
  43.     /*
  44.      * QPROCSTAT:
  45.      *      "header" structure returned by DosQProcStat,
  46.      *      containing the offsets to the other data
  47.      */
  48.  
  49.     typedef struct _QPROCSTAT
  50.     {
  51.         ULONG  ulGlobal;        // offset to global data section
  52.         ULONG  ulProcesses;     // offset to process data section
  53.         ULONG  ulSemaphores;    // offset to semaphore data section
  54.         ULONG  ulUnknown1;
  55.         ULONG  ulSharedMem;     // offset to shared mem data section
  56.         ULONG  ulModules;       // offset to DLL data section
  57.         ULONG  ulUnknown2;
  58.         ULONG  ulUnknown3;
  59.     } QPROCSTAT, *PQPROCSTAT;
  60.  
  61.     /*
  62.      * QGLOBAL:
  63.      *      at offset QPROCSTAT.ulGlobal, contains
  64.      *      global system information (no. of threads)
  65.      */
  66.  
  67.     typedef struct _QGLOBAL {
  68.         ULONG  ulThreads;       // total number of threads;
  69.         ULONG  ulReserved1,
  70.                ulReserved2;
  71.     } QGLOBAL, *PQGLOBAL;
  72.  
  73.     /*
  74.      * QPROCESS:
  75.      *      DosQProcStat structure for process info
  76.      */
  77.  
  78.     typedef struct _QPROCESS {
  79.         ULONG  ulType;          // 1 for processes
  80.         ULONG  ulThreadList;
  81.         USHORT usPID;
  82.         USHORT usParentPID;
  83.         ULONG  ulSessionType;
  84.         ULONG  ulStatus;        // see status #define's below
  85.         ULONG  ulSID;           // session (screen group) ID
  86.         USHORT usHModule;       // program module handle for process
  87.         USHORT usThreads;       // # of TCBs in use in process
  88.         ULONG  ulReserved1;
  89.         ULONG  ulReserved2;
  90.         USHORT usSemaphores;    // # of 16-bit semaphores
  91.         USHORT usDLLs;          // # of linked DLLs
  92.         USHORT usSharedMems;
  93.         USHORT usReserved3;
  94.         ULONG  ulSemList;       // offset to semaphore list
  95.         ULONG  ulDLLList;       // offset to DLL list
  96.         ULONG  ulSharedMemList; // offset to shared mem list
  97.         ULONG  ulReserved4;
  98.     } QPROCESS, *PQPROCESS;
  99.  
  100.     // process status flags
  101.     #define STAT_EXITLIST 0x01
  102.     #define STAT_EXIT1    0x02
  103.     #define STAT_EXITALL  0x04
  104.     #define STAT_PARSTAT  0x10
  105.     #define STAT_SYNCH    0x20
  106.     #define STAT_DYING    0x40
  107.     #define STAT_EMBRYO   0x80
  108.  
  109.     /*
  110.      * QTHREAD:
  111.      *      DosQProcStat structure for thread info
  112.      */
  113.  
  114.     typedef struct _QTHREAD
  115.     {
  116.         ULONG  ulType;          // 0x100 for thread records
  117.         USHORT usTID;           // thread ID
  118.         USHORT usThreadSlotID;  // ???
  119.         ULONG  ulBlockID;       // sleep id thread is sleeping on
  120.         ULONG  ulPriority;
  121.         ULONG  ulSysTime;
  122.         ULONG  ulUserTime;
  123.         UCHAR  ucStatus;        // TSTAT_* flags
  124.         UCHAR  ucReserved1;
  125.         USHORT usReserved2;
  126.     } QTHREAD, *PQTHREAD;
  127.  
  128.     // thread status flags
  129.     #define TSTAT_READY   1
  130.     #define TSTAT_BLOCKED 2
  131.     #define TSTAT_RUNNING 5
  132.     #define TSTAT_LOADED  9
  133.  
  134.     /*
  135.      * QMODULE:
  136.      *      DosQProcStat structure for module info
  137.      */
  138.  
  139.     typedef struct _QMODULE
  140.     {
  141.         ULONG  nextmodule;
  142.         USHORT modhandle;
  143.         USHORT modtype;
  144.         ULONG  submodules;
  145.         ULONG  segments;
  146.         ULONG  reserved;
  147.         ULONG  namepointer;
  148.         USHORT submodule[1];      // varying, see member submodules */
  149.     } QMODULE, *PQMODULE;
  150.  
  151.     /*
  152.      * QSEMAPHORE:
  153.      *      DosQProcStat structure for semaphore info (16-bit only, I guess)
  154.      */
  155.  
  156.     typedef struct _QSEMAPHORE
  157.     {
  158.         ULONG  nextsem;
  159.         USHORT owner;
  160.         UCHAR  flag;
  161.         UCHAR  refs;
  162.         UCHAR  requests;
  163.         UCHAR  reserved1;
  164.         USHORT reserved2;
  165.         USHORT index;
  166.         USHORT dummy;
  167.         UCHAR  name[1];       /* varying */
  168.     } QSEMAPHORE, *PQSEMAPHORE;
  169.  
  170.     /*
  171.      * QSHAREDMEM:
  172.      *      DosQProcStat structure for shared memory info
  173.      */
  174.  
  175.     typedef struct _QSHAREDMEM
  176.     {
  177.         ULONG  nextseg;
  178.         USHORT handle;            // handle for shared memory
  179.         USHORT selector;          // shared memory selector
  180.         USHORT refs;              // reference count
  181.         UCHAR  name[1];           // varying
  182.     } QSHAREDMEM, *PQSHAREDMEM;
  183.  
  184.     /*
  185.      * PRCPROCESS:
  186.      *      additional, more lucid structure
  187.      *      filled by prcQueryProcessInfo
  188.      */
  189.  
  190.     typedef struct _PRCPROCESS {
  191.         CHAR   szModuleName[CCHMAXPATH];    // module name
  192.         USHORT usPID,                       // process ID
  193.                usParentPID,                 // parent process ID
  194.                usThreads;                   // thread count
  195.         ULONG  ulSID;                       // session ID
  196.         ULONG  ulSessionType;
  197.         ULONG  ulStatus;
  198.         ULONG  ulCPU;                       // CPU usage (sum of thread data)
  199.     } PRCPROCESS, *PPRCPROCESS;
  200.  
  201.     /*
  202.      * PRCTHREAD:
  203.      *      additional, more lucid structure
  204.      *      filled by prcQueryThreadInfo
  205.      */
  206.  
  207.     typedef struct _PRCTHREAD {
  208.         USHORT usTID;           // thread ID
  209.         USHORT usThreadSlotID;  // ???
  210.         ULONG  ulBlockID;       // sleep id thread is sleeping on
  211.         ULONG  ulPriority;
  212.         ULONG  ulSysTime;
  213.         ULONG  ulUserTime;
  214.         UCHAR  ucStatus;        // see status #define's below
  215.     } PRCTHREAD, *PPRCTHREAD;
  216.  
  217.     /*
  218.      * prcQueryProcessInfo:
  219.      *      this searches for a given process ID (usPID) and
  220.      *      fills a given PRCPROCESS structure with lots of
  221.      *      information about this process.
  222.      *      Returns FALSE upon errors.
  223.      */
  224.  
  225.     BOOL prcQueryProcessInfo(USHORT usPID, PPRCPROCESS pprcp);
  226.  
  227.     /*
  228.      * prcForEachProcess:
  229.      *      this calls a given callback func for each running
  230.      *      process; this func will be passed the following params:
  231.      *          HWND hwnd       like hwnd passed to prcForEachProcess
  232.      *          ULONG msg       like msg passed to prcForEachProcess
  233.      *          MPARAM mp1      like mp1 passed to prcForEachProcess
  234.      *          PPRCPROCESS mp2 pointer to a PRCPROCESS struct for each process
  235.      *      This function returns the number of running processes on the
  236.      *      system. If pfnwpCallback is NULL, only this number will be
  237.      *      returned.
  238.      */
  239.  
  240.     ULONG prcForEachProcess(PFNWP pfnwpCallback, HWND hwnd, ULONG ulMsg, MPARAM mp1);
  241.  
  242.     /*
  243.      * prcQueryThreadCount:
  244.      *      returns the total number of running threads
  245.      *      in the given process. If pid == 0, the
  246.      *      total thread count for the system is returned.
  247.      */
  248.  
  249.     ULONG prcQueryThreadCount(USHORT usPID);
  250.  
  251.     /*
  252.      * prcQueryThreadInfo:
  253.      *      this searches for a given thread in a given process
  254.      *      and fills a given PRCTHREAD structure with lots of
  255.      *      information about that thread.
  256.      *      Returns FALSE upon errors.
  257.      *      Note: This function loops thru all processes which
  258.      *      are currently running and is therefore not terribly
  259.      *      fast. Use economically.
  260.      */
  261.  
  262.     BOOL prcQueryThreadInfo(USHORT usPID, USHORT usTID, PPRCTHREAD pprct);
  263.  
  264.  
  265.     /*
  266.      * prcQueryPriority:
  267.      *      shortcut if you want the priority only.
  268.      *      Returns -1 upon errors.
  269.      *      Note: This function loops thru all processes which
  270.      *      are currently running and is therefore not terribly
  271.      *      fast. Use economically.
  272.      */
  273.  
  274.     ULONG prcQueryThreadPriority(USHORT usPID, USHORT usTID);
  275.  
  276. #endif
  277.  
  278. #if __cplusplus
  279. }
  280. #endif
  281.  
  282.