home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / QPS.ZIP / QPS.C next >
Text File  |  1989-11-02  |  6KB  |  213 lines

  1. #define INCL_DOS
  2. #define INCL_DOSPROCESS
  3. #include <stdlib.h>
  4. #include <stdio.h>
  5. #include <os2.h>
  6.  
  7. extern USHORT APIENTRY DosQProcStatus( PVOID pBuf, USHORT cbBuf );
  8. void Put_name( char *name );
  9. void Put_state( unsigned state );
  10.  
  11. BYTE bBuf[0x2000];
  12.  
  13. typedef union _ps_info PS_info;
  14.  
  15. struct _reference_info
  16.   { /* type 0 */
  17.     unsigned       TYPE;
  18.     PS_info        *NEXT;
  19.     unsigned       PID;
  20.     unsigned       PARENT_PID;
  21.     unsigned       SGID;
  22.     unsigned       MODULE_HANDLE;
  23.     unsigned       *MODULE_REFS;     /* points to modules handle numbers */
  24.     unsigned       MODULE_REF_COUNT;
  25.     unsigned       *SHARED_MEM_REFS; /* points to shared mem handle numbers */
  26.     unsigned       SHARED_MEM_COUNT;
  27.     unsigned       *SEMAPHORE_REFS;  /* points to semaphore handle numbers */
  28.     unsigned       SEMAPHORE_COUNT;
  29.   };
  30.  
  31. struct _thread_info
  32.   { /* type 1 */
  33.     unsigned       TYPE;
  34.     PS_info        *NEXT;
  35.     unsigned       PD_INDEX;
  36.     unsigned       PID;
  37.     unsigned       TID;
  38.     unsigned       PRIORITY;
  39.     unsigned       STATE;
  40.     unsigned long  BLOCK_ID;
  41.   };
  42.  
  43. struct _module_info
  44.   { /* type 2 */
  45.     unsigned       TYPE;
  46.     PS_info        *NEXT;
  47.     unsigned       HANDLE;
  48.     unsigned       NUM_DEPENDENCIES;      /* number of imported modules */
  49.     unsigned       DEPENDENCIES_PTR;
  50.     char           *MODULE_NAME_PTR;
  51.     unsigned       DEPENDENT_HANDLE_LIST; /* imported handle list */
  52.   };
  53.  
  54. struct _semaphore_info
  55.   { /* type 3 */
  56.     unsigned       TYPE;
  57.     PS_info        *NEXT;
  58.     unsigned       FLAGS;
  59.     unsigned       REF;
  60.     unsigned       HANDLE;
  61.     char           SEM_NAME;
  62.   };
  63.  
  64. struct _shared_mem_info
  65.   { /* type 4 */
  66.     unsigned       TYPE;
  67.     PS_info        *NEXT;
  68.     unsigned       HANDLE;
  69.     unsigned       SELECTOR;
  70.     unsigned       REF;
  71.     char           SEG_NAME;
  72.   };
  73.  
  74. typedef union _ps_info
  75.   {
  76.     struct _reference_info   t0;
  77.     struct _thread_info      t1;
  78.     struct _module_info      t2;
  79.     struct _semaphore_info   t3;
  80.     struct _shared_mem_info  t4;
  81.   } PS_info;
  82.  
  83.  
  84.  
  85.  
  86. void main( int    argc,
  87.            char   *argv[] )
  88.   {
  89.     PIDINFO   pid;
  90.     USHORT    type;
  91.     PS_info   *info;
  92.     unsigned  *pw;
  93.     unsigned  i;
  94.  
  95.  
  96.     DosGetPID( &pid );
  97.     printf( "Process ID  = 0x%04X\n", pid.pid );
  98.     printf( "Process TID = 0x%04X\n", pid.tid );
  99.     printf( "Parent ID   = 0x%04X\n", pid.pidParent );
  100.     if( DosQProcStatus(bBuf, sizeof(bBuf)) ) exit( 1 );
  101.  
  102.     printf( "Buffer address is %p:\n\n", bBuf );
  103.     info = (PS_info *) bBuf;
  104.     for(;;)
  105.       {
  106.         type = info->t0.TYPE;
  107.         if( type == 0xFFFF ) break;
  108.  
  109.    /*     printf( "Info @ %04X : Type = %u, Next = %04X\n",
  110.                  info, type, info->t0.NEXT );  */
  111.  
  112.         switch( type )
  113.           {
  114.           case 0:
  115.             printf( "Reference Information:  " );
  116.             printf( "PID=%04X PARENT_PID=%04X SGID=%04X MODULE_HANDLE=%04X\n",
  117.                     info->t0.PID, info->t0.PARENT_PID, info->t0.SGID, info->t0.MODULE_HANDLE );
  118.             pw = info->t0.MODULE_REFS;
  119.             printf( "Module reference handles:" );
  120.             for( i=0; i<info->t0.MODULE_REF_COUNT; ++i )
  121.                 printf( " %04X", pw[i] );
  122.             pw = info->t0.SHARED_MEM_REFS;
  123.             printf( "\nShared memory handles:" );
  124.             for( i=0; i<info->t0.SHARED_MEM_COUNT; ++i )
  125.                 printf( " %04X", pw[i] );
  126.             pw = info->t0.SEMAPHORE_REFS;
  127.             printf( "\nSemaphore handles:" );
  128.             for( i=0; i<info->t0.SEMAPHORE_COUNT; ++i )
  129.                 printf( " %04X", pw[i] );
  130.             break;
  131.  
  132.           case 1:
  133.             printf( "Thread Information:  " );
  134.             printf( "PD_INDEX=%04X PID=%04X TID=%04X PRIORITY=%04X BLOCK_ID=%08lX STATE=",
  135.                     info->t1.PD_INDEX, info->t1.PID, info->t1.TID,
  136.                     info->t1.PRIORITY, info->t1.BLOCK_ID );
  137.             Put_state( info->t1.STATE );
  138.             break;
  139.  
  140.           case 2:
  141.             printf( "Module  Information:  " );
  142.             printf( "HANDLE=%04X NUM_DEPENDENCIES=%04X\n",
  143.                     info->t2.HANDLE, info->t2.NUM_DEPENDENCIES );
  144.             pw = &info->t2.DEPENDENT_HANDLE_LIST;
  145.             printf( "Dependent handles:" );
  146.             for( i=0; i<info->t2.NUM_DEPENDENCIES; ++i )
  147.                 printf( " %04X", pw[i] );
  148.             printf( "\nModule Name: " );
  149.             Put_name( info->t2.MODULE_NAME_PTR );
  150.             break;
  151.  
  152.           case 3:
  153.             printf( "System Semaphore Information:  " );
  154.             printf( "FLAGS=%04X REF=%04X HANDLE=%04X\n",
  155.                     info->t3.FLAGS, info->t3.REF, info->t3.HANDLE );
  156.             printf( "Semaphore Name: "  );
  157.             Put_name( &info->t3.SEM_NAME );
  158.             break;
  159.  
  160.           case 4:
  161.             printf( "Named Shared Segment Information:  " );
  162.             printf( "HANDLE=%04X SELECTOR=%04X REF=%04X\n",
  163.                     info->t4.HANDLE, info->t4.SELECTOR, info->t4.REF );
  164.             printf( "Shared Segment Name: " );
  165.             Put_name( &info->t4.SEG_NAME );
  166.             break;
  167.  
  168.           default:
  169.             printf( "Unknown Information:\n" );
  170.             break;
  171.           }
  172.         printf( "\n\n" );
  173.  
  174.         info = info->t0.NEXT;
  175.       }
  176.  
  177.     printf( "End of Chain\n" );
  178.   }
  179.  
  180.  
  181.  
  182. void Put_name( char  *name )
  183.   {
  184.     unsigned       i;
  185.  
  186.     for( i=0; i<64; ++i )
  187.       {
  188.         if( *name == '\0' ) break;
  189.         if( *name >= ' ' && *name < 0x7F )
  190.             putchar( *name );
  191.         ++name;
  192.       }
  193.   }
  194.  
  195.  
  196.  
  197. void  Put_state( unsigned state )
  198.   {
  199.  
  200.     switch( state )
  201.       {
  202.         case 0      : printf( "start   " ); break;
  203.         case 1      : printf( "zombie  " ); break;
  204.         case 2      : printf( "ready   " ); break;
  205.         case 3      : printf( "blocked " ); break;
  206.         case 4      : printf( "frozen  " ); break;
  207.         case 5      : printf( "critsec " ); break;
  208.         case 6      : printf( "backgnd " ); break;
  209.         case 7      : printf( "boost   " ); break;
  210.         default     : printf( "0x%02X    ", state ); break;
  211.       }
  212.   }
  213.