home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
CLASS.ZIP
/
NICE.C
< prev
next >
Wrap
Text File
|
1993-01-03
|
3KB
|
85 lines
#define INCL_DOSPROCESS
#include <os2.h>
#include <string.h>
#include <stdio.h>
#ifdef DEBUG
#define printFileLine() fprintf(stderr, "%s:%u\n", __FILE__, __LINE__)
#else
#define printFileLine() (void)1
#endif
int main(int argc, char **argv)
{ int iPid;
int iClass;
int iPriority;
char *arg;
char acCommand[1024];
iPid = 0;
iPriority = 0;
iClass = PRTYC_REGULAR;
acCommand[0] = 0;
for ( argv++; arg = *argv++; )
if (!strcmp(arg, "-idle"))
{ iClass = PRTYC_IDLETIME;
#ifdef DEBUG
fprintf(stderr, "iClass = %d\n", iClass);
#endif
}
else
if (!strcmp(arg, "-priority"))
{ iPriority = atoi(*argv++);
#ifdef DEBUG
fprintf(stderr, "iPriority = %d\n", iPriority);
#endif
}
else
if (!strcmp(arg, "-pid"))
{ iPid = atoi(*argv++);
#ifdef DEBUG
fprintf(stderr, "iPid = %d\n", iPid);
#endif
}
else
{ char *pScan;
int iStrLen;
strcpy(acCommand, arg);
for (pScan = acCommand + strlen(acCommand) + 1;
arg = *argv;
argv++, pScan += iStrLen, *pScan++ = ' ')
memcpy(pScan, arg, iStrLen = strlen(arg));
pScan[-1] = 0;
#ifdef DEBUG
{ char *pScan;
for (pScan = acCommand; *pScan; pScan += strlen(pScan) + 1)
fprintf(stderr, "%s ", pScan);
fprintf(stderr, "\n");
}
#endif
break;
}
if (acCommand[0])
{ char acFailObjectName[1024];
RESULTCODES structResult;
unsigned int iRet;
if (iRet = DosExecPgm(acFailObjectName, sizeof acFailObjectName, EXEC_ASYNCRESULT,
acCommand, (char*)0, (RESULTCODES*)&iPid, acCommand))
fprintf(stderr, "'DosExecPgm()' returns %d!\n", iRet);
DosSetPriority(PRTYS_PROCESSTREE, iClass, iPriority, iPid);
DosWaitChild(DCWA_PROCESS, DCWW_WAIT, &structResult, &iPid, iPid);
#ifdef DEBUG
fprintf(stderr, "codeResult=%d\n", structResult.codeResult);
#endif
DosExit(EXIT_PROCESS, structResult.codeResult);
}
else DosExit(EXIT_PROCESS, DosSetPriority(PRTYS_PROCESSTREE, iClass, iPriority,
iPid));
}