home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cenvi23.zip / IDLE.CMD < prev    next >
OS/2 REXX Batch file  |  1995-03-28  |  2KB  |  56 lines

  1. EXTPROC CEnvi2
  2. /**************************************************************
  3.  *** IDLE - CEnvi2 program to demonstrate altering the       ***
  4.  *** ver.1  priority of this process to only execute during ***
  5.  ***        system idletime.                                ***
  6.  **************************************************************/
  7.  
  8. // RUN LOOP TEST BEFORE REDUCING THE PROCESS PRIORITY
  9. printf("Looping at standard priority %d...\n",GetCurrentPriority());
  10. BigLoop();
  11.  
  12. // REDUCE PRIORITY OF THIS PROCESS TO IDLETIME
  13. #define ORD_DOS32SETPRIORITY     236
  14. #define PRTYC_IDLETIME     1  // set to idletime priority
  15. DynamicLink("doscalls",ORD_DOS32SETPRIORITY,BIT32,CDECL,
  16.             0/*all threads*/,PRTYC_IDLETIME/*idletime*/,
  17.             0/*no process change at new level*/,0/*current process*/)
  18.  
  19. printf("\nPriority has been set to idle; priority = %d.  Now this loop process\n",GetCurrentPriority());
  20. printf("runs only when the system is idle.  Will now run the loop test again\n");
  21. printf("but now the loops run only in idle time\n");
  22. BigLoop();
  23.  
  24.  
  25. // ROUTINES CALLED IN THE ABOVE CODE
  26.  
  27. #include <DosCalls.lib>
  28.  
  29. BigLoop()
  30. {
  31.    for ( i = 1000; i; i-- )
  32.       printf("\r%4d",i);
  33. }
  34.  
  35. GetCurrentPriority()
  36. {
  37.    MyID = GetMyID();
  38.    // find the priority of the first thread in this process
  39.    PList = ProcessList(TRUE);
  40.    assert( NULL != PList );
  41.    for ( pcount = 0; pcount <= GetArraySpan(PList); pcount++ ) {
  42.       if ( PList[pcount].id == MyID ) {
  43.          TList = PList[pcount].Threads;
  44.          assert( NULL != PList );
  45.          return( TList[0].Priority );
  46.       }
  47.    }
  48.    abort(); // should never get to this point
  49. }
  50.    
  51. GetMyID()   // get current process ID. Current ID is first UWORD32 in Process Info Block
  52. {
  53.    DosGetInfoBlocks(tid,pid);
  54.    return( peek(pid,UWORD32) );
  55. }
  56.