home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / CLASS.ZIP / NICE.C < prev    next >
Text File  |  1993-01-03  |  3KB  |  85 lines

  1. #define INCL_DOSPROCESS
  2. #include <os2.h>
  3. #include <string.h>
  4. #include <stdio.h>
  5.  
  6.  
  7. #ifdef DEBUG
  8. #define printFileLine() fprintf(stderr, "%s:%u\n", __FILE__, __LINE__)
  9. #else
  10. #define printFileLine() (void)1
  11. #endif
  12.  
  13.  
  14. int main(int argc, char **argv)
  15. {       int iPid;
  16.         int iClass;
  17.         int iPriority;
  18.         char *arg;
  19.         char acCommand[1024];
  20.  
  21.  
  22.         iPid = 0;
  23.         iPriority = 0;
  24.         iClass = PRTYC_REGULAR;
  25.         acCommand[0] = 0;
  26.         for ( argv++; arg = *argv++; )
  27.                 if (!strcmp(arg, "-idle"))
  28.                 {       iClass = PRTYC_IDLETIME;
  29. #ifdef DEBUG
  30.                         fprintf(stderr, "iClass = %d\n", iClass);
  31. #endif
  32.                 }
  33.                 else
  34.                 if (!strcmp(arg, "-priority"))
  35.                 {       iPriority = atoi(*argv++);
  36. #ifdef DEBUG
  37.                         fprintf(stderr, "iPriority = %d\n", iPriority);
  38. #endif
  39.                 }
  40.                 else
  41.                 if (!strcmp(arg, "-pid"))
  42.                 {       iPid = atoi(*argv++);
  43. #ifdef DEBUG
  44.                         fprintf(stderr, "iPid = %d\n", iPid);
  45. #endif
  46.                 }
  47.                 else
  48.                 {       char *pScan;
  49.                         int iStrLen;
  50.  
  51.                         strcpy(acCommand, arg);
  52.                         for (pScan = acCommand + strlen(acCommand) + 1;
  53.                             arg = *argv;
  54.                             argv++, pScan += iStrLen, *pScan++ = ' ')
  55.                                 memcpy(pScan, arg, iStrLen = strlen(arg));
  56.                         pScan[-1] = 0;
  57. #ifdef DEBUG
  58.                         {       char *pScan;
  59.  
  60.                                 for (pScan = acCommand; *pScan; pScan += strlen(pScan) + 1)
  61.                                         fprintf(stderr, "%s ", pScan);
  62.                                 fprintf(stderr, "\n");
  63.                         }
  64. #endif
  65.                         break;
  66.                 }
  67.         if (acCommand[0])
  68.         {       char acFailObjectName[1024];
  69.                 RESULTCODES structResult;
  70.                 unsigned int iRet;
  71.  
  72.                 if (iRet = DosExecPgm(acFailObjectName, sizeof acFailObjectName, EXEC_ASYNCRESULT,
  73.                     acCommand, (char*)0, (RESULTCODES*)&iPid, acCommand))
  74.                         fprintf(stderr, "'DosExecPgm()' returns %d!\n", iRet);
  75.                 DosSetPriority(PRTYS_PROCESSTREE, iClass, iPriority, iPid);
  76.                 DosWaitChild(DCWA_PROCESS, DCWW_WAIT, &structResult, &iPid, iPid);
  77. #ifdef DEBUG
  78.                 fprintf(stderr, "codeResult=%d\n", structResult.codeResult);
  79. #endif
  80.                 DosExit(EXIT_PROCESS, structResult.codeResult);
  81.         }
  82.         else DosExit(EXIT_PROCESS, DosSetPriority(PRTYS_PROCESSTREE, iClass, iPriority, 
  83.             iPid));
  84. }
  85.